What is a microservice?
A microservice is one small program that owns a single business capability and its own data, and can be deployed without deploying the rest of the system. The whole system is a team of these programs calling each other over a network instead of one big program sharing one database.
Think of a restaurant kitchen. A monolith is one chef running every station in one kitchen. Microservices are a grill chef, a salad chef and a pastry chef, each with their own station and ingredients, passing tickets between them. You can double the grill station at dinner rush without rebuilding the pastry station.
The point is not "small". The point is independent change: the catalog team can ship on Tuesday without redeploying orders, and catalog storage can be scaled at midnight without touching checkout. If you cannot change one piece alone, splitting it did not buy you anything.
- service boundary
- the seam where one capability ends and another begins
- API contract
- the promised inputs and outputs a service offers to callers
- independent deploy
- one service can be released while every other keeps running
Words to know
The monolith that stopped shipping
SliceNow began as one app: 350,000 lines, one database, 40 engineers. Every Friday, everybody's changes were bundled into a single 45-minute deploy. One bad line at 4:50 pm rolled back the whole week — and took dinner down with it.
The bottleneck was not CPU. It was coordination. Menu photos needed 10× the storage; checkout needed 10× the write throughput. Both lived in the same process and the same tables, so the only way to grow either was to grow everything.
The team drew boundaries around business capabilities, not code folders: Catalog, Orders, Payments, Notifications, Auth. Six months later a typical change touched one service, shipped in about 4 minutes, and a bad release took out one capability instead of the entire restaurant.
Monolith size
350k lines
Weekly deploy
45 min
After the split
4 min
Must hold true
- A catalog change must never require an orders deploy.
- Each service must own the data it writes.
- A half-finished payment must never leave an order silently confirmed.
Quick check
Which signal is the strongest reason to pull a service out of a monolith?
Where to draw the boundary
A good boundary wraps a business capability — something the business can explain to a customer — not a technical layer. "Orders" is a capability. "Validation", "controllers" and "the user model" are layers; services split along those lines cannot deliver anything on their own.
Test a proposed seam with three questions: can one team own this end to end, can it be deployed alone, and can it say no to another service through a clear contract? If any answer is no, the seam is in the wrong place.
Then follow the data. Whichever service creates and changes a piece of data should be the only service that writes it. If two services write the same table, you have one database with two deploy schedules — the monolith again, this time with network calls added.
Who owns which data
One writer per piece of data; everyone else asks through a contract.
| Data | Owner | How others read it | Why |
|---|---|---|---|
| Menu item and price | Catalog | Catalog API | Only catalog decides availability and price |
| Order status | Orders | Orders API / events | Only orders moves placed → paid → cancelled |
| Payment record | Payments | Callback + event | Card data never leaves the payments service |
| Name and email | Profile | Profile API | One source of truth for the customer |
How services talk: sync and async
Services have two ways to talk. Synchronous means the caller waits: Orders calls Payments over HTTP and blocks until it hears "charged". Asynchronous means the caller drops a message on a queue and carries on: Orders publishes OrderPlaced, and Notifications sends the email whenever it gets to it.
Trace one checkout, value by value. The gateway calls Orders (POST /orders) and waits ~120 ms. Orders writes its row, calls Payments (~200 ms) and waits for the answer. Only after "charged" does it publish an event; Notifications consumes it about 2 seconds later. The customer sees confirmation in ~350 ms — the email is off the critical path.
Use a synchronous call when the answer decides what happens next (charge approved, stock reserved). Use an event when the work can happen later and you want its failure isolated (email, receipt, recommendation refresh). Getting this choice wrong puts a slow email server in the middle of checkout.
- synchronous call
- caller waits for the response before continuing
- event
- a recorded fact ("OrderPlaced") that others may react to
- queue
- the holding area that lets a consumer work at its own pace
Words to know
Quick check
After a customer places an order, which job should be asynchronous?
One front door, many instances
Clients should not know that twelve services exist or where each one lives. An API gateway is the single front door: it routes /catalog/* to Catalog, /orders/* to Orders, and handles tokens and rate limits in one place instead of twelve.
Behind it, services find each other through a registry or platform DNS, and each instance reports a health check every few seconds. The gateway routes only to healthy instances, so a dead process is quietly removed from the list.
Trace one request: browser → gateway (token checked) → Catalog instance 3 (healthy) → catalog’s private database → back through the gateway. The browser never learns an internal hostname, and Catalog can be replaced without shipping a new client.
- API gateway
- the single public entry point that routes to internal services
- health check
- a short reply saying "I am alive and ready for traffic"
Words to know
Common trap — The network is not a function call
A cross-service call can time out, be duplicated or arrive out of order. Give every call a short timeout (~2 s, not 30 s), retry only a few times with backoff and jitter, send an idempotency key so a retried charge is never charged twice, and add a circuit breaker that stops calling a sick service for a while. Without these, one slow service becomes a traffic jam across all of them.
Consistency without one big transaction
You cannot wrap one database transaction around Orders and Payments when they own different databases. Instead you use a saga: each service commits its own step and publishes what happened, and later steps compensate if an earlier one fails.
Trace a declined payment: Orders writes PENDING, Payments answers "declined", Orders writes CANCELLED and publishes OrderCancelled. If the confirmation email somehow went out first, Notifications listens for the cancel and sends a correction. There is no instant where two databases pretend to be one transaction — there is a short, visible window where the order is pending.
That window is the price of independent data. Show it to the user honestly ("Processing your payment…") instead of hiding it, and make every published event describe a fact that already happened.
- eventual consistency
- copies converge to the same answer a little later, not instantly
- saga
- a sequence of local commits with compensating actions on failure
Words to know
Picking the right consistency tool
Most systems need a mix, not a single rule for every field.
| Need | Pattern | What the user sees |
|---|---|---|
| Card must be charged before order is confirmed | Synchronous call with idempotency key | Confirmation waits ~200 ms |
| Email and receipts can lag | Event on a queue | Arrives seconds later |
| Payment fails after order was placed | Compensating action in a saga | Order shows "cancelled", not a silent success |
| Catalog reads vastly outnumber writes | Cache in front of the catalog API | Fast reads; price may lag by its TTL |
Match them up
Match each term to its plain meaning.
0/5 matched — tap a term on the left.
Build it yourself
SliceNow’s single app is blocking two teams. Build the split: clients enter through one front door, Catalog and Orders are separate services, and each owns its own database. The old shared database is a decoy — leave it on the shelf.
Tip — When NOT to split
Do not start with microservices. A small product with one team and one database is faster as a well-structured monolith. Split when the coordination cost of one deploy unit is clearly higher than the cost of a network boundary: teams blocking each other’s releases, genuinely different scaling profiles, and data with obvious separate owners. Saying this out loud in an interview is a stronger signal than memorising service names.
Apply it in an interview
Take the URL-shortener problem into the simulator. Draw a front door, a redirect path and a separate analytics path, then explain out loud why you split where you did — and what you deliberately kept together.