What it is
A microservice architecture builds an application from small services, each responsible for one business capability (orders, inventory, payments), owned by one team, deployed on its own schedule and usually storing its own data. Services talk over the network: synchronously (HTTP, gRPC) or asynchronously (messages, events). The alternative is a monolith: one deployable application whose modules call each other in-process.
Why it exists
A monolith is simple to build, test and run, until the organisation grows. With dozens of engineers in one codebase, every change waits for a shared release, one team's bug can take everything down, and the whole application must be scaled to relieve one hot part. Microservices let teams own their service end to end: release independently, choose what fits their problem, and scale only what needs scaling. The motivation is mainly organisational and operational, not performance.
How it works
Boundaries. Services are cut along business capabilities (often found with domain-driven design), not technical layers. A good boundary means most changes touch one service.
Data ownership. Each service owns its data and exposes it only through its API or events. Sharing tables between services re-couples them: one team's schema change breaks another team's service.
Communication. A synchronous call is simple to reason about but couples the caller's latency and availability to the callee's. An asynchronous message (via a queue or event stream) lets the caller continue without waiting, at the price of eventual consistency.
Latency stacking. If Orders calls its database, then Inventory, then Payments, the request takes the sum of all those calls plus a network round trip for each. Parallel calls reduce this to the slowest branch but not below it.
Capacity and availability coupling. While Orders waits for Payments, it holds a worker, a connection and memory. A slow Payments therefore makes Orders busier without doing more work, and can exhaust it. Availabilities multiply: five services in a chain at 99.9% each give about 99.5% for the whole request.
Supporting infrastructure. Service discovery, an API gateway, per-service CI/CD, centralised logging, metrics and distributed tracing, timeouts, retries and circuit breakers on every call. This is real, ongoing cost.
When to use it
- Several teams need to work and deploy independently on one product.
- Parts of the system have clearly different scaling, availability or technology needs.
- Domain boundaries are understood well enough that services will not need constant cross-service changes.
- The organisation can afford the operational platform: automation, observability and on-call per service.
When not to
- A small team or an early product: a well-structured modular monolith gives clear boundaries without network calls, and can be split later along those boundaries.
- When boundaries are unclear; wrong cuts produce a distributed monolith where every feature needs coordinated releases of several services.
- When the main goal is performance; extra network hops usually make requests slower.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Microservices over a monolith | Independent deployment, scaling and ownership | Network latency, partial failures, distributed data, operational overhead |
| Synchronous calls | Immediate answers, simple flow | Latency and availability coupling |
| Asynchronous messaging | Isolation from slow or failed services | Eventual consistency, compensation logic, harder debugging |
| Database per service | Teams evolve schemas independently | No cross-service joins or transactions; data duplication |
| Many fine-grained services | Small, focused codebases | More hops, more deployables, more coordination |
Alternatives
- Modular monolith: one deployable with strict internal module boundaries; most of the design benefits, few of the operational costs.
- A few larger services ("macroservices") split only where the benefit is clear.
- Serverless functions for isolated, event-driven pieces.
- Service-oriented architecture with shared infrastructure: coarser services, often with a central integration layer.
Failure modes
- Cascading failure: a slow or failed service exhausts its callers, which fail their callers in turn. Mitigate with timeouts, circuit breakers, bulkheads and fallbacks.
- Bottleneck service: one under-provisioned service limits every request that passes through it.
- Retry amplification: retries at several layers multiply load on a struggling service.
- Distributed monolith: services that must be deployed together and share databases, with all the costs and none of the benefits.
- Inconsistent data: without distributed transactions, a crash halfway through a multi-service operation leaves partial state; sagas and the outbox pattern handle this.
- Chatty interfaces: many small calls per request multiply latency and failure points.
In production
Start from business boundaries, give each service its own data, and keep synchronous chains short. Put timeouts, bounded retries and circuit breakers on every call. Move work the user does not need right away onto queues or events, with idempotent consumers and the outbox pattern. Invest in distributed tracing so you can see where a request spent its time. Monitor each service's latency, errors and saturation, and plan capacity per service.
Common misconceptions
- "Microservices are faster." Requests usually get slower: function calls become network calls.
- "Microservices are more reliable." Only with deliberate isolation. A synchronous chain fails if any link fails.
- "Smaller is always better." Very fine services create chatty, fragile systems.
- "We can share the database for now." Shared tables are the strongest coupling there is and are hard to undo.
Interview angle
Interviewers want to hear why you would split (team autonomy, independent scaling) and why you might not (latency, complexity, distributed data), not microservices by default. Expect questions on boundaries, data ownership, synchronous versus asynchronous communication, handling a slow or failed dependency, consistency across services (sagas, outbox) and observability. Quantifying the cost ("each hop adds a few ms; five services in a chain at 99.9% give 99.5%") makes the trade-off concrete.
Model assumptions
The simulation is a simplified model, not a benchmark. The monolith has 16 workers and a 50 ms mean service time plus one database query. After the split, Orders (32 workers, 15 ms) calls its database, then Inventory (15 ms, which calls its own database), then Payments (16 workers, 20 ms), strictly one after another, holding its worker while it waits. Service times are lognormal (cv 0.3); hops between services take 3–5 ms and shoppers are 20 ms away. Extra Inventory capacity is modelled as more workers rather than more instances. "Degraded" makes a service 4× slower. In the asynchronous step an order succeeds once its payment message is stored. Numbers show behaviour and orders of magnitude only.