Distributed Systems Patterns
# Distributed Systems Patterns
Distributed systems are hard. These patterns make them manageable.
## Resilience Patterns
**Circuit Breaker**
Stop calling failing services. Give them time to recover.
**Retry with Backoff**
Try again, but not immediately. Exponential backoff prevents thundering herds.
**Bulkhead**
Isolate resources to prevent cascade failures.
## Data Patterns
**Saga Pattern**
Distributed transactions via compensating actions.
**CQRS**
Separate read and write models for optimal performance.
**Event Sourcing**
Store changes, not state. Enables powerful audit and replay.
## Communication Patterns
**API Gateway**
Single entry point for clients. Handles routing, auth, rate limiting.
**Service Mesh**
Infrastructure layer for service-to-service communication.
## The Fallacies
Never assume:
- The network is reliable
- Latency is zero
- Bandwidth is infinite
- The network is secure
Plan for failure. It's not if, it's when.
