Event-Driven Architecture
Structure a system around events: components announce what happened, and other components react, instead of calling each other directly.
Description
In an event-driven system, components communicate by publishing events, facts about something that happened such as OrderPlaced or PaymentFailed, to a broker. Other components subscribe and react on their own. The producer doesn't know who listens or wait for them.
This decouples parts in time and in knowledge: consumers can be added, removed or briefly down without affecting producers, and work spreads naturally across services. The price is that the overall flow is harder to see, and data becomes eventually consistent.
System design
Event-Driven Architecture system design diagram
- Checkout (service): producer.
- Event broker (topic).
- Warehouse (service).
- Loyalty points (service).
- Fraud check (function).
- Step 1: Checkout → Event broker: OrderPlaced.
- Step 2: Event broker → Warehouse: pick & pack.
- Step 3: Event broker → Loyalty points: add points.
- Step 4: Event broker → Fraud check: score order.
- Step 5: Fraud check → Event broker: OrderFlagged.
- Checkout publishes the fact that an order was placed, then moves on.
- The warehouse reacts by preparing the shipment.
- Loyalty adds points. It was added last month without touching checkout.
- Fraud checking scores the order in parallel.
- When fraud finds something, it publishes its own event, OrderFlagged, which others can react to in turn.
- AWS
- Amazon EventBridge; SNS/SQS; Amazon MSK or Kinesis for streams.
- Azure
- Event Grid; Service Bus; Event Hubs.
- Google Cloud
- Pub/Sub; Eventarc.
When to use it
Use it when
- Several parts of the system react to the same business events, and the list of reactions grows.
- Components should keep working when others are slow or down.
- You need an audit trail or real-time streams of business activity, for analytics or integrations.
Avoid it when
- The caller needs an immediate answer to continue. Use a request/response API for that step.
- The workflow is a strict sequence that must be easy to follow. Explicit orchestration may be clearer.
- The team is small and the system simple. Direct calls are easier to build and debug.
Pitfalls
- Invisible flows: nobody can say what happens after an event. Document event flows and use tracing across the broker.
- Events used as commands in disguise ("SendEmailNow"), recreating tight coupling. Events state facts.
- Duplicate and out-of-order delivery. Make consumers idempotent and tolerant of reordering.
- Schema changes breaking unknown consumers. Version events and use a schema registry.
Alternatives
Microservices
Choose it when the goal is independent deployment by team; events are one of the ways services talk.
Saga (orchestration)
Choose it when a business process needs a clear owner and compensations, not just reactions.
Request/response APIs
Choose it when interactions are simple queries and commands that need immediate answers.