Architecture
Event-Driven Architecture
Event-driven systems communicate through events â immutable records of things that happened. This decouples producers from consumers and enables reactive, scalable architectures.
- Events â Immutable facts about state changes
- Event Sourcing â Store events instead of current state
- CQRS â Separate read and write models
Event-driven architecture trades consistency for scalability and resilience.
What Is Event-Driven Architecture?
An architectural pattern where components communicate by producing and consuming events through a message broker.
Event Sourcing
Event Store
CQRS
Separating read and write models for independent optimization.
Saga Pattern
Managing distributed transactions across services.
Choreography vs Orchestration
| Approach | Description | Pros | Cons |
|---|---|---|---|
| Choreography | Each service listens for events and reacts | Loose coupling, simple | Hard to track flow, cyclic deps |
| Orchestration | Central coordinator directs the flow | Clear flow, easy to modify | Single point of failure, tight coupling |
Practice Exercises
-
Design: Design an event-driven architecture for an e-commerce order flow: order placement, payment, inventory reservation, shipping. Include event schemas and saga steps.
-
Event Sourcing: Implement event sourcing for a bank account. Events: AccountCreated, Deposited, Withdrawn, Transferred. Derive current balance by replaying events.
-
CQRS: Design CQRS for a social media feed. The write side handles posts; the read side materializes personalized feeds. How do you handle fan-out?
-
Trade-offs: Compare event-driven architecture with synchronous REST for a ride-sharing app. Which components benefit from events? Which should remain synchronous?
What to Learn Next
-> Service Mesh Envoy, Istio, and sidecar proxy patterns.
-> Data Replication Leader-follower, multi-leader, and conflict resolution.
-> Distributed Consensus Raft, Paxos, and leader election algorithms.
-> Containerization Docker, Kubernetes, and pod scheduling.
-> CI/CD Pipelines Continuous integration and deployment strategies.
-> Observability Logging, metrics, tracing, and monitoring.