DM
All learning areas
Trade-offs

Architecture Patterns

Understand when patterns help, when they hurt, and what they cost.

Topic library

Repository patternService layerDependency injectionAdapter patternStrategy patternFactory patternObserver patternState machinesEvent-driven architectureModular monolithMicroservicesCQRSSaga patternTransactional outboxCache-asideCircuit breaker

Featured guides

Practical starting points for the highest-value topics.

Modular monolith

Keep one deployable application with deliberate internal boundaries.

  1. Organize around business capabilities instead of technical folders alone.
  2. Give modules explicit public interfaces and private implementation details.
  3. Avoid direct access to another module's internal tables or classes.
  4. Test boundaries and record dependency direction.
  5. Extract a service only when independent operation creates demonstrated value.

Key idea: A well-structured monolith is often the simplest distributed-system strategy.

Transactional outbox

Publish events without losing consistency between database writes and messaging.

  1. Write the business change and an outbox row in one database transaction.
  2. Have a relay publish pending rows to the broker.
  3. Mark delivery state or use change-data capture.
  4. Make consumers idempotent because publication can repeat.
  5. Monitor outbox age, failures, and relay throughput.

Key idea: The pattern trades dual-write loss for retryable duplicate delivery.

When not to use microservices

Avoid paying distributed-system costs before they solve a real constraint.

  1. Do not split solely because the codebase is messy; improve boundaries first.
  2. Check whether teams truly require independent deployment and scaling.
  3. Account for network failure, observability, contracts, security, and data ownership.
  4. Compare against modules, queues, read replicas, and separate workers.
  5. Extract incrementally with a clear owner and measurable benefit.

Key idea: Microservices move complexity; they do not automatically remove it.