Microservices Interview Questions and Answers
Last updated 2026-11-19
Microservices interviews rarely stop at "small independent services". They go to the hard parts: where to draw boundaries, how to keep data consistent when each service owns its database, what to do when a dependency fails, and how to trace a request across ten services. Each answer below ends with the trade-off, because that is what is being tested.
Read it with system design questions and REST API questions. Messaging concepts continue in message queue and Kafka questions, and for the round plan see how to crack a backend interview.
| Core ideas | Bounded contexts, data per service, resilience |
|---|---|
| Patterns | Saga, outbox, circuit breaker, API gateway |
| Level | Medium to hard |
A worked example: order placement
An order spans Order, Inventory and Payment services, each with its own database, so no single transaction covers them. The Order service saves the order as PENDING and publishes OrderCreated. Inventory reserves stock and publishes StockReserved. Payment charges the customer and publishes PaymentSucceeded, and Order marks the order CONFIRMED. If payment fails, Payment publishes PaymentFailed, Inventory releases the reservation (a compensating action) and Order marks the order CANCELLED. This is a choreographed saga, and the same flow can be coordinated by an orchestrator service instead.
What a good answer always mentions
- The cost: network failures, eventual consistency, operational overhead.
- Idempotent handlers, because messages can be delivered more than once.
- Observability: correlation ids, logs, metrics and traces.
- That a monolith first is often the right call.
Microservices Interview Questions and Answers: questions with worked answers
1 What are microservices and how do they differ from a monolith?
easyMicroservices structure an application as many small services, each owning one business capability, deployed independently and communicating over the network. A monolith ships as one deployable unit with in-process calls and usually one database. Microservices allow independent deployment, scaling and technology choice per team, but add distributed-system problems: latency, partial failure, data consistency and operational complexity. They help most when many teams work on one large product.
2 How do you decide service boundaries?
hardFollow business capabilities and bounded contexts from domain-driven design, not technical layers. A service should own its data and change for one reason, so a feature change touches one service. Warning signs of bad boundaries: two services that must always be deployed together, chatty calls between them, or a shared database table. Start with a modular monolith and extract a module when it needs independent scaling or a separate team. Splitting by layer (a "database service") creates coupling, not independence.
3 Why should each microservice own its database?
mediumA shared database couples services through the schema: one team's migration can break another, and nobody can change internals freely. Owning data lets each service pick a suitable store and evolve independently, and others access the data only through its API or events. The cost is that joins across services and cross-service transactions are no longer available, so you need API composition, replicated read models and sagas.
4 Synchronous REST or asynchronous messaging between services?
mediumSynchronous calls are simple and give an immediate answer, suited to queries and operations the caller needs a result from. They create temporal coupling: if the callee is down or slow the caller suffers, and chains of calls multiply latency and failure probability. Asynchronous messaging decouples services in time, absorbs bursts and supports fan-out, but makes flows harder to follow and results eventual. Common practice: synchronous for reads, asynchronous events for state changes that other services react to.
5 What does an API gateway do?
mediumIt is the single entry point for clients: it routes requests to services, authenticates callers, applies rate limits, terminates TLS, aggregates responses from several services and can translate protocols. It simplifies clients, which need not know the service topology. Risks: it becomes a bottleneck and a single point of failure if not replicated, and business logic creeping into it creates a new monolith. A backend-for-frontend variant keeps a separate gateway per client type.
6 How does service discovery work?
mediumInstances come and go with scaling and failures, so callers cannot hard-code addresses. In client-side discovery, instances register with a registry (Consul, Eureka, etcd) and the client queries it and load balances. In server-side discovery, the client calls a stable name and a load balancer or the platform finds an instance; Kubernetes does this with Services and DNS. Health checks remove dead instances from the registry.
7 Explain the circuit breaker pattern and its states.
hardA circuit breaker wraps calls to a dependency and stops calling it when it is failing, so the caller fails fast instead of piling up slow requests. Closed: calls pass and failures are counted. When failures exceed a threshold in a window, the breaker opens: calls fail immediately or return a fallback. After a timeout it moves to half-open and lets a few trial calls through; if they succeed it closes, otherwise it opens again. Combine with timeouts, bounded retries with backoff and bulkheads that isolate resource pools.
8 What is the saga pattern? Compare choreography and orchestration.
hardA saga is a sequence of local transactions, one per service, where each step publishes an event or command for the next, and a failure triggers compensating transactions that undo earlier steps (for example refund a payment, release stock). In choreography, services react to each other's events with no central coordinator: simple for few steps but the flow is hard to see. In orchestration, a coordinator tells each service what to do and tracks the state: easier to follow and change, but adds a component. Sagas give eventual consistency, not isolation, so intermediate states are visible.
9 What is the transactional outbox pattern and what problem does it solve?
hardA service that updates its database and then publishes an event can crash between the two, losing the event or publishing without a commit (the dual-write problem). With an outbox, the service writes the business change and an event row to an outbox table in the same local transaction. A separate relay, polling or reading the database log with change data capture, publishes outbox rows to the broker and marks them sent. Delivery is at least once, so consumers must be idempotent.
10 How do you make message handlers idempotent?
mediumAssign each message a unique id and record processed ids in the same transaction as the handler's effect, using a unique constraint so a duplicate fails harmlessly. Alternatively design operations to be naturally idempotent, such as setting a value rather than incrementing, or using conditional updates with version numbers. Brokers typically guarantee at-least-once delivery, so duplicates will happen.
11 How do you debug a request that crosses many services?
mediumGenerate a correlation or trace id at the edge and pass it in headers to every downstream call and message, and include it in all log lines. Distributed tracing, such as OpenTelemetry with a backend like Jaeger, records a span per hop and shows where time was spent. Add per-service metrics (rate, errors, duration) and centralised logging. Without these, a slow request across services is almost impossible to diagnose.
12 How do you version service APIs without breaking consumers?
mediumPrefer backward-compatible changes: add optional fields and new endpoints, never remove or change meaning. Consumers should ignore unknown fields. When a breaking change is unavoidable, run both versions side by side (a version in the path or header), migrate consumers, then retire the old one. Consumer-driven contract tests catch accidental breaks before release.
13 What is the strangler fig pattern for migrating a monolith?
mediumYou build new functionality as services around the monolith and route traffic for one feature at a time from the monolith to the new service, usually via a proxy or gateway, until the monolith has no remaining responsibilities and is removed. It avoids a risky big-bang rewrite, allows rollback per feature and delivers value incrementally. The hard part is untangling shared data, often handled with replicated read models or an anti-corruption layer.
14 When should you not use microservices?
mediumWith a small team, an unclear domain, or a product still finding its shape: boundaries drawn too early are wrong and costly to change. The operational overhead (pipelines, monitoring, service discovery, on-call) can exceed the benefit. A modular monolith keeps clean module boundaries and can be split later. Choose microservices for organisational scale and independent scaling needs, not for fashion.
Frequently asked questions
How big should a microservice be?
Size follows a business capability and team ownership, not lines of code. A team should be able to understand and own it fully.
Do microservices need Kubernetes?
No, but containers and an orchestrator make deploying and scaling many services manageable. Smaller setups can use managed container services.
How do microservices handle transactions?
With sagas and eventual consistency instead of distributed ACID transactions. Two-phase commit is rarely used across services.
Which language should microservices use?
Any, since services communicate over the network. Most organisations limit the choices to keep operations manageable.
Related guides
More in CS Fundamentals Interview Questions
- MongoDB Interview Questions and Answers
- Network Security Interview Questions: Cryptography, Firewalls and Attacks
- Normalization Interview Questions with Worked Examples
- NoSQL Interview Questions and Answers
- OOPs Interview Questions and Answers
- Operating Systems Interview Questions with Worked Answers
- OSI Model Interview Questions: Layers, PDUs, Devices and Encapsulation
- Paging and Virtual Memory Interview Questions with Numericals
- Process and Thread Interview Questions with fork() Output Problems
- Process Synchronization Interview Questions: Semaphores, Mutex and Classic Problems
- Redis Interview Questions and Answers
- REST API Interview Questions and Answers