Skip to content

πŸ—οΈ Architecture Patterns ​

Common software architecture patterns and when to use them.

Monolith vs Microservices ​

AspectMonolithMicroservices
ComplexityLow at startHigh from day one
DeploymentSingle unitIndependent services
ScalingScale everythingScale per service
Team size< 10 devsMultiple teams
Best forMVPs, small teamsLarge 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 ​

SituationPattern
Simple CRUD appMonolith + layered
Complex business rulesDomain-driven design
High read/write asymmetryCQRS
Multiple independent teamsMicroservices
Event-heavy systemEvent-driven + message queue
Starting a new productModular 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

Pergame Knowledge Base