Event-Driven Architecture: The Complete Guide for 2026
Event-Driven Architecture: The Complete Guide#
Every major system — Uber, Netflix, Stripe, LinkedIn — runs on events. When a user places an order, that's an event. When a payment succeeds, that's an event. When a driver accepts a ride, that's an event.
Event-driven architecture (EDA) is how you build systems that react to things happening instead of waiting to be asked.
Request-Driven vs Event-Driven#
Request-driven (synchronous):
User → API → Order Service → Payment Service → Inventory Service → Email Service
↑ waiting... waiting... waiting...
Each service calls the next and waits. If Email Service is slow, the entire chain is slow.
Event-driven (asynchronous):
User → API → Order Service → publishes "OrderCreated" event
↓
Message Broker (Kafka)
↓ ↓ ↓
Payment Inventory Email
Service Service Service
Order Service publishes an event and returns immediately. Downstream services process independently.
Core Patterns#
1. Event Notification#
The simplest pattern. A service publishes a lightweight event; others react if they care.
{
"type": "order.created",
"data": { "orderId": "abc123", "userId": "user456" }
}
Consumers fetch full details from the source if needed. Low coupling, but requires additional API calls.
2. Event-Carried State Transfer#
The event contains all the data consumers need — no callbacks required.
{
"type": "order.created",
"data": {
"orderId": "abc123",
"userId": "user456",
"items": [{ "productId": "p1", "quantity": 2, "price": 29.99 }],
"total": 59.98,
"shippingAddress": { "city": "SF", "zip": "94105" }
}
}
Consumers are self-sufficient but coupled to the event schema.
3. Event Sourcing#
Instead of storing current state, store the sequence of events that led to it.
Event Log:
1. AccountCreated { id: "acc1", name: "Alice" }
2. MoneyDeposited { id: "acc1", amount: 1000 }
3. MoneyWithdrawn { id: "acc1", amount: 200 }
4. MoneyDeposited { id: "acc1", amount: 500 }
Current State: balance = 1000 - 200 + 500 = $1300
Benefits: Complete audit trail, time travel (replay to any point), no data loss. Cost: Complex queries (need projections), eventual consistency, storage growth.
4. CQRS (Command Query Responsibility Segregation)#
Separate the write model (commands) from the read model (queries):
Write Path: API → Command Handler → Event Store → publishes events
Read Path: API → Query Handler → Read Database (optimized views)
↑
Event Processor (builds read models from events)
When: Reads and writes have very different patterns. Example: e-commerce catalog (millions of reads, hundreds of writes per second).
Message Brokers Compared#
| Feature | Kafka | RabbitMQ | AWS SQS |
|---|---|---|---|
| Model | Distributed log | Message queue | Managed queue |
| Ordering | Per-partition | Per-queue | Best-effort (FIFO available) |
| Retention | Days/weeks (configurable) | Until consumed | 14 days max |
| Throughput | 1M+ msg/sec | 30K msg/sec | Unlimited (managed) |
| Replay | Yes (consumers seek) | No (messages deleted) | No |
| Best for | Event streaming, logs, analytics | Task queues, RPC | Simple async tasks |
| Complexity | High (ZooKeeper/KRaft, partitions) | Medium | Low (managed) |
When to Use Each#
- Kafka — You need event replay, high throughput, or multiple consumers per event
- RabbitMQ — You need routing, priorities, or request-reply patterns
- SQS — You want managed, simple, with no operational overhead
The Saga Pattern#
How do you handle transactions across multiple services?
Choreography — services react to each other's events (no coordinator):
Order Created → Payment Service charges card
Payment Succeeded → Inventory Service reserves items
Inventory Reserved → Shipping Service creates shipment
Orchestration — a saga coordinator tells each service what to do:
Saga Orchestrator:
1. Tell Payment: charge card
2. If success → Tell Inventory: reserve items
3. If success → Tell Shipping: create shipment
4. If any fails → compensate (refund, unreserve)
| Choreography | Orchestration | |
|---|---|---|
| Coupling | Low (services don't know each other) | Medium (orchestrator knows all) |
| Visibility | Hard to trace the flow | Easy to see full saga state |
| Complexity | Grows with number of services | Centralized logic |
| Best for | Simple flows (2-3 steps) | Complex flows (4+ steps) |
When NOT to Use Events#
Events add complexity. Don't use them when:
- Simple CRUD — A monolith with direct function calls is simpler
- Strong consistency required — Events are eventually consistent
- Small team — The operational overhead isn't worth it for < 5 engineers
- Request-response fits — If the caller needs an immediate answer, use sync
- Debugging matters more than decoupling — Distributed tracing is hard
Architecture Examples#
E-Commerce Order Flow#
Web App → API Gateway → Order Service → Kafka
↓
Payment Service (charges card)
Inventory Service (reserves stock)
Email Service (sends confirmation)
Analytics Service (tracks conversion)
Real-Time Analytics Pipeline#
App Events → Kafka → Stream Processor (Flink/Spark)
↓
ClickHouse (analytics DB)
↓
Grafana Dashboard
IoT Data Pipeline#
Sensors → MQTT Broker → Kafka → Stream Processor
↓ ↓
Time-Series DB Alert Service
(InfluxDB) (PagerDuty)
Getting Started#
- Start with a queue — SQS or RabbitMQ for simple async tasks
- Graduate to Kafka when you need replay, multiple consumers, or event sourcing
- Add CQRS when read and write patterns diverge significantly
- Implement sagas when transactions span multiple services
- Always add dead-letter queues — events that fail processing need a place to go
Summary#
| Pattern | When | Complexity |
|---|---|---|
| Event Notification | Decouple services, fire-and-forget | Low |
| Event-Carried State | Consumers need full data, no callbacks | Medium |
| Event Sourcing | Audit trail, time travel, financial systems | High |
| CQRS | Different read/write patterns at scale | High |
| Saga (choreography) | Simple multi-service transactions | Medium |
| Saga (orchestration) | Complex multi-service transactions | Medium-High |
Design your event-driven architecture at codelit.io — generate interactive diagrams, run performance audits, and export as Kafka + infrastructure code.
Try it on Codelit
Chaos Mode
Simulate node failures and watch cascading impact across your architecture
Related articles
AI Agent Tool Use Architecture: Function Calling, ReAct Loops & Structured Outputs
6 min read
AI searchAI-Powered Search Architecture: Semantic Search, Hybrid Search, and RAG
8 min read
AI safetyAI Safety Guardrails Architecture: Input Validation, Output Filtering, and Human-in-the-Loop
8 min read
Try these templates
Netflix Video Streaming Architecture
Global video streaming platform with adaptive bitrate, CDN distribution, and recommendation engine.
10 componentsSearch Engine Architecture
Web-scale search with crawling, indexing, ranking, and sub-second query serving.
8 componentsGoogle Search Engine Architecture
Web-scale search with crawling, indexing, PageRank, query processing, ads, and knowledge graph.
10 components
Comments