ποΈ Architecture Patterns β
Common software architecture patterns and when to use them.
Monolith vs Microservices β
| Aspect | Monolith | Microservices |
|---|---|---|
| Complexity | Low at start | High from day one |
| Deployment | Single unit | Independent services |
| Scaling | Scale everything | Scale per service |
| Team size | < 10 devs | Multiple teams |
| Best for | MVPs, small teams | Large orgs, diverse scaling needs |
Rule of thumb: Start monolith, extract services when you have clear boundaries.
Layered architecture β
Presentation (UI / API)
β
Application (Use cases / Services)
β
Domain (Business logic / Entities)
β
Infrastructure (DB / External APIs / Files)Dependencies point inward β domain has no external dependencies.
Common patterns β
Repository pattern β
Abstracts data access behind an interface. Business logic doesn't know about the database.
Service layer β
Encapsulates business logic and orchestrates between repositories and external services.
Event-driven β
Components communicate via events instead of direct calls. Good for decoupling.
CQRS β
Separate read and write models. Useful when read/write patterns differ significantly.
Saga pattern β
Manages distributed transactions across microservices using compensating actions.
Decision guide β
| Situation | Pattern |
|---|---|
| Simple CRUD app | Monolith + layered |
| Complex business rules | Domain-driven design |
| High read/write asymmetry | CQRS |
| Multiple independent teams | Microservices |
| Event-heavy system | Event-driven + message queue |
| Starting a new product | Modular monolith |
Anti-patterns β
- Distributed monolith β Microservices that are tightly coupled
- Big ball of mud β No clear structure or boundaries
- Golden hammer β Using the same pattern for everything
- Premature optimization β Over-architecting before understanding the problem