Ravindra BagaleCourses & study guides English Track your progress

Serverless वर Queue-Based Load Leveling, DLQ, Retries आणि Idempotency

तिकीट खिडकी जलद; किचन steady. मध्ये ticket rail = queue. SQS burst थामवते. DLQ, retries, visibility timeout, idempotency — चार सुरक्षित async स्तंभ.

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

  • Ticket-rail story
  • Visibility vs Lambda timeout
  • DLQ design
  • Idempotent consumers
  • Link async-order

1. रोजचे: ticket rail

Sofia (EUR) cafe: tour bus = 40 orders. Ticket rail = SQS. API 202; workers steady.

Hands-on: async order project. Depth: SQS/SNS.

2. Load leveling का?

हे का लागतं?

Queue नसेल तर spike → throttle → angry retries. Queue = lag जो measurable आहे.

हे काय आहे?

Load leveling + DLQ + Idempotency.

3. Vertical path

Client -> API -> SQS -> Worker -> DynamoDBEdge 202; durable queue
DLQ बाजूला
Client burst Intake Lambda (202) SQS main queueVisibility timeout + redrive DLQ Worker Lambda (batch) DynamoDB idempotent write
Main queue बाजूला DLQ.

4. Visibility vs Lambda timeout

SettingRule
Lambda timeoutp99 पेक्षा थोडं जास्त
VisibilityGreater than Lambda timeout × batch worry factor (often ≥ 6× timeout for safety margin in labs, tune in prod)Lambda timeout पेक्षा जास्त — tune
maxReceiveCount3–5
batch size1–10 पासून

Ravindra Bagale's Tip

Visibility लवकर संपली तर duplicate. Idempotency वाचवते; timeouts pain कमी.

5. How: intake + worker

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

  1. Queue+DLQ redrive.
  2. Intake 202.
  3. Worker idempotent.
  4. Partial batch failure.
  5. Alarms.
  6. Burst test.

Create + redrive

aws sqs create-queue --queue-name sofia-orders-dlq --region ap-south-1
# then create main with RedrivePolicy pointing at DLQ ARN, maxReceiveCount=5

अर्थ: आधी DLQ ARN.

SendMessage

aws sqs send-message --queue-url $Q --region ap-south-1 \
  --message-body '{"orderId":"o-7","currency":"EUR","total":12.5}'

अर्थ: तेच orderId दोनदा = एक row.

6. Idempotency

Python conditional

# Concept: PutItem with ConditionExpression attribute_not_exists(orderId)
# First write wins; duplicate message returns ConditionalCheckFailed — treat as success
print("first -> wrote")
print("dup -> already exists -> ok")

अर्थ: at-least-once → exactly-once effect.

Node key

const crypto = require('crypto');
const key = (o) => crypto.createHash('sha256').update(JSON.stringify(o)).digest('hex').slice(0,16);
console.log(key({orderId:'o-7',total:12.5}));

अर्थ: stable key = dedupe.

7. Retry taxonomy

Layerकायतुम्ही
ClientHTTPBackoff
SQSVisibility नंतरTimeouts
Lambda asyncDestinationsSQS prefer
SFNPer-stateBackoff

8. Partial batch failure

Batch मध्ये एक poison ≠ सगळं rewind. Item-level failure report.

9. Lab

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

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

  1. Timeout numbers.
  2. Redrive path.
  3. Optional.
  4. Alarm sketch.
  5. Cleanup.

Cleanup (billing थांबवा)

  1. Main then DLQ.
  2. Function+logs.

10. FIFO vs Standard

  • Standard: throughput.
  • FIFO: order.
  • Aisha: FIFO ledger; Standard email.

Attributes

aws sqs get-queue-attributes --queue-url $Q --attribute-names All --region ap-south-1 --query 'Attributes.{V:VisibilityTimeout,R:RedrivePolicy,D:DelaySeconds}'

अर्थ: Load test आधी confirm.

11. Backpressure

Queue = shock absorber; infinite disk नव्हे. API throttle/shed.

12. एकाच 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.

13. 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.

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

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

Error / लक्षणFix
Visibility lowRaise.
No DLQAdd.
Early deleteWrite first.
Ignore ageAlarm.
Huge batchPartial+smaller.
Queue as DBDDB/S3.
Weak keyIntent in key.
Forever DLQRedrive SLA.
Needless FIFOStandard.
No intake alarmAlarm.

15. FAQ

प्र. Only SQS?

Kinesis/MSK too.

प्र. Exactly-once?

Idempotent effect.

प्र. ESM?

Prefer ESM.

प्र. Size?

256KB; else S3.

प्र. Project?

build-async-order.

प्र. Redrive?

DLQ→main.

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

प्र. Beginner queue

Absorb spikes.

प्र. DLQ

Failed often.

प्र. Mid visibility

Visibility > timeout.

प्र. Idempotency

One effect.

प्र. Senior batch

Per-item.

प्र. MNC poison

Alarm+fix+redrive.

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

Ravindra Bagale's Tip (EN)

Tickets on a rail: 202 at the window, steady cooks, DLQ for burnt tickets, idempotent recipes.

Ravindra Bagale's Tip (MR)

Ticket rail: खिडकी 202, steady cook, DLQ, idempotent.

Tip (HI)

टिकट रेल: खिड़की 202, स्थिर कुक, DLQ, idempotent रेसिपी।

घरी करून बघा

  1. Timeouts लिहा.
  2. Idempotency fields.

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

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

18. 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.

19. 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.

20. अजून 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.

21. 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

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

  1. 60s: queue load leveling गोष्ट.
  2. 60s: sync vs async checkout.
  3. 60s: Lambda नको कधी.
  4. 60s: DLQ + idempotency.
  5. Record ×2.

23. Safe lab hygiene

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

25. Myths

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

26. 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.

27. Regional notes (ap-south-1)

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

28. 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 सोपा.

29. Pre-mortems

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

30. Currency / locale

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

31. Failure timeline

  1. Bad JSON throw.
  2. Receive +1.
  3. To DLQ.
  4. Human inspect.
  5. Fix+redrive.

32. Metrics

  • Backlog.
  • Age/SLA.
  • Sent vs Deleted.
  • Concurrency.

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

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

उजळणी card: Load leveling. Direct spike hurts. Queue absorbs; drain safely. API → SQS → alarm age. Ticket rail.
उजळणी card: Load leveling · PNG download करा · Card page उघडा
उजळणी card: Idempotent writes. Double side effects. Conditional put on key. Condition → treat dup OK. Idempotency first.
उजळणी card: Idempotent writes · PNG download करा · Card page उघडा
तुलना: Direct Lambda vs Queue leveled. Direct Lambda: Per-request invoke. Queue leveled: Enqueue then drain.
तुलना: Direct Lambda vs Queue leveled · PNG download करा · Card page उघडा
तुलना: Infinite retry vs maxReceive + DLQ. Infinite retry: Forever retry. maxReceive + DLQ: DLQ + alarm.
तुलना: Infinite retry vs maxReceive + DLQ · PNG download करा · Card page उघडा
मुलाखत card: Visibility timeout. Short visibility. Visibility > timeout. Numbers.
मुलाखत card: Visibility timeout · PNG download करा · Card page उघडा
मुलाखत card: maxReceiveCount + DLQ. Infinite retry. 3–5 → DLQ + alarm. Why not 1.
मुलाखत card: maxReceiveCount + DLQ · PNG download करा · Card page उघडा
मुलाखत card: Partial batch failure. Whole-batch fail. Per-item fail report. Response shape.
मुलाखत card: Partial batch failure · PNG download करा · Card page उघडा
मुलाखत card: Oldest message age. Depth alone. Age vs SLA. Threshold.
मुलाखत card: Oldest message age · PNG download करा · Card page उघडा

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

सराव Tasks

या scenario बद्दल

Milan Furniture हा मिलान मधला फर्निचर व्यवसाय आहे. Giulia Rossi त्यांचं IT व cloud काम पाहतात. त्यांचे पैसे EUR मध्ये मोजले जातात आणि AWS resources eu-south-1 Region मध्ये चालतात. खालच्या tasks मध्ये तुम्ही या lesson मध्ये शिकलेलं वापरून त्यांची खरी कामं करता. सगळी नावं, account IDs, IP addresses व numbers सरावासाठी काल्पनिक आहेत.

0 / 16

सोपं Queue

का: Metaphor.

काय करायचं: Queue metaphor तर 1.

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

सोपं Level

का: Effect.

काय करायचं: Measurable lag तर 1.

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

सोपं Visibility

का: Timing.

काय करायचं: Visibility greater तर 1.

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

सोपं DLQ

का: Safe.

काय करायचं: Failed messages तर 1.

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

सोपं List-queues

का: CLI.

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

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

सोपं Knobs

का: Config.

काय करायचं: visibility/max_receive.

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

सोपं Batch

का: Cost.

काय करायचं: Batch cost तर 1.

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

मध्यम MRC

का: Config.

काय करायचं: Then DLQ तर 1.

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

मध्यम Idem

का: Write.

काय करायचं: Conditional put तर 1.

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

मध्यम PBF

का: Batch.

काय करायचं: Per-item fail तर 1.

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

मध्यम Age

का: SLA.

काय करायचं: Lagging SLA तर 1.

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

मध्यम Idem

का: Write.

काय करायचं: condition/key.

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

अवघड 202

का: API.

काय करायचं: 202 Accepted तर 1.

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

अवघड Not disk

का: Anti.

काय करायचं: Not infinite disk तर 1.

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

अवघड Alarm

का: Ops.

काय करायचं: Alarm age+DLQ तर 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 दाबा.