Monolith vs Microservices
Monolith vs Microservices
Every system starts as a set of requirements. Before writing a single line of code, architects face one of the most consequential decisions in software design: should this system be built as a monolith or as microservices? The answer is not ideological — it is a deliberate trade-off analysis driven by team size, deployment frequency, data isolation needs, and operational maturity.
What Is a Monolith?
A monolithic architecture bundles all application concerns — the HTTP layer, business logic, domain models, and data access — into a single deployable unit. When you ship, you ship everything together. When one process handles a request, that process has direct in-memory access to every module.
Real-world examples: Stack Overflow runs on a finely-tuned monolith serving ~1.5 billion page-views a month on a handful of servers. Early Shopify and Basecamp ran as Rails monoliths for years at significant scale.
What Are Microservices?
A microservices architecture decomposes the system into a collection of small, independently deployable services, each owning its own data store and communicating over a network (typically HTTP/REST or async messaging). Netflix runs >1,000 microservices. Amazon famously decomposed from a monolith around 2001–2002 and credits that decision with enabling its massive scale.
The Trade-Off Matrix
Neither style is universally superior. The right choice depends on where your system and team sit on several axes:
- Operational complexity. A monolith has one deployment artifact, one set of logs, one database connection to manage. Microservices require service discovery, distributed tracing, inter-service authentication, and resilience patterns (circuit breakers, retries). This overhead is real — Netflix's Chaos Engineering discipline exists precisely because they operate hundreds of services.
- Development velocity (early stage). In a monolith, a developer opens the repo, runs one command, and changes any part of the system. No network hops, no API versioning contracts. Early Shopify engineers iterated the entire product from a single Rails repo. This speed advantage is enormous before product-market fit.
- Independent scalability. If only your
video-transcodingservice needs 500 CPU cores while the rest of the system needs 5, microservices let you scale exactly that process. A monolith forces you to scale the whole application together. - Fault isolation. In a monolith, a memory leak in the
ReportGeneratormodule can take down the entire application. In microservices, a failingNotification Serviceshould not stop users from placing orders — if you design the circuit breakers correctly. - Team autonomy. Conway's Law states that organizations produce systems that mirror their communication structures. When you have 200 engineers split into 15 autonomous teams, a single codebase creates merge-conflict hell. Microservices let each team own its service end-to-end.
- Data consistency. A monolith can use a database transaction to guarantee that an order and its payment record are written atomically. Across microservices you lose that guarantee; you must use patterns like Sagas or eventual consistency, which are harder to reason about and debug.
When to Choose Each
Choose a monolith when:
- You are building an MVP or the domain is not yet well understood.
- Your team has fewer than ~20 engineers sharing the codebase.
- Deployment simplicity is a high priority (startups, agencies, internal tools).
- You do not have the operational infrastructure (container orchestration, distributed tracing) to run services reliably.
Choose microservices when:
- Different parts of the system have genuinely different scaling requirements.
- You have multiple large teams and you need organizational autonomy.
- Regulatory or security constraints require strict data isolation between domains (e.g., PCI-DSS for payments).
- You need to use different languages or runtimes per service (Python for ML, Go for low-latency, Node for I/O-heavy).
Real-World Migration Pattern
Most large systems today were monoliths first. Amazon, Netflix, Uber, and Airbnb all publicly documented migrating from monoliths to microservices over years, not overnight. They extracted the most painful boundaries first — authentication, payments, or the highest-traffic service — while leaving the rest of the monolith intact. This approach (the Strangler Fig pattern, covered in Lesson 8) de-risks the migration enormously.
Summary
The monolith vs. microservices decision is not about which architecture is "better" — it is about which trade-offs your team can absorb today. Start with the simplest thing that works. As you scale and as your domain boundaries crystallize, extract services strategically. The goal is always to deliver reliable software at speed; the architecture is the means, not the end.