CMD Guide
HomeSystem DesignMicroservices Patterns

The Architecture of the Event-Driven Architecture Pattern

Event-Driven Architecture (EDA) is a style in which components communicate by producing and reacting to events rather than calling each other directly. An event is an immutable record that something happened — MotionDetected, OrderPlaced, TemperatureChanged. The producer that emits it does not know, and does not care, who will consume it. That single fact — the decoupling of "something happened" from "what to do about it" — is the source of every benefit and every headache in EDA.

The moving parts

Two structural questions decide the shape of the whole system: who owns the routing and business decisions, and how tightly are producers coupled to consumers. Those questions produce two canonical topologies — Mediator and Broker — plus a Hybrid that mixes them.

Two topologies, one core trade-off

Mediator (orchestration)

A central mediator knows the producers and consumers and orchestrates the flow. Producers send events to the mediator; the mediator applies routing, filtering, transformation, and multi-step business logic, then dispatches commands to the appropriate consumers. The workflow lives in one place, so it is easy to read, reorder, and reason about.

Price: the mediator is a single point that every event flows through. It can become a throughput bottleneck and a scaling/availability chokepoint, and it accumulates coupling — as you add features, the mediator gets fatter.

Put a number on the chokepoint. Suppose the mediator spends 2 ms of CPU per event on routing + transformation (an assumption — measure yours). One single-threaded mediator instance then saturates at roughly 1 / 0.002 = 500 events/s; at 5,000 events/s you need ~10 workers — and now the mediator is itself a distributed system whose workflow state needs shared storage and whose ordering guarantees need re-deriving. The broker topology sidesteps this because partitioned consumers scale horizontally without shared workflow state. This is exactly why hybrid designs keep the firehose on the broker and route only the low-volume, high-value workflows through the mediator.

Broker (choreography)

There is no central coordinator. Producers publish events directly to channels on the bus; consumers subscribe and react independently. The bus just moves events. This is highly scalable and evolvable — you can add a new consumer to an existing event stream without touching the producer or any other consumer.

Price: the business logic is now scattered across consumers. No single component knows the end-to-end flow, which makes a multi-step process harder to trace, debug, and change coherently.

DimensionMediatorBroker
Routing controlCentralized, rich (filter/transform/orchestrate)Minimal — publish/subscribe only
ScalabilityLimited by the mediator (bottleneck)High — no central chokepoint
EvolvabilityChange the mediator to change flowAdd/remove consumers freely
Where logic livesOne place (easy to reason about)Scattered across consumers
End-to-end visibilityGood — the mediator is the mapPoor — flow is emergent

Hybrid EDA uses a broker for high-volume ingestion and fan-out, and a mediator for the few workflows that genuinely need central orchestration — capturing most of the throughput of broker with the control of mediator where it matters.

diagram
diagram

Trace one event through both topologies

Take a concrete home-automation requirement: when the front-door motion sensor fires, turn on the porch light — but only at night. The interesting question is not "does the light turn on" but where the "only at night" decision lives. That is exactly what the topology decides.

Mediator: the decision is central

#ComponentAction
1Motion sensor (producer)Detects movement, emits MotionDetected{ time } to the mediator. It knows nothing about lights or night.
2MediatorReceives the event, applies the rule if isNight(time), and only then issues a TurnOnLight command.
3Porch light (consumer)Receives an explicit command and switches on. It is "dumb" — it never evaluates the rule.

The night-check sits in one place. To later say "also only when nobody is home", you edit the mediator and nothing else.

Broker: the decision is at the edge

#ComponentAction
1Motion sensor (producer)Publishes MotionDetected{ time } to the motion topic. Same event, no addressee.
2Event busFans the event out to every subscriber of motion — no logic, just delivery.
3Porch light (consumer)Receives the event and evaluates if isNight(time) itself, then switches on. The light is "smart".

The night-check now lives inside the consumer. The upside: a new subscriber — say a security camera — can react to the very same MotionDetected stream without anyone changing the sensor or the light. The downside: if three consumers each need the night rule, that logic is now copied in three places, and no single component describes the whole behavior.

Choosing well: the selection layer

Mediator vs Broker

EDA vs plain request/response

Don't default to events. Prefer synchronous request/response when the caller needs an immediate answer, when you want strong/read-your-write consistency, or when the interaction is a simple one-to-one call — an async event round-trip only adds latency and moving parts there. Prefer EDA when you want temporal decoupling (producer and consumer need not be up at the same time), fan-out to many/unknown consumers, resilience to consumer slowness via buffering, or the freedom to add reactions later without touching the source. A useful tell: if the producer needs the result to continue, that is a call; if it is simply announcing a fact, that is an event.

Pitfalls that bite in production

Takeaways

Source

Mediator and Broker EDA topologies and their trade-offs follow the canonical treatment in Mark Richards, Software Architecture Patterns (O'Reilly). The idempotency, dead-letter, correlation-ID, and event-carried-state-transfer (fat vs thin event) practices draw on Sam Newman, Building Microservices (2nd ed., O'Reilly), and Martin Fowler's writing on event-driven architectures. The home-automation MotionDetected walkthrough and step tables are original teaching material built on top of those sources.

🤖 Don't fully get this? Learn it with Claude

Stuck on The Architecture of the Event-Driven Architecture Pattern? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **The Architecture of the Event-Driven Architecture Pattern** (System Design) and want to truly understand it. Explain The Architecture of the Event-Driven Architecture Pattern from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **The Architecture of the Event-Driven Architecture Pattern** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **The Architecture of the Event-Driven Architecture Pattern** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **The Architecture of the Event-Driven Architecture Pattern** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes