Topic 113 / Core
Event-driven architecture
Chapter 7.3 · Event-Driven Architecture and Delivery Guarantees
What and why
Services that call each other synchronously (→ 105) couple not just in time but in knowledge — the caller must know who to call. In event-driven architecture, a service emits a fact about what happened ("OrderPlaced") without knowing who, if anyone, cares, and other services subscribe and react; publish/subscribe (→ 109) is the delivery mechanism underneath. Builds on: → 109.
Diagram
| Style | Event carries | Consumer gets details by |
|---|---|---|
| Event notification | Just enough to identify the subject (e.g. order_id) |
Calling back to the source |
| Event-carried state transfer | The data needed to act (e.g. the full order) | Reading the event itself |
How it works
- A service completes a meaningful state change and publishes an event named for what happened, not for what a consumer should do — "OrderPlaced," not "SendEmail."
- Zero, one, or many subscribers receive the event independently (→ 109).
- Event notification: the event carries just enough to identify the subject; interested consumers call back to the source for details.
- Event-carried state transfer: the event carries the data a consumer needs, so it can act without calling back, at the cost of duplicated, potentially stale data.
- The event's shape needs the same contract discipline as an API response — consumers depend on it just as much (→ 34, 36).
Practical example
(illustrative). "OrderPlaced" is published once. Shipping, using
event-carried state transfer with the order lines embedded, starts packing immediately with
no callback. Analytics, using event notification with only order_id in the event, queries
the order service's API for full details later during its nightly batch — two valid
choices for two different latency needs on the same event.
When to use it
- Use when consumers' reactions don't need to be synchronous, and the set of interested consumers can grow without the producer changing.
- Avoid when a caller needs an immediate answer to proceed (→ 105 stays synchronous), or the business logic genuinely needs one traceable, linear flow.
- Failure scenarios: no single service holds the full picture of "what happens when an order is placed" — debugging requires tracing across every subscriber (→ 201); a skipped schema version (→ 34, 35) breaks every subscriber at once.
- Simpler alternative: a direct synchronous call chain, when there is genuinely one consumer and one flow to reason about.
Practice
(decision — judge scenarios and defend the choice; 15–20 min, lab Kafka). For Project 10's notification platform, decide for "OrderPlaced," "OrderCancelled," and "UserEmailChanged" whether each should be a thin notification or a fat state-transfer event, justified by what the notification consumer actually needs. Done when each choice names the specific field that drove it.
Shared lab setupKey takeaway
Event-driven architecture trades a traceable call chain for independent, decoupled reactions to facts, paid for in observability and schema discipline. Done when you can: pick notification vs. state-transfer for a given event and defend it. Used next in → 114 (ordering events from multiple sources), → 120 (event sourcing makes the events themselves the record).
References
None — this topic makes no external claims.
Source directory