Microservices, step by step

Why do big companies split one app into many small services, and why do they put a gateway in front? Watch a growing shop hit each problem and pick the fix.

3 steps · about 6 minutes · free, no sign-up

Step 1: 40 engineers, one app

Forty engineers, one app: every release waits for everyone, and one bug breaks everything.

Every change ships the whole app, so releases are slow and risky, and a busy catalog can only scale by copying everything. What do you do?

  • Freeze releases until it is stable (Not this one): Fewer releases means bigger, riskier ones later, and customers wait months for fixes. The app is still one tangled piece.
  • Split it into services by business area (Right fix): Orders, catalog, accounts and payments each become a service with its own code, data and team. Each ships on its own, and only the busy one needs to scale. Microservices: Building a system as small services, each owning one business area and its own data, talking over the network. Teams move independently; the price is more moving parts to run and connect.
  • Split the code into folders, still deploy as one app (Helps for a while): Cleaner code helps teams find their way, and it is a good first step. But it still ships and scales as one piece, so one bug still takes everything down.

Step 2: Too many calls

The app calls four services directly, each with its own address and login check.

Phones make four slow trips per screen, every service re-checks login, and payments is open to the internet. What do you do?

  • Put an API gateway in front of the services (Right fix): The app talks to one address. The gateway checks the login once, routes each call, and can combine calls into one reply. Payments is no longer reachable from outside. API gateway: A single entry point in front of many services. It handles routing, sign-in checks, rate limits and sometimes combining responses, so services stay simple and private.
  • Merge the services back into one app (Not this one): The phone makes one call again, but you are back to one release for everyone and one bug breaking everything.
  • Add a load balancer for each service (Helps for a while): Each service now scales well, which helps later. But the phone still makes four trips, every service still checks login, and payments is still exposed.

Step 3: Payments goes down

Payments hangs. Orders wait on it, the gateway waits on orders: the shop freezes.

One slow service makes every caller wait until they run out of threads, so the failure spreads to the whole shop. What do you do?

  • Retry each failed call 5 times (Helps for a while): Retries fix brief blips. But against a service that is already down, five retries mean five times the load, and the pile-up gets worse.
  • Add more gateway servers (Not this one): The gateway was only waiting on orders, which was waiting on payments. More gateways just hold more stuck requests.
  • Use timeouts and a circuit breaker on payments (Right fix): Calls to payments give up after 2 seconds. After a few failures the breaker opens and orders stop calling it, saving the order as "payment pending". The rest of the shop keeps working. Circuit breaker: A guard around calls to another service. After repeated failures it "opens" and fails fast for a while instead of waiting, then lets a test call through to see if the service is back.

What you built

  • Microservices: Small services, each owning one business area and its data, released independently.
  • API gateway: One front door: routing, sign-in checks and rate limits in one place.
  • Timeouts: Calls give up instead of waiting forever on a stuck service.
  • Circuit breaker: Stops calling a failing service for a while so the failure doesn’t spread.
ProblemFixTrade-off
One app slows every teamSplit into servicesMore things to run and monitor
Clients call many servicesAPI gatewayOne more component on the path
One failure spreadsTimeouts + circuit breakerFeatures degrade instead of erroring

Frequently asked questions

When should I move from a monolith to microservices?

When the team or the app is big enough that one shared release slows everyone down, or parts need to scale very differently. Small teams usually move faster with a well-organised monolith.

What does an API gateway do?

It is the single entry point for clients: it routes requests to services, checks authentication, applies rate limits and can combine several service calls into one response.

What is a circuit breaker?

A pattern that stops calling a failing service after repeated errors and fails fast for a while, then tests whether it has recovered. It keeps one outage from freezing everything.

Do microservices share a database?

Ideally each service owns its data and others ask it through its API. Sharing one database couples the services again and makes independent changes risky.

← All visual lessons

Try AI Flowchart free →