Event-Driven Architecture
Definition
Event-driven architecture
- In plain English
- Event-driven architecture is a design where services announce facts that happened and other services react to them.
- Think of it like
- It is like a newsroom where reporters announce stories and each desk decides what to do with them.
Event
- In plain English
- An event is a record of something that already happened, named in the past tense, such as OrderPlaced.
- Think of it like
- It is like a stamped entry in a diary.
Command vs event
- In plain English
- A command asks a service to do something, while an event announces that something already happened.
- Think of it like
- Like "please bake a cake" versus "the cake is ready".
Choreography and orchestration
- In plain English
- Choreography lets each service react to events on its own, while orchestration has one coordinator telling each service what to do next.
- Think of it like
- Like dancers each following the music versus a conductor cueing each player.
Saga
- In plain English
- A saga is a multi-step business process across services where each step has an undo action if a later step fails.
- Think of it like
- Like a holiday booking that cancels the hotel if the flight can't be booked.
Event sourcing
- In plain English
- Event sourcing stores every change as an event and rebuilds current state by replaying them.
- Think of it like
- Like working out your bank balance from the full list of transactions.
Why it exists
A ferry booking calls seats, payments, and ticketing in one chain. One unavailable service can interrupt the whole journey.
Separate service databases cannot share an ordinary local transaction. Events and coordinated recovery steps offer another way to finish the booking.
How it works
| Question | Choreography | Orchestration |
|---|---|---|
| Control | Each service reacts | One coordinator directs steps |
| Visibility | Follow several reactions | Follow coordinator state |
| Dependency | Shared event meanings | Coordinator knows participants |
| Good fit | Independent reactions | Multi-step business processes |
The coordinator reserves a slot, receives a payment decline, and asks the seat service to release the slot.
- Name facts in the past tense: DonationReceived or PaymentCaptured.
- Use commands for requests: ReserveSlot or CapturePayment.
- Event-driven design does not require storing every state change as an event.
Compensation
- In plain English
- Compensation is a new business action that counteracts an earlier completed step without rolling back its database transaction.
- Think of it like
- It is like refunding a purchase after its payment has already completed.
Compensation can fail and need retries. Some actions, such as sending an email, cannot be undone; plan irreversible steps and manual recovery.
Examples
Ferry booking
A ferry booking reserves a car slot, charges the card, then issues a ticket. A confirmed payment failure triggers a slot release.
Reserve the slot, charge the card, then issue the ticket. A confirmed payment decline triggers a release.
- A timeout means the payment outcome is unknown; check it before choosing recovery.
- Retry failed releases and alert staff if the booking remains stuck.
The insight
Sagas replace cross-service transactions with steps plus undo actions.
Food bank
DonationReceived triggers inventory updates, a thank-you email, and volunteer scheduling. Each service reacts independently.
Each service receives its own DonationReceived event. Their updates can finish at different times.
DonationReceived sends separate reactions to inventory, thank-you email, and volunteer scheduling.
The insight
Choreography adds new reactions without touching the publisher.
Library ebooks
Loans are stored as Borrowed, Renewed, and Returned events. Replaying them rebuilds current loans and answers who borrowed a book in March.
Replay events in order to rebuild the member’s loans. Keep event meanings readable as software changes.
[
{"type":"Borrowed","loan":"L17","member":"M8","date":"2026-03-02"},
{"type":"Renewed","loan":"L17","date":"2026-03-16"},
{"type":"Returned","loan":"L17","date":"2026-03-23"}
]The insight
Event sourcing keeps the full story, not just the latest state.
Trade-offs
Pros
- Add independent reactions.
- Separate service failure handling.
- Retain business history when events are stored.
Cons
- Following a process takes more work.
- Service views can update at different times.
- Compensation needs retry and recovery plans.
Use when
- Many services react to business facts.
- A process spans separate service databases.
Avoid when
- One local transaction covers the work.
- A small app gains no useful independence.
Quick check
Takeaways
- Events announce facts; commands request actions.
- Choreography reacts independently; orchestration coordinates steps.
- Sagas recover using compensating actions rather than automatic cross-service rollback.