Ravindra BagaleCourses & study guides English Track your progress

SNS, SQS आणि Step Functions ने Fan-Out आणि Fan-In Patterns

एक घंटा वाजतो; सगळ्या class उठतात (fan-out). Sports day नंतर अनेक tracks चे scores एका board वर (fan-in). SNS/SQS/SFN Parallel-Map — recursive storms नको.

या chapter मध्ये तुम्ही काय शिकाल

  • School stories
  • SNS vs EB vs Parallel
  • SQS buffer
  • Fan-in join
  • Link fanout project

1. रोजचे: घंटा आणि sports board

Rohan (Pune): SNS OrderPlaced → inventory/invoice/analytics. Fraud checks Parallel → join = fan-in.

Hands-on: order fanout project. SQS/SNS. Step Functions.

2. Fan-out का?

हे का लागतं?

Sync तीन Lambda = coupled timeouts. Fan-out = स्वतंत्र scale/fail.

हे काय आहे?

Fan-out: एक → अनेक. Fan-in: अनेक → एक next.

3. Vertical diagrams

Producer -> SNS/EB -> Queues -> WorkersBuffers सह fan-out
Per-queue DLQ
Parallel -> Branches -> JoinSFN fan-in
Per-branch Catch

4. SNS vs EB vs Parallel

ToolStyleकधी
SNSSQS/Lambda/SMSSimple
EventBridgeFiltered rulesFilters/archive
SFN Parallel/MapKnown then joinFan-in+timeline

5. How: safe fan-out

कसं करायचं (step by step)

  1. Topic.
  2. Queues+DLQ subscribe.
  3. Raw delivery choice.
  4. ESM per queue.
  5. IAM split.
  6. Test ×3.
  7. DLQ alarms.

Subscriptions

aws sns list-subscriptions-by-topic --topic-arn $TOPIC --region ap-south-1

अर्थ: तीन SQS subs confirm.

Publish test

aws sns publish --topic-arn $TOPIC --region ap-south-1 \
  --message '{"orderId":"o-42","currency":"INR","total":499}'

अर्थ: तीन queues depth बघा.

6. Fan-in

  • SFN Parallel.
  • Map + cap.
  • DDB counter risky.
  • No busy-poll.

Python buffer?

def needs_queue(consumer_slow, spike_expected):
    return consumer_slow or spike_expected
print(needs_queue(True, False))
print(needs_queue(False, False))

Output: True/False. अर्थ: slow/spiky → SQS.

7. Failure isolation

Invoice fail ≠ inventory fail. Luis (Mexico City) sync for-loop मुळे stock अडकला.

8. Lab

Org block नसेल तर ap-south-1 (Mumbai). आधी budget alert.

कसं करायचं (step by step)

  1. Draw + DLQs.
  2. FIFO vs Standard.
  3. Optional sandbox.
  4. Publish verify.
  5. Cleanup.

Cleanup (billing थांबवा)

  1. Unsub then delete.
  2. Lambdas/logs.

9. Map concurrency

Map MaxConcurrency सेट करा; fragile API आधी SQS.

Queue depth

aws sqs get-queue-attributes --queue-url $Q --attribute-names ApproximateNumberOfMessages ApproximateNumberOfMessagesNotVisible --region ap-south-1

अर्थ: Depth ↑ = consumer lag.

10. Fan-out idempotency

Duplicates येतात. orderId conditional put. Kenji (Osaka) जपान Yen invoices दुप्पट.

11. एकाच pattern — वेगवेगळ्या industries

  • Fintech (Aisha, Lagos): payment webhooks → SQS → Lambda.
  • Ecommerce (Rohan, Pune): checkout API; inventory SNS fan-out.
  • Healthcare (Mei, Singapore): SNS SMS; PHI + fine-grained IAM.
  • EdTech (Diego, São Paulo): EventBridge nightly cleanup.
  • Logistics (Fatima, Casablanca): EventBridge + saga.
  • Media (Kenji, Osaka): S3 → Lambda thumbs + fan-out.
  • SaaS (Priya, Bengaluru): Cognito + per-tenant partition.
  • Gov (Omar, Amman): strangler fig per form route.

12. Troubleshooting checklist

  1. Region confirm करा.
  2. CloudWatch Logs + request id.
  3. Execution role permissions.
  4. DLQ + oldest message age.
  5. curl -v + CORS.
  6. SFN event history.
  7. Linked chapter पुन्हा वाचा.
  8. Cost: concurrency/retries.

13. सामान्य errors आणि fixes

प्रत्येक row = खरी चूक. Panic करण्याआधी fix वाचा.

Error / लक्षणFix
Sync for-loopSNS/EB/Parallel.
Shared DLQPer DLQ.
No filtersFilters.
Sleep fan-inSFN.
Unbounded MapCap.
Raw surpriseTest envelope.
FIFO everywhereWhen needed.
No idempotencyConditional.
Huge SNSS3 key.
SQS policyAllow SNS.

14. FAQ

प्र. SNS vs EB?

Simple vs filters.

प्र. Fan-in w/o SFN?

Prefer SFN.

प्र. SQS middle?

हो.

प्र. Order?

FIFO/SFN.

प्र. Project?

build-order-fanout.

प्र. Poison?

DLQ+redrive.

15. Interview Q&A (Beginner / Mid / Senior + MNC)

प्र. Beginner fan-out

One→many.

प्र. Fan-in

Many→join.

प्र. Mid SQS

Buffer/isolate.

प्र. Parallel vs Map

Fixed vs array.

प्र. Senior blast

IAM+DLQ+caps.

प्र. MNC dupes

Idempotent.

16. Tips — English, मराठी आणि हिंदी

Ravindra Bagale's Tip (EN)

Fan-out for independence; fan-in with a real join — not a sleep loop.

Ravindra Bagale's Tip (MR)

Fan-out = independence; fan-in = खरा join — sleep loop नको.

Tip (HI)

Fan-out से स्वतंत्रता; fan-in के लिए असली join — sleep loop नहीं।

घरी करून बघा

  1. तीन consumers.
  2. FIFO कोणाला.

थोडक्यात सांगायचं तर

  1. गोष्टी पासून सुरू, मग services.
  2. Existing chapters link — labs copy नको.
  3. Failure साठी design.
  4. Measure → मग पैसे.

17. Fan-out poison/redrive

  1. Per-consumer DLQ.
  2. Alarm → team.
  3. Redrive that DLQ.
  4. Inspect sample first.

18. Security

  • Topic Publish policy.
  • Queue allow SNS ARN.
  • Least privilege consume.
  • SSE/KMS.

19. Cost

Isolation खरेदी. Labs free tier; Black Friday scale = watch SQS+concurrency.

Filter policy

# Subscription attribute FilterPolicyJSON
# {"currency":["INR","AED"],"type":["OrderPlaced"]}

अर्थ: Matching currency लाच wake.

20. Architecture decision checklist

  1. User journey 5 bullets, no AWS names.
  2. Sync vs async mark.
  3. Failure mode.
  4. Idempotency key.
  5. Data from access patterns.
  6. Cost 1x and 10x.
  7. Quotas ap-south-1.
  8. Auth decision.
  9. On-call + alarm.
  10. Deep chapter link.
  11. मग console/IaC.

21. Copy-paste quick commands

# Region and identity
aws configure get region
aws sts get-caller-identity

# Lambda landscape
aws lambda list-functions --region ap-south-1 --max-items 20 \
  --query 'Functions[].{N:FunctionName,R:Runtime,T:Timeout,M:MemorySize}' --output table
aws lambda get-account-settings --region ap-south-1

# API Gateway (HTTP APIs)
aws apigatewayv2 get-apis --region ap-south-1 --query 'Items[].{N:Name,Id:ApiId,Ep:ProtocolType}' --output table

# Queues and topics
aws sqs list-queues --region ap-south-1
aws sns list-topics --region ap-south-1 --query 'Topics[].TopicArn'

# Event buses and state machines
aws events list-event-buses --region ap-south-1
aws stepfunctions list-state-machines --region ap-south-1 --query 'stateMachines[].name'

# DynamoDB tables (names only)
aws dynamodb list-tables --region ap-south-1

Sandbox + read-only IAM.

22. अजून industry आणि stack stories

  • Fintech Lagos: webhook → SQS → idempotent ledger.
  • Ecommerce Pune: throttle + fan-out.
  • Healthcare SG: SNS + PHI IAM.
  • EdTech: EventBridge cleanup.
  • Logistics: bus + saga.
  • Media: avoid recursive S3.
  • SaaS: tenant partition.
  • Gov: strangler peel.
  • Startup: Function URL → HTTP API.
  • Retail: FIFO vs Standard.
  • Python: thin handlers.
  • Node: async/await.
  • Java: SnapStart.
  • .NET: package size.
  • Go: static binary.
  • PHP: hybrid.

23. Glossary

Termअर्थ
Cold startपहिल्या invoke ची init
Idempotencyदोनदा = तोच effect
DLQFail झालेले messages
ChoreographyEvents; conductor नाही
OrchestrationSFN central
Fan-outएक → अनेक
Fan-inअनेक → join
Strangler figMonolith peel
SagaSteps + compensate
Provisioned concurrencyWarm N; pay

24. Practice: मोठ्याने explain

  1. 60s: fan-out आणि fan-in गोष्ट.
  2. 60s: sync vs async checkout.
  3. 60s: Lambda नको कधी.
  4. 60s: DLQ + idempotency.
  5. Record ×2.

25. Safe lab hygiene

  • Tag owner+expiry.
  • Budget alarm आधी.
  • Read-only first.
  • Cleanup.
  • No secrets in env/screenshots.
  • No provisioned on hello.

27. Myths

Mythखरं
Servers नाहीतServers आहेत; manage नको
नेहमी स्वस्तSteady वर EC2
No OpsIAM/data/alarms
एक LambdaBounded contexts
Queues optionalLoad leveler

28. Serverless error budget

Checkout error budget 0.1% असेल तर aggressive retries email duplicates देऊन budget जाळू शकतात. Money SLO ≠ notify SLO.

  1. दोन SLOs.
  2. Money retries bounded.
  3. Notify best-effort.
  4. Money page; notify ticket.

29. Regional notes (ap-south-1)

  • Labs Mumbai.
  • Feature availability.
  • Data residency.
  • Latency India.

30. Naming conventions

# Suggested prefixes
# Lambda:  pay-intake-prod, pay-worker-prod
# SQS:     pay-orders.fifo / pay-orders-dlq
# SNS:     pay-order-events
# EB bus:  pay.domain
# SFN:     pay-refund-saga
# DDB:     pay-orders-prod

env + domain नावात ठेवा. CloudWatch grep सोपा.

31. Pre-mortems

  1. Double charge headline.
  2. DLQ drain plan.
  3. Cognito outage mode.
  4. Runbook.

32. Currency / locale

Currencies आणि names rotate करा — global mental model.

उजळणी, मुलाखत आणि तुलना cards

हा lesson काही मिनिटांत revise करा. Cards phone वर save करा किंवा PNG download करा. प्रत्येक card वरचा QR हा lesson उघडतो.

उजळणी card: Fan-out shape. Sync loop couples. Publish once; many consumers. Topic → SQS → Lambda. One event many.
उजळणी card: Fan-out shape · PNG download करा · Card page उघडा
उजळणी card: Fan-in join. Early next step. Parallel/Map join. All done → next. Join before charge.
उजळणी card: Fan-in join · PNG download करा · Card page उघडा
तुलना: SNS→Lambda direct vs SNS→SQS→Lambda. SNS→Lambda direct: Direct invoke. SNS→SQS→Lambda: Buffered.
तुलना: SNS→Lambda direct vs SNS→SQS→Lambda · PNG download करा · Card page उघडा
तुलना: Parallel vs Map. Parallel: Fixed join. Map: Dynamic list.
तुलना: Parallel vs Map · PNG download करा · Card page उघडा
मुलाखत card: SNS then SQS. Direct SNS Lambda. SNS→SQS→Lambda. Three reasons.
मुलाखत card: SNS then SQS · PNG download करा · Card page उघडा
मुलाखत card: Map MaxConcurrency. Stampede. Cap concurrency. Pick a cap.
मुलाखत card: Map MaxConcurrency · PNG download करा · Card page उघडा
मुलाखत card: Fat event via S3. Fat message. S3 key on bus. Envelope vs blob.
मुलाखत card: Fat event via S3 · PNG download करा · Card page उघडा
मुलाखत card: FIFO when order. FIFO overuse. Order → FIFO. One each.
मुलाखत card: FIFO when order · PNG download करा · Card page उघडा

अजून cards: Ravi Sir's Cards.

सराव Tasks

या scenario बद्दल

Amravati Agro Market हा अमरावती मधला शेती व्यवसाय आहे. Anjali Thakre त्यांचं IT व cloud काम पाहतात. त्यांचे पैसे INR मध्ये मोजले जातात आणि AWS resources ap-south-1 Region मध्ये चालतात. खालच्या tasks मध्ये तुम्ही या lesson मध्ये शिकलेलं वापरून त्यांची खरी कामं करता. सगळी नावं, account IDs, IP addresses व numbers सरावासाठी काल्पनिक आहेत.

0 / 16

सोपं Fan-out

का: Shape.

काय करायचं: One to many तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

सोपं Fan-in

का: Shape.

काय करायचं: Many join तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

सोपं Buffer

का: Why.

काय करायचं: Buffer isolate तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

सोपं Parallel

का: Tool.

काय करायचं: Parallel join तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

सोपं List-topics

का: CLI.

काय करायचं: list.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

सोपं Shapes

का: Map.

काय करायचं: fan_out/fan_in.

कसं करायचं:
  1. Task मधल्या top-level keys पासून सुरू करा.
  2. Child keys 2 spaces ने indent करा (tabs नकोत).
  3. प्रत्येक property मध्ये task मधली value भरा.
  4. Check answer दाबा. Keys चा क्रम महत्त्वाचा नाही.

सोपं Map

का: SFN.

काय करायचं: Map dynamic तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

मध्यम MaxConc

का: Protect.

काय करायचं: Protect downstream तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

मध्यम Idem

का: Dupes.

काय करायचं: Idempotent तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

मध्यम Payload

का: Size.

काय करायचं: S3 key तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

मध्यम Per-DLQ

का: Isolate.

काय करायचं: Isolate failures तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

मध्यम Buffer

का: Why.

काय करायचं: after_sns/reason.

कसं करायचं:
  1. Task मधल्या top-level keys पासून सुरू करा.
  2. Child keys 2 spaces ने indent करा (tabs नकोत).
  3. प्रत्येक property मध्ये task मधली value भरा.
  4. Check answer दाबा. Keys चा क्रम महत्त्वाचा नाही.

अवघड FIFO

का: Order.

काय करायचं: Order matters तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

अवघड Anti

का: Smell.

काय करायचं: Anti-pattern तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

अवघड Standard

का: Tradeoff.

काय करायचं: Throughput तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

अवघड Lab

का: Hygiene.

काय करायचं: Delete lab तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.