1.4 KiB
1.4 KiB
Common Architecture Patterns
API Gateway
Single entry point for all client requests, handles routing, auth, rate limiting.
- Use when: Multiple backend services, need centralized auth/logging
- Options: Kong, AWS API Gateway, custom Nginx
- Tradeoffs: Single point of failure, added latency
Backends for Frontends (BFF)
Separate backend for each frontend type.
- Use when: Different clients need different data shapes
- Benefits: Optimized per-client, independent deployment
- Tradeoffs: Code duplication, more services to maintain
Circuit Breaker
Prevent cascading failures by failing fast when downstream unhealthy.
- Implementation: Track failure rate, open circuit after threshold, half-open to test recovery
- Libraries: Hystrix (Java), Polly (.NET), Resilience4j (Java), opossum (Node)
Saga Pattern
Manage distributed transactions across services.
| Type | Description |
|---|---|
| Choreography | Services emit events, others listen and react |
| Orchestration | Central coordinator manages workflow |
- Use when: Multi-service transaction, eventual consistency acceptable
Strangler Fig
Gradually migrate from legacy by routing new features to new system.
- Route all traffic through proxy/facade
- Build new features in new system
- Gradually migrate existing features
- Sunset legacy when complete