Chapter 4: Architectural Patterns & Trade-offs

Architecture is the art of trade-offs. There is no “best” pattern, only the one that best fits your current constraints.

Monolith vs. Microservices

The Monolith

Microservices

[!WARNING] The Distributed Monolith Trap: You split the code, but Service A cannot work without calling Service B, C, and D synchronously. You now have the latency and failure modes of a distributed system with the tight coupling of a monolith. This is the worst of both worlds.

Event-Driven Architecture (EDA)

Decouple services using events. Instead of Service A calling Service B, Service A publishes an event (“User Signed Up”), and Service B listens for it.

Idempotency

In EDA, messages will eventually be delivered more than once (network retries). Your consumers must be idempotent.

Serverless (FaaS)