Event-Driven Architecture Patterns
Expert guidance for designing, implementing, and operating event-driven systems with proven patterns for event sourcing, CQRS, message brokers, saga coordination, and eventual consistency management.
When to Use This Skill
- Designing systems with asynchronous, decoupled communication
- Implementing event sourcing and CQRS patterns
- Building systems requiring eventual consistency and high scalability
- Managing distributed transactions across microservices
- Processing real-time event streams and data pipelines
- Implementing publish-subscribe or message queue architectures
- Designing reactive systems with complex event flows
Core Principles
1. Events as First-Class Citizens
Events represent immutable facts that have occurred in the system. Use past tense naming (OrderCreated, PaymentProcessed) and include all necessary context.
2. Eventual Consistency
Systems achieve consistency over time rather than immediately. Trade strong consistency for higher availability and scalability.
3. Loose Coupling
Services communicate through events without direct dependencies, enabling independent evolution and deployment.
4. Asynchronous Communication
Operations don't block waiting for responses, improving system responsiveness and resilience.
5. Event-Driven Thinking
Design around what happened (events) rather than what to do (commands).
Quick Reference
| Topic |
Load reference |
| Event structure, types, and characteristics |
skills/event-driven-architecture/references/event-fundamentals.md |
| Event sourcing pattern and implementation |
skills/event-driven-architecture/references/event-sourcing.md |
| CQRS pattern with read/write separation |
skills/event-driven-architecture/references/cqrs.md |
| Message brokers (RabbitMQ, Kafka, SQS/SNS) |
skills/event-driven-architecture/references/message-brokers.md |
| Saga pattern for distributed transactions |
skills/event-driven-architecture/references/saga-pattern.md |
| Choreography vs orchestration patterns |
skills/event-driven-architecture/references/choreography-orchestration.md |
| Eventual consistency and conflict resolution |
skills/event-driven-architecture/references/eventual-consistency.md |
| Best practices, anti-patterns, testing |
skills/event-driven-architecture/references/best-practices.md |
Workflow
1. Design Phase
- Identify Events: What business facts need to be captured?
- Define Boundaries: Which events are domain vs integration events?
- Choose Patterns: Event sourcing? CQRS? Sagas? Choreography or orchestration?
- Select Technology: Kafka for high throughput? RabbitMQ for routing? AWS managed services?
2. Implementation Phase
- Event Schema: Define versioned event structures with correlation IDs
- Event Store: Implement append-only storage with optimistic concurrency
- Projections: Create read models from events for query optimization
- Handlers: Ensure idempotent, at-least-once delivery handling
- Sagas: Implement compensating transactions for failures
3. Operation Phase
- Monitoring: Track event lag, processing time, failure rates
- Replay: Build capability to replay events for debugging/recovery
- Versioning: Support multiple event schema versions simultaneously
- Scaling: Partition by aggregate ID, scale consumers horizontally
- Testing: Test handlers in isolation with contract testing
Common Mistakes
Event Design Errors
- ❌ Using commands instead of events (CreateOrder vs OrderCreated)
- ❌ Mutable events or missing versioning
- ❌ Events without correlation/causation IDs
- ✓ Immutable, past-tense, self-contained events
Consistency Issues
- ❌ Assuming immediate consistency across services
- ❌ Not handling duplicate event delivery
- ❌ Missing idempotency in handlers
- ✓ Design for eventual consistency, idempotent handlers
Architecture Mistakes
- ❌ Synchronous event chains (waiting for responses)
- ❌ Events coupled to specific service implementations
- ❌ No compensation strategy for sagas
- ✓ Async fire-and-forget, domain-focused events, compensating transactions
Operational Gaps
- ❌ No event replay capability
- ❌ Missing monitoring for event lag
- ❌ No schema registry or version management
- ✓ Replay-ready, monitored, schema-managed events
Pattern Selection Guide
Use Event Sourcing When:
- Need complete audit trail of all changes
- Temporal queries required ("state at time T")
- Multiple projections from same events
- Event replay for debugging/recovery
Use CQRS When:
- High read:write ratio (10:1+)
- Complex query requirements
- Need to scale reads independently
- Different databases for read/write optimal
Use Sagas When:
- Distributed transactions across services
- Need atomicity without 2PC
- Complex multi-step workflows
- Compensation logic required
Choose Choreography When:
- Simple workflows (2-4 steps)
- High service autonomy desired
- Event-driven culture established
- No complex dependencies
Choose Orchestration When:
- Complex workflows (5+ steps)
- Sequential dependencies
- Need centralized visibility
- Business logic in workflow
Resources
- Books: "Designing Event-Driven Systems" (Stopford), "Versioning in an Event Sourced System" (Young)
- Sites: eventuate.io, event-driven.io, Martin Fowler's event sourcing articles
- Tools: Kafka, EventStoreDB, RabbitMQ, Axon Framework, MassTransit
- Patterns: Event Sourcing, CQRS, Saga, Outbox, CDC, Event Streaming
1---2name: event-driven-architecture3description: Event-driven architecture patterns with event sourcing, CQRS, and message-driven communication. Use when designing distributed systems, microservices communication, or systems requiring eventual consistency and scalability.4---5
6# Event-Driven Architecture Patterns
7
8Expert guidance for designing, implementing, and operating event-driven systems with proven patterns for event sourcing, CQRS, message brokers, saga coordination, and eventual consistency management.
9
10## When to Use This Skill
11
12- Designing systems with asynchronous, decoupled communication
13- Implementing event sourcing and CQRS patterns
14- Building systems requiring eventual consistency and high scalability
15- Managing distributed transactions across microservices
16- Processing real-time event streams and data pipelines
17- Implementing publish-subscribe or message queue architectures
18- Designing reactive systems with complex event flows
19
20## Core Principles
21
22### 1. Events as First-Class Citizens
23Events represent immutable facts that have occurred in the system. Use past tense naming (OrderCreated, PaymentProcessed) and include all necessary context.
24
25### 2. Eventual Consistency
26Systems achieve consistency over time rather than immediately. Trade strong consistency for higher availability and scalability.
27
28### 3. Loose Coupling
29Services communicate through events without direct dependencies, enabling independent evolution and deployment.
30
31### 4. Asynchronous Communication
32Operations don't block waiting for responses, improving system responsiveness and resilience.
33
34### 5. Event-Driven Thinking
35Design around what happened (events) rather than what to do (commands).
36
37## Quick Reference
38
39| Topic | Load reference |
40| --- | --- |
41| Event structure, types, and characteristics | `skills/event-driven-architecture/references/event-fundamentals.md` |
42| Event sourcing pattern and implementation | `skills/event-driven-architecture/references/event-sourcing.md` |
43| CQRS pattern with read/write separation | `skills/event-driven-architecture/references/cqrs.md` |
44| Message brokers (RabbitMQ, Kafka, SQS/SNS) | `skills/event-driven-architecture/references/message-brokers.md` |
45| Saga pattern for distributed transactions | `skills/event-driven-architecture/references/saga-pattern.md` |
46| Choreography vs orchestration patterns | `skills/event-driven-architecture/references/choreography-orchestration.md` |
47| Eventual consistency and conflict resolution | `skills/event-driven-architecture/references/eventual-consistency.md` |
48| Best practices, anti-patterns, testing | `skills/event-driven-architecture/references/best-practices.md` |
49
50## Workflow
51
52### 1. Design Phase
53- **Identify Events**: What business facts need to be captured?
54- **Define Boundaries**: Which events are domain vs integration events?
55- **Choose Patterns**: Event sourcing? CQRS? Sagas? Choreography or orchestration?
56- **Select Technology**: Kafka for high throughput? RabbitMQ for routing? AWS managed services?
57
58### 2. Implementation Phase
59- **Event Schema**: Define versioned event structures with correlation IDs
60- **Event Store**: Implement append-only storage with optimistic concurrency
61- **Projections**: Create read models from events for query optimization
62- **Handlers**: Ensure idempotent, at-least-once delivery handling
63- **Sagas**: Implement compensating transactions for failures
64
65### 3. Operation Phase
66- **Monitoring**: Track event lag, processing time, failure rates
67- **Replay**: Build capability to replay events for debugging/recovery
68- **Versioning**: Support multiple event schema versions simultaneously
69- **Scaling**: Partition by aggregate ID, scale consumers horizontally
70- **Testing**: Test handlers in isolation with contract testing
71
72## Common Mistakes
73
74### Event Design Errors
75- ❌ Using commands instead of events (CreateOrder vs OrderCreated)
76- ❌ Mutable events or missing versioning
77- ❌ Events without correlation/causation IDs
78- ✓ Immutable, past-tense, self-contained events
79
80### Consistency Issues
81- ❌ Assuming immediate consistency across services
82- ❌ Not handling duplicate event delivery
83- ❌ Missing idempotency in handlers
84- ✓ Design for eventual consistency, idempotent handlers
85
86### Architecture Mistakes
87- ❌ Synchronous event chains (waiting for responses)
88- ❌ Events coupled to specific service implementations
89- ❌ No compensation strategy for sagas
90- ✓ Async fire-and-forget, domain-focused events, compensating transactions
91
92### Operational Gaps
93- ❌ No event replay capability
94- ❌ Missing monitoring for event lag
95- ❌ No schema registry or version management
96- ✓ Replay-ready, monitored, schema-managed events
97
98## Pattern Selection Guide
99
100### Use Event Sourcing When:
101- Need complete audit trail of all changes
102- Temporal queries required ("state at time T")
103- Multiple projections from same events
104- Event replay for debugging/recovery
105
106### Use CQRS When:
107- High read:write ratio (10:1+)
108- Complex query requirements
109- Need to scale reads independently
110- Different databases for read/write optimal
111
112### Use Sagas When:
113- Distributed transactions across services
114- Need atomicity without 2PC
115- Complex multi-step workflows
116- Compensation logic required
117
118### Choose Choreography When:
119- Simple workflows (2-4 steps)
120- High service autonomy desired
121- Event-driven culture established
122- No complex dependencies
123
124### Choose Orchestration When:
125- Complex workflows (5+ steps)
126- Sequential dependencies
127- Need centralized visibility
128- Business logic in workflow
129
130## Resources
131
132- **Books**: "Designing Event-Driven Systems" (Stopford), "Versioning in an Event Sourced System" (Young)
133- **Sites**: eventuate.io, event-driven.io, Martin Fowler's event sourcing articles
134- **Tools**: Kafka, EventStoreDB, RabbitMQ, Axon Framework, MassTransit
135- **Patterns**: Event Sourcing, CQRS, Saga, Outbox, CDC, Event Streaming