Event-Driven ArchitectureDS-02 · theory

Source · Building Event-Driven Microservices / Event-Driven Data Mesh (O'Reilly)

Why this matters

Building Event-Driven Microservices, Ch. 1

As systems grow, tightly synchronous request/response chains become brittle: one slow or down service stalls the whole call graph. Event-driven architecture (EDA) decouples producers from consumers, so services can evolve, fail, and scale independently.

EDA is the backbone of modern streaming platforms, microservice choreography, and real-time analytics. Getting the mental model right — events versus commands, pub/sub, eventual consistency — is essential to reasoning about these systems.

The concept

Building Event-Driven Microservices, Ch. 2–4

An event is an immutable statement of fact about something that already happened — 'OrderPlaced'. A command is a request for something to happen — 'PlaceOrder' — and expects an owner to act. Events are named in the past tense and have no single addressed recipient; commands are imperative and directed.

Events flow through pub/sub: producers publish to a topic, and any number of subscribers consume independently. An event streaming platform like Kafka persists these events as an ordered, replayable log rather than a transient message, so consumers can read at their own pace, replay history, and join late. Because consumers update asynchronously, the system exhibits eventual consistency — different services converge to the same state over time, not instantly. Event sourcing stores state as the full sequence of events (the log is the source of truth), and CQRS separates the write model from optimized read models, often rebuilt from that event stream.

Worked scenario

Building Event-Driven Microservices, Ch. 5

A checkout emits an 'OrderPlaced' event to a Kafka topic. Independently, an inventory service decrements stock, a billing service charges the card, and an email service sends a receipt — each a subscriber, none aware of the others.

If the email service is down, orders still process; when it recovers it resumes from its committed offset and catches up by replaying missed events. State is eventually consistent: for a brief window the order exists but the receipt hasn't sent. Adding a new 'fraud-check' consumer later requires zero changes to checkout — it simply subscribes to the same topic.

How it connects

Building Event-Driven Microservices, Ch. 9

EDA is the coupling glue for the stateless services of DS-01 and the plumbing beneath flow architectures (DS-04) and the data mesh (DS-03), where domain events become shared data products.

Serverless functions (DS-05) are frequently triggered by exactly these events, making EDA the connective tissue of the whole path.

Common traps
  • Confusing events with commands — an event states a fact ('OrderPlaced'), a command requests an action ('PlaceOrder').
  • Expecting immediate consistency across consumers — EDA is eventually consistent by design.
  • Treating a Kafka topic like a queue that is emptied on read; it's a retained, replayable log consumers read by offset.
Key takeaways
  • Events are immutable past-tense facts with no addressed recipient; commands are directed requests for action.
  • Pub/sub plus a persistent log (Kafka) decouples producers from consumers and enables replay.
  • Consumers converge asynchronously — plan for eventual consistency; event sourcing + CQRS build on the log.