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