Monoliths and microservices

1 block or many pieces · Part of Architecture

Key idea

Practice

7 questions · about 4 min

Explained step by step

Monolith

A monolith is a self-contained app, built as 1 single piece. It doesn't do 1 particular task: it does every step the business needs, from login to payment. All the code lives together and is deployed together. It's like a restaurant where 1 single person cooks, serves and takes payment: simple at first, but when 200 customers arrive, they can't keep up.

The monolith has advantages: it's simple to develop and debug, communication between parts is fast and reliable (they're calls inside the same program), it's easy to monitor and test, and it supports ACID transactions. But as it grows, it gets hard to maintain, everything becomes tightly coupled, it ties you to one technology, every change deploys everything and 1 single bug can bring down the whole system. It's like a studio apartment: cheap and practical for 1 person, cramped for 10.

Modular monolith

A modular monolith is a middle ground: 1 single app is built and deployed (the monolith part), but the code is split into independent modules, 1 for each feature. That way one module can change without affecting the others. Done right, it greatly lowers the complexity of maintaining a growing monolith. It's like a dresser with drawers: it's 1 single piece of furniture, but socks don't mix with T-shirts.

Microservices

A microservices architecture is a set of small, autonomous services, each with 1 business capability. Each service has its own codebase, managed by a small team, and is deployed alone: it can be updated without redeploying the whole app. Also, each service stores its own data (1 database per service). It's like a food court: each stall cooks its own thing, with its own kitchen and team, and if one closes, the others keep going.

Microservices have advantages: they're deployed separately, several teams work with agility, they tolerate failures better, they isolate data, each service scales alone and they don't tie you to 1 technology. But they have costs: the complexity of a distributed system, harder testing, higher cost (each with its own servers and databases), communication between services over the network, hard data consistency and more latency. It's like moving from 1 house to 10 apartments: more freedom, but 10 rents.

Bounded context

Each microservice implements 1 business capability inside a bounded context. A bounded context is a natural division of business logic, with a clear boundary inside which terms have 1 single meaning. For example, «product» in the catalog has a photo and description; in shipping it has weight and size. It's like a company's departments: «customer» for sales is someone who buys, and for support it's someone with a complaint.

Coupling

Microservices have 5 traits. Loosely coupled: they're deployed and scaled alone. Small but focused: «they do 1 thing and do it well». Organized around the business. Resilient: they keep working even if something fails. Easy to maintain and test. It's like a football team: each player has a position, if 1 gets injured another comes in, and the team keeps playing.

Terms in this lesson

Arki, the beaver mascot

Your next interview starts with 5 minutes today.

Free on iOS and Android. Start from zero, no account needed.

Key idea

1 block or many pieces