Ravindra BagaleCourses & study guides मराठी Track your progress

Event-Driven Serverless: Choreography vs Orchestration Explained

At a wedding, either every relative reacts when they hear the dhol (choreography), or one stage manager cues each act (orchestration). Event-driven serverless uses both. This chapter helps you pick: EventBridge/SNS reactions vs Step Functions as the conductor — and how to avoid spaghetti events.

What you'll learn in this chapter

  • Explain choreography vs orchestration with a wedding story
  • Place EventBridge/SNS vs Step Functions on a decision table
  • Spot spaghetti events and missing ownership
  • Design one order-flow both ways on paper
  • Link EventBridge and Step Functions chapters

1. Everyday example: wedding cues

When the dhol starts, the photographer shoots, the caterer plates, the DJ fades talk music — nobody waits for a central WhatsApp from the host for each micro-step. That is choreography. When the host needs the pheras exactly after the vows, a stage manager sequences it. That is orchestration. Diego in São Paulo models order-paid the same way: inventory and email can react to an event; refund+stock rollback wants a visible workflow.

Deep service chapters: EventBridge, Step Functions, SQS/SNS. This page is the decision layer.

2. Why the distinction matters

Why do we need this?

If everything is choreography, nobody sees the whole story when a step fails at 2 AM. If everything is orchestration, every small notification becomes a state machine you hate to change. Grown systems mix both.

What is it?

Choreography: producers emit events; consumers subscribe; no central brain. Orchestration: a workflow engine tells each step when to run and what to do on failure.

3. Vertical comparison

Event -> Bus/Topic -> Many consumersChoreography path
No single execution id across all consumers
Start -> Step Functions -> Task -> Task -> EndOrchestration path with one execution ARN
Compensations are visible in history

4. Decision table

QuestionPrefer choreographyPrefer orchestration
Many independent reactions?Yes — SNS/EventBridgeNo
Need one visible timeline?Maybe notYes — Step Functions
Need compensations / saga?Hard — invent correlationBuilt-in patterns
Team owns one small side effect?Subscribe and goCentral team owns flow
Audit for regulators?Need good log designExecution history helps

5. How to design an order-paid flow both ways

How to do it (step by step)

Choreography sketch

  1. Order service emits OrderPaid on EventBridge bus.
  2. Inventory rule → Lambda reserve stock.
  3. Email rule → Lambda send receipt (INR/BRL).
  4. Analytics rule → firehose/Lambda.
  5. Each consumer owns retries + DLQ.

Orchestration sketch

  1. API returns 202 and StartExecution on state machine.
  2. Task ReserveStock → Task Charge → Task Email.
  3. Catch on Charge → Task ReleaseStock.
  4. One execution ARN in support tickets.

List event buses

aws events list-event-buses --region ap-south-1

Meaning: Default bus always exists; custom buses isolate domains.

List state machines

aws stepfunctions list-state-machines --region ap-south-1 --query 'stateMachines[].{N:name,A:stateMachineArn}'

Meaning: See what orchestrations already exist before adding another.

6. Spaghetti events — symptoms and fixes

SymptomFix
Everyone listens to almost every eventEvent storms
No owner for an event schemaNo owner
Silent fail in one consumerSilent fail
Circular events A→B→ACycles
Cannot answer where is my orderWhere is order?

7. Worked mini-examples

Python: choose mode

def mode(needs_saga, many_side_effects, need_timeline):
    if needs_saga or need_timeline:
        return "orchestrate"
    if many_side_effects:
        return "choreograph"
    return "either"
print(mode(True, True, False))
print(mode(False, True, False))

Output: orchestrate / choreograph. Meaning: saga/timeline push you to Step Functions.

EventBridge rule shape (concept)

{
  "source": ["shop.orders"],
  "detail-type": ["OrderPaid"],
  "detail": {"currency": ["INR", "BRL"]}
}

Meaning: filter early so the inventory Lambda never wakes for EUR-only analytics noise.

8. Lab: paper both designs + read-only console

Do this in ap-south-1 (Mumbai) unless your org forbids it. Set a budget alert first.

How to do it (step by step)

  1. Draw choreography for OrderPaid with three consumers.
  2. Draw orchestration with one compensation.
  3. Console: EventBridge rules count (read-only).
  4. Console: one state machine definition preview if any.
  5. Write which design you pick for refunds and why.

Cleanup (stop billing)

  1. No creates required; delete any bus/rule you added.
  2. Delete lab state machines.

9. Hybrid: the usual adult answer

Orchestrate the money path (pay, reserve, refund). Choreograph the fan-out notifications (email, push, analytics). Fatima in Casablanca does exactly that for customs: saga in Step Functions, notifications on a bus.

10. Per-concept commands

Put a sample event (sandbox)

aws events put-events --region ap-south-1 --entries '[{
  "Source":"shop.orders","DetailType":"OrderPaid",
  "Detail":"{"orderId":"o-1","currency":"INR"}"}]'

Meaning: Only in sandbox; watch which rules fire.

Describe a state machine

aws stepfunctions describe-state-machine --state-machine-arn $ARN --region ap-south-1 --query 'definition' --output text | head

Meaning: Read definition before changing.

11. Same pattern across industries

  • Fintech (Aisha, Lagos): payment webhooks → SQS → Lambda; never block the bank callback thread.
  • Ecommerce (Rohan, Pune): checkout API on API Gateway+Lambda; inventory fan-out on SNS.
  • Healthcare (Mei, Singapore): appointment SMS via SNS; PHI stays in DynamoDB with fine-grained IAM.
  • EdTech (Diego, São Paulo): nightly cleanup EventBridge → Lambda on student drafts.
  • Logistics (Fatima, Casablanca): package scan events on EventBridge bus; Step Functions for customs saga.
  • Media (Kenji, Osaka): S3 upload → Lambda thumbnails; fan-out to moderation + CDN invalidate.
  • SaaS multi-tenant (Priya, Bengaluru): Cognito groups + DynamoDB partition per tenant.
  • Gov portal (Omar, Amman): strangler fig — peel one PDF form route per sprint to Lambda.

12. Troubleshooting checklist

  1. Confirm region (ap-south-1 vs us-east-1 for CloudFront/ACM quirks).
  2. Check CloudWatch Logs for the function name and request id.
  3. Verify IAM execution role allows the API you call.
  4. For async: check DLQ depth and SQS age of oldest message.
  5. For APIs: curl -v and compare status, CORS headers, body.
  6. For workflows: open Step Functions execution event history.
  7. Re-read the linked deep chapter before reinventing a service.
  8. If cost spikes: check concurrency, retries, and provisioned capacity.

13. Common errors and fixes

Each row is a real mistake students and juniors hit. Read the fix before you panic.

Error / symptomFix
All notifications as SFN statesEmit event; let email subscribe.
No DLQ on EventBridge targetsAdd SQS DLQ per target.
Unversioned event payloadsAdd version field; consumers tolerate.
Circular event stormBreak with orchestration or redesign.
Using SNS when you need content filters + busesPrefer EventBridge for rich filters.
Mega state machine for everythingSplit by domain.
Ignoring execution history costsLog levels; short retention where OK.
No correlation id in choreographyPass orderId everywhere.
Assuming at-least-once never duplicatesIdempotent consumers.
Editing prod rules without dry-runStage bus first.

14. FAQ

Q. Is EventBridge better than SNS?

Different: EB has rich filters/buses/archive; SNS is simple fan-out/SMS.

Q. Is Step Functions expensive?

Pay per transition; fine for business flows; not for millions of tiny ticks.

Q. Can I mix both?

Yes — normal.

Q. What about SQS?

Buffer between; works under both styles.

Q. Where is the order workflow project?

build-order-workflow — orchestration example.

Q. Choreography testing?

Contract tests per consumer + replay from archive.

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

Q. Beginner: choreography in one line?

Services react to events without a central conductor.

Q. Beginner: orchestration?

A workflow engine sequences steps.

Q. Mid: when SFN over EB?

Saga, compensations, single timeline.

Q. Mid: DLQ ownership?

Each target owns its DLQ and alarm.

Q. Senior: prevent event spaghetti?

Schema ownership, versioning, filters, domain buses.

Q. MNC: audit story?

SFN history for money path; immutable logs for choreography side effects.

16. Tips in English, Marathi and Hindi

Ravindra Bagale's Tip (EN)

Orchestrate money; choreograph noise. Draw both before you pick.

Ravindra Bagale's Tip (MR)

Money = orchestrate; noise = choreograph. दोन्ही कागदावर.

Tip (HI)

पैसे orchestrate करें; notify choreograph करें। दोनों कागज़ पर बनाएं।

Try at home

  1. Pick one flow at work; label orchestrate vs choreograph.
  2. Name the event owner team.

In short

  1. Start from a real story, then name the AWS services.
  2. Link existing chapters — do not copy their labs.
  3. Design for failure: retries, DLQ, idempotency, rollback.
  4. Measure before you buy provisioned concurrency or multi-region.

17. Correlation and causation ids

In choreography, every event should carry orderId (correlation) and a unique eventId (causation chain). Support engineers paste one id and reconstruct the story across logs.

{"eventId":"e-9f","orderId":"o-1","type":"OrderPaid","currency":"AED","version":1}

18. When to introduce a custom bus

  • Domain isolation: payments vs marketing.
  • Different archive/replay policies.
  • Least-privilege put-events per team.

19. Step Functions patterns cheat sheet

PatternUse
Task + Retry + CatchMost Lambda tasks
ParallelFan-out inside orchestration
MapProcess array with capped concurrency
WaitCallbacks, human delay, SLA pause
ChoiceBranch on currency or risk score

20. Architecture decision checklist

  1. Write the user journey in five bullets with no AWS names.
  2. Mark each step sync (user waits) or async.
  3. Name failure mode: retry, DLQ, compensate, or alert-only.
  4. Name the idempotency key for every write.
  5. Pick data store from access patterns (link DynamoDB modeling).
  6. Estimate monthly cost at 1x and 10x traffic (USD and INR).
  7. Confirm account concurrency and service quotas in ap-south-1.
  8. Decide auth: Cognito, IAM, Lambda authorizer, or none.
  9. Name on-call and which CloudWatch alarm pages them.
  10. Link the deep chapter you will not rewrite.
  11. Only then open console or IaC.

21. Copy-paste quick commands (read-only first)

# 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

Run these in a sandbox account. Prefer read-only IAM while learning.

22. More industry and stack stories

  • Fintech (Aisha, Lagos, NGN): bank webhooks must return 200 fast — SQS absorbs spikes; ledger Lambda is idempotent on paymentId.
  • Ecommerce (Rohan, Pune, INR): Black Friday — API Gateway throttle + SQS order intake; SNS fans inventory, email, analytics.
  • Healthcare (Mei, Singapore, SGD): appointment reminders via SNS SMS; PHI only in DynamoDB with condition keys.
  • EdTech (Diego, São Paulo, BRL): EventBridge nightly cleanup of draft quizzes; Lambda timeout 30s, not 15 min.
  • Logistics (Fatima, Casablanca, MAD): package scans on custom EventBridge bus; Step Functions customs saga.
  • Media (Kenji, Osaka, JPY): S3 → Lambda thumbnails; never write thumbs to the watched prefix.
  • SaaS (Priya, Bengaluru, INR): Cognito groups + DynamoDB PK tenantId; one Lambda authorizer for all routes.
  • Gov (Omar, Amman, JOD): strangler — peel one PDF form route per sprint from the monolith.
  • Startup (Sofia, Sofia, EUR): start with Function URL for demos; move to HTTP API when partners need JWT.
  • Retail (Luis, Mexico City, MXN): store POS sync via SQS FIFO when order matters; Standard when it does not.
  • Python: handlers thin; put domain logic in plain modules for unit tests without Lambda.
  • Node: prefer async/await; never block the event loop on sync DNS.
  • Java: SnapStart for cold starts; keep dependencies lean.
  • .NET: AspNetCoreServer for low-traffic tenants; watch package size.
  • Go: single static binary; great for SQS workers.
  • PHP: keep Laravel queues on ECS; Lambda for S3/webhooks glue.

23. Glossary (short)

TermMeaning
Cold startFirst invoke pays init; later invokes reuse the env
IdempotencySame request twice → same effect
DLQDead-letter queue for failed messages
ChoreographyServices react to events; no central conductor
OrchestrationCentral workflow (Step Functions) directs steps
Fan-outOne event → many consumers
Fan-inMany branches join before next step
Strangler figPeel routes from monolith gradually
SagaDistributed tx via steps + compensations
Provisioned concurrencyKeep N envs warm; you pay for ready capacity

24. Practice: explain out loud

  1. 60 seconds: everyday story for choreography vs orchestration.
  2. 60 seconds: sync vs async with a checkout example.
  3. 60 seconds: when you refuse Lambda.
  4. 60 seconds: DLQ + idempotency in one breath.
  5. Record once; cut fillers; record again.

25. Safe lab hygiene

  • Tag every lab resource with owner and expiry date.
  • Set a monthly AWS Budget alarm in INR or USD before experiments.
  • Prefer read-only commands first; mutate in a sandbox account.
  • Delete queues, APIs, tables you created — DynamoDB and APIGW leave footprints.
  • Never put production secrets in env vars or screenshots.
  • Do not enable provisioned concurrency for a hello-world.

27. Myths to drop

MythReality
Serverless means zero serversServers exist; you do not manage them
Always cheaper than EC2Steady high load can favor EC2/Savings Plans
No Ops neededYou own IAM, data, alarms, cost, incidents
One Lambda per app is fineBounded contexts scale better
Queues are optional decorationQueues are the load leveler and blast-radius wall

28. Error budget thinking for serverless

If your monthly error budget is 0.1% on checkout, a fan-out that retries aggressively can burn the budget with duplicate emails while money stays correct. Separate business correctness SLOs from notification SLOs.

  1. Write two SLOs: money-correct and notify-delivered.
  2. Retries on money path: bounded + idempotent.
  3. Retries on notify path: best-effort + DLQ.
  4. Page humans on money DLQ; ticket on notify DLQ.

29. Regional notes (ap-south-1)

  • Build labs in Mumbai (ap-south-1) unless your org mandates elsewhere.
  • Some services launch first in us-east-1 — check feature availability.
  • Data residency for INR fintech may require in-region only.
  • Latency to end users in India usually favors ap-south-1.

30. Naming conventions that save incidents

# 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

Include env (dev/stage/prod) and domain. Future you grepping CloudWatch will thank present you.

31. Pre-mortems (ten minutes)

  1. Imagine tomorrow headline: double charge in AED. What broke?
  2. Imagine DLQ depth 50,000 after a bad deploy. How do you drain?
  3. Imagine Cognito outage. Do APIs fail closed or serve read-only?
  4. Write answers in the runbook before go-live.

32. Currency and locale in examples

Rotate currencies in designs: INR, USD, EUR, AED, NGN, BRL, JPY, SGD. Rotate names: Aisha, Rohan, Mei, Diego, Fatima, Kenji, Priya, Omar, Sofia, Luis. This keeps mental models global — not one-country samples.

Revision, interview and comparison cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

Revision card: Choreo vs orchestration. One style for every flow either spaghetti-events or a mega state machine. Choreography = react on bus; orchestration = Step Functions sequences. Money path → SFN; notifications → EventBridge/SNS. Priya Deshmukh draws both boxes before picking tools.
Revision card: Choreo vs orchestration · Download PNG · Open card page
Revision card: Hybrid adult answer. Orchestrating likes and emails bloats the state machine. Orchestrate critical money; choreograph side effects with DLQs. Split diagram → SFN for refund → bus for email/SMS. Kenji Tanaka answers hybrid in every senior interview.
Revision card: Hybrid adult answer · Download PNG · Open card page
Comparison: Choreography vs Orchestration. Choreography: Services react to events; no central engine. Orchestration: Step Functions sequences and compensates.
Comparison: Choreography vs Orchestration · Download PNG · Open card page
Comparison: Money path SFN vs Notify on bus. Money path SFN: Orchestrate charge/refund with compensations. Notify on bus: Choreograph email/SMS/analytics off the bus.
Comparison: Money path SFN vs Notify on bus · Download PNG · Open card page
Interview card: Choreography fit. A central conductor for every email creates a bottleneck. Independent side effects fit EventBridge/SNS with filters and DLQs. MNC: give one choreography example and one orchestration example.
Interview card: Choreography fit · Download PNG · Open card page
Interview card: Saga compensations. Partial refunds without reverse steps leave money wrong. Step Functions saga with catch/compensate on failure paths. MNC: sketch compensate for charge-then-reserve-inventory failure.
Interview card: Saga compensations · Download PNG · Open card page
Interview card: Correlation id. Support cannot rebuild a story across consumers without a shared id. Propagate correlation id on every event and log line. MNC: where do you put the id — envelope field name?
Interview card: Correlation id · Download PNG · Open card page
Interview card: Per-target DLQ. One shared DLQ mixes unrelated failures. Each EventBridge target owns DLQ + alarm + owner. MNC: what metric/alarm do you put on that DLQ?
Interview card: Per-target DLQ · Download PNG · Open card page

More cards: Ravi Sir's Cards.

Practice Tasks

About this scenario

London Legal LLP is a law business in London. Oliver Hughes looks after its IT and cloud work. They count money in GBP and run their AWS resources in the eu-west-2 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 16

Easy Choreography no conductor — 1

Why: Style.

What to do: Enter 1 if choreography means services react without a central conductor.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Orchestration has engine — 1

Why: Style.

What to do: Enter 1 if orchestration uses a workflow engine to sequence steps.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Refund saga → SFN — 1

Why: Fit.

What to do: Enter 1 if a refund saga with compensations fits Step Functions.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Side effects choreography — 1

Why: Fit.

What to do: Enter 1 if fan-out email/analytics side effects often fit choreography.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy List EventBridge rules

Why: CLI.

What to do: List rules on default bus

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Styles YAML

Why: Map.

What to do: YAML: choreography: bus, orchestration: sfn.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.

Easy Filters reduce noise — 1

Why: Hygiene.

What to do: Enter 1 if event filters reduce unnecessary invocations.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Spaghetti everyone listens — 1

Why: Smell.

What to do: Enter 1 if spaghetti events mean everyone listens to almost every event.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium EventBridge filters — 1

Why: Tool.

What to do: Enter 1 if EventBridge offers richer filters, buses, archive/replay than basic SNS.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Correlation id — 1

Why: Trace.

What to do: Enter 1 if a correlation id helps reconstruct a story across consumers.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Break A→B→A — 1

Why: Anti.

What to do: Enter 1 if circular A→B→A events should be broken by redesign or orchestration.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Hybrid YAML

Why: Split.

What to do: YAML: money: sfn, notify: bus.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.

Hard Hybrid money vs notify — 1

Why: Adult.

What to do: Enter 1 if you orchestrate money path and choreograph notifications.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard Each target owns DLQ — 1

Why: Ops.

What to do: Enter 1 if each EventBridge target should own its DLQ and alarm.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard Schema ownership — 1

Why: Contract.

What to do: Enter 1 if event schemas need clear owners.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard Delete lab same day — 1

Why: Hygiene.

What to do: Enter 1 if lab-spc-events should be deleted same day.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.