Module 2 · Backend architectureLesson 11 of 887 minBeginner
Monolith vs microservices
One big program is simple until it isn't. Many small services scale teams, at the price of more moving parts.
Play "Monolith" and watch one bug take everything down. Then play "Microservices" and see the failure stay inside the payment service.
The monolith
A monolith is one program that does everything: users, products, cart, payments. You build it, test it and deploy it as one unit.
Good things:
- Simple: one codebase, one deploy, one place to look when something breaks.
- Fast inside: parts call each other in memory, in microseconds.
- Easy to change across features: a change touching users and orders is one pull request.
Problems appear as the app and team grow:
- One bug or memory leak can crash everything.
- Every deploy ships everything, so 50 engineers queue up behind each other.
- You can only scale the whole thing, even if only search is busy.
Microservices
Microservices split the app into small services, each owning one job and its own data: a user service, an order service, a payment service. They talk over the network with APIs or events.
Good things:
- Failures stay contained: payments down doesn't mean browsing is down.
- Teams move independently: each team deploys its service when it's ready.
- Scale what's busy: run 30 copies of search and 2 of settings.
The costs are real:
- Every call is now a network call: slower, and it can fail or time out.
- You need service discovery, gateways, tracing, retries, and many deploy pipelines.
- Data is spread out, so a single action may touch several databases (you'll meet sagas later).
A sensible path
Most successful systems started as monoliths. Build a modular monolith with clear internal boundaries. When a part needs to scale differently, or a team needs to ship independently, cut it out along that boundary.