Updated 24 October 2026
Microservices, service discovery and API gateways
Monolith versus microservices and when to split, service discovery, API gateways and backends for frontends, synchronous versus asynchronous communication, service meshes, and the failure modes that come with a distributed system.
Try it yourself, in a playground:Deadline propagationTrace samplingRetry storms
Almost every system design diagram is drawn as a set of services, so interviewers sometimes ask why. "Microservices are more scalable" is not an answer. The real reasons are organisational and operational, and the costs (network calls, partial failure, distributed data) are real. This guide covers how to decide where to draw service boundaries and how services find and talk to each other.
Monolith or microservices
A monolith is one deployable application, usually with one database. A microservice architecture splits it into services that are deployed, scaled and owned independently, each with its own data.
| Monolith | Microservices | |
|---|---|---|
| Calls between parts | function calls: nanoseconds, never partially fail | network calls: milliseconds, can time out or half-succeed |
| Transactions | one database transaction | sagas and eventual consistency across services |
| Deploys | everything together | each team ships independently |
| Scaling | scale the whole thing | scale the hot parts (search, not settings) |
| Failure isolation | a memory leak takes everything down | one service degrades; others keep working (if designed to) |
| Operational cost | one thing to run | service discovery, tracing, many pipelines and dashboards |
Split when different parts have very different scaling or reliability needs (the read path of a URL shortener versus link creation), when many teams are blocked on one deploy, or when a part needs a different technology (a GPU inference service). Do not split a small product with one team: a well-structured modular monolith is faster to build and easier to run.
In an interview, drawing separate services is fine, but justify the ones that matter: "redirects and link creation are separate because reads outnumber writes 100 to 1 and must stay up even if creation fails".
Drawing boundaries
Good boundaries follow business capabilities and data ownership: an order service owns orders, a payment service owns payments, and nobody else writes their tables. Signs of a bad boundary:
- Two services that must always be deployed together.
- A call chain of five services to serve one request (a "distributed monolith").
- Services that share a database and write each other’s tables.
Each service owns its data and exposes it through an API or events. Other services that need it either call that API or keep their own read-optimised copy from events.
Service discovery
Instances come and go with deploys and autoscaling, so callers cannot use fixed addresses.
- DNS-based (Kubernetes services): a name resolves to a stable virtual IP that load-balances across healthy pods. Simple and the default today.
- Registry-based (Consul, etcd, Eureka): instances register with a health check; clients or proxies look up the current list.
- Client-side load balancing: the caller holds the list and picks an instance (gRPC does this well), avoiding an extra hop.
- Server-side: the caller talks to a load balancer, which picks.
Health checks decide who is in the list: liveness (restart me if this fails) and readiness (do not send me traffic yet).
API gateways and backends for frontends
An API gateway is the single public entry point: it terminates TLS, authenticates, rate limits, routes to services and can aggregate responses. It keeps cross-cutting concerns out of every service and hides internal topology from clients. See API design and rate limiting.
A backend for frontend (BFF) is a gateway layer per client type (mobile, web, partners) that shapes responses for that client: one call from the phone returns exactly the screen’s data, fetched from several services server-side, instead of six calls over a slow mobile network.
Synchronous or asynchronous
- Synchronous (REST, gRPC): the caller waits. Right when the user needs the answer now (is this seat free?). Every hop adds latency and a failure mode.
- Asynchronous (events through Kafka or a queue): the caller publishes and moves on. Right when the work can happen later (send a receipt, update search, recompute recommendations). It decouples availability: the publisher keeps working even if consumers are down. See message queues and streams.
A healthy design is mostly synchronous on the user’s critical path and asynchronous everywhere else. Long synchronous chains multiply failure: five services each at 99.9 % availability give 99.5 % for the chain.
Living with partial failure
Every network call can be slow, fail, or succeed without you hearing back. The standard defences:
- Timeouts on every call, shorter than the caller’s own deadline.
- Retries with backoff and jitter, only for idempotent operations, with a retry budget so retries do not multiply load.
- Circuit breakers that stop calling a failing dependency and fail fast.
- Bulkheads: separate pools per dependency so one slow service cannot consume all threads.
- Fallbacks: serve cached or default data when a non-critical dependency fails.
- Idempotency keys so retries of writes are safe. See distributed transactions and idempotency.
Service mesh
A service mesh (Istio, Linkerd) runs a proxy next to every service instance (a sidecar) that handles mutual TLS, retries, timeouts, load balancing and telemetry, configured centrally. It removes that code from every service, at the cost of more moving parts and a little latency per hop. Worth mentioning for large fleets with many languages; overkill for a handful of services.
Observability is not optional
With dozens of services, "why is this request slow" needs distributed tracing (a trace id propagated through every call), structured logs with that id, and per-service metrics on latency, errors and saturation. See observability, operations and rollouts.
Checklist
- Why each service boundary exists (scaling, reliability, ownership).
- Each service owns its data; no shared tables.
- Discovery and load balancing between services.
- A gateway at the edge; a BFF if clients differ a lot.
- Synchronous only on the critical path; events elsewhere.
- Timeouts, retries with idempotency, circuit breakers.
- Tracing across services.
Questions people ask
What are microservices?
A microservice architecture splits an application into services that are deployed, scaled and owned independently, each with its own data. Good boundaries follow business capabilities and data ownership: an order service owns orders, a payment service owns payments, and nobody else writes their tables. The real reasons to adopt them are organisational and operational; "microservices are more scalable" is not an answer on its own.
Monolith vs microservices: what is the difference?
A monolith is one deployable application, usually with one database, while microservices are independently deployed services that each own their data. Inside a monolith, parts talk through function calls that take nanoseconds and never partially fail, and one database transaction covers a change. Between microservices, calls take milliseconds and can time out or half-succeed, and consistency needs sagas; in return, each team ships independently, hot parts scale alone, and one failing service need not take everything down.
When should you split a monolith into microservices?
Split when parts have very different scaling or reliability needs, when many teams are blocked on one deploy, or when a part needs a different technology, such as a GPU inference service. In a URL shortener, redirects and link creation are separate because reads outnumber writes 100 to 1 and redirects must stay up even if creation fails. Do not split a small product with one team: a well-structured modular monolith is faster to build and easier to run.
Should microservices communicate synchronously or asynchronously?
Mostly synchronously on the user's critical path and asynchronously everywhere else. Synchronous calls (REST, gRPC) fit when the user needs the answer now, such as whether a seat is free, but every hop adds latency and a failure mode: five services each at 99.9 % availability give 99.5 % for the chain. Asynchronous events through Kafka or a queue fit work that can happen later, such as sending a receipt, and keep the publisher working even if consumers are down.
What is the difference between an API gateway and a backend for frontend?
An API gateway is the single public entry point that terminates TLS, authenticates, rate limits, routes to services and can aggregate responses, while a backend for frontend (BFF) is a gateway layer per client type that shapes responses for that client. The gateway keeps cross-cutting concerns out of every service and hides internal topology. A BFF lets one call from a phone return exactly the screen's data, fetched from several services server-side, instead of six calls over a slow mobile network.
How do microservices handle partial failure?
With timeouts, retries, circuit breakers, bulkheads, fallbacks and idempotency keys, because any network call can be slow, fail, or succeed without the caller hearing back. Timeouts are shorter than the caller's own deadline, and retries use backoff and jitter, only for idempotent operations, with a retry budget so they do not multiply load. Circuit breakers stop calling a failing dependency, bulkheads give each dependency its own pool, and fallbacks serve cached or default data when a non-critical dependency fails.