System Design Academy

Saving…

Lesson 8 of 9 in Module 40 of 54 lessons complete

Event-Driven Architecture

Module 4, lesson 8Concept12 min

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

QuestionChoreographyOrchestration
ControlEach service reactsOne coordinator directs steps
VisibilityFollow several reactionsFollow coordinator state
DependencyShared event meaningsCoordinator knows participants
Good fitIndependent reactionsMulti-step business processes

The coordinator reserves a slot, receives a payment decline, and asks the seat service to release the slot.

A failed payment triggers a compensating release.

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.

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

Which is an event rather than a command?
Payment fails after a seat was reserved in another service. In a saga, what happens?

Takeaways

  • Events announce facts; commands request actions.
  • Choreography reacts independently; orchestration coordinates steps.
  • Sagas recover using compensating actions rather than automatic cross-service rollback.

Try the quick check above whenever you feel ready.

Previous: Pub/Sub & Event Streams