Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 37 ยท Practice and Review

Microservices Interview Questions

Thirty microservices interview questions with concise, honest answers on boundaries, CAP, sagas, consistency, resilience, scaling and design prompts, plus two runnable demos.

Microservices interviews rarely ask for definitions alone. Interviewers want to hear that you know the trade-offs: what you gain, what it costs, and what you would do when something breaks. This page collects thirty questions in five groups, each with a short answer you can say out loud in under a minute, plus a link to the lesson with the details.

Use the answers as a skeleton, not a script. A strong answer states the idea, gives one concrete example, and names a downside. Two questions have runnable stand-ins (a replica quorum model and an availability calculator); they are small models for building intuition, not real databases.

A good answer has three parts

The idea One clear sentence.
An example Something concrete from a real system.
The trade-off What it costs, and when not to.
1 / 2

Fundamentals

1. What is a microservice?

A small, independently deployable service that owns one business capability and its data, and talks to other services over the network. The key words are independently deployable and owns its data; being small is a side effect. See What Are Microservices?.

2. What are the main trade-offs versus a monolith?

Gains: independent deployment, independent scaling, team autonomy, fault isolation, technology choice per service. Costs: network latency and failure, distributed data consistency, harder testing and debugging, operational overhead (pipelines, monitoring, orchestration). A monolith is simpler until the team or the load outgrows it.

3. When would you not use microservices?

For a small team, an unclear domain, a new product still finding its shape, or when you lack deployment automation and monitoring. A well-structured modular monolith is usually the better start. See When (and When Not) to Use Microservices.

4. How big should a service be?

Big enough to own a coherent capability and let one team work independently, small enough that the team can understand it fully. "Lines of code" is a poor measure. Better signals: it changes for one reason, one team owns it, and most changes do not require changing another service.

5. What is a modular monolith and why mention it?

One deployable application with strict module boundaries: each module owns its data and exposes a small interface. It gives most of the design benefits at a fraction of the operational cost, and clean modules can later become services.

6. What is Conway's law and why does it matter here?

Systems tend to mirror the communication structure of the organization that builds them. If three teams share one service, expect friction; if you want independent services, give each one an owning team (the "inverse Conway manoeuvre").

7. What is a bounded context?

A boundary inside which a model and its terms have one precise meaning. "Customer" can mean different things for billing and for shipping; each context has its own model. Bounded contexts are the best starting point for service boundaries. See Finding Boundaries with Domain-Driven Design.

Data and consistency

8. Why should each service own its database?

Shared tables couple services through the schema: one change can break others, and nobody can deploy or scale independently. Private data lets a service change its storage freely. Other services get data through its API or events. See Database per Service and Data Ownership.

9. How do you query data that lives in several services?

Three options: API composition (a gateway or aggregator calls each service and merges results), a read model built from events (CQRS), or keeping a small local copy of the other service's data. Composition is simple but couples latency; read models are fast but eventually consistent.

10. Explain the CAP theorem accurately.

When a network partition happens, a distributed data store must choose between consistency (every read sees the latest write, or an error) and availability (every request gets an answer, possibly stale). Partitions are a fact of life, so the real choice is what to do during one. A common refinement, PACELC, adds that even without a partition you trade latency against consistency. "Pick any two of three" is a misleading summary.

The stand-in below models three replicas. A write goes to W replicas, a read asks R replicas and takes the newest version. If R + W > N, a read must overlap at least one replica that saw the latest write.

JS Quorum reads and writes with three replicas

Press Run (or Ctrl + Enter) to see the console output here.

No output.

With W=2, R=2 the read always sees the latest value, and when two replicas are down the write is refused: consistency chosen over availability. With W=1, R=1 the system stays available but the read can be stale. Real databases also handle conflicting concurrent writes, repair and failure detection, which this model leaves out.

11. What is eventual consistency?

If no new updates arrive, all copies converge to the same value, but for a while different readers can see different values. It is acceptable where staleness is harmless (a view counter, a search index) and needs design work where it is not (show the user their own write immediately).

12. Orchestration versus choreography in a saga?

A saga is a sequence of local transactions with compensating actions. In orchestration a central coordinator tells each service what to do and handles failures; it is easier to follow and monitor. In choreography services react to each other's events with no central brain; it is loosely coupled but the overall flow is harder to see. See Sagas.

13. What is the dual-write problem and how does the outbox solve it?

Updating your database and publishing an event are two operations; one can succeed while the other fails, leaving them inconsistent. The transactional outbox writes the event to an outbox table in the same local transaction as the data, and a relay publishes it afterwards. See The Transactional Outbox and Idempotent Consumers.

14. Is exactly-once delivery possible?

Not across a network in general. Practical systems give at-least-once delivery and make consumers idempotent, so processing a message twice has the same effect as once; the combination behaves like exactly-once processing.

15. Event sourcing versus CQRS?

CQRS separates the write model from the read models. Event sourcing stores the changes (events) as the source of truth and rebuilds state by replaying them. They are independent: you can use CQRS without event sourcing. Both add complexity, so use them where the history or read scaling matters. See Event Sourcing and CQRS.

16. What is idempotency and how do you implement it?

An operation is idempotent when repeating it has the same effect as doing it once. Typical implementation: the client sends an idempotency key, the server stores the key with the result, and a repeated request returns the stored result instead of acting again. Natural idempotency (PUT with a full resource, "set status to paid") needs no key.

Communication and resilience

17. When do you choose synchronous versus asynchronous communication?

Use synchronous calls when the caller needs the answer now (is this coupon valid?). Use asynchronous messaging when work can happen later or several consumers care (send an email, update a search index). Async decouples availability and absorbs bursts but makes flows harder to trace. See Synchronous Communication with HTTP APIs.

18. REST or gRPC between services?

REST with JSON is simple, human-readable and works everywhere. gRPC uses a strict contract (Protocol Buffers), a compact binary format, streaming and generated clients, which suits high-volume internal calls. Many systems use REST at the edge and gRPC inside. See RPC, gRPC and Protocol Buffers.

19. What does an API gateway do, and what is a BFF?

A gateway is the single entry point: routing, authentication, rate limiting, aggregation. A Backend for Frontend is a gateway tailored to one client type (web, mobile), so each client gets exactly the data shape it needs. Keep business logic out of the gateway. See API Gateway and Backend for Frontend.

20. How do services find each other?

Through service discovery: instances register with a registry (or the platform, like Kubernetes DNS, does it), and callers look up healthy instances, either client-side or via a load balancer. Health checks remove dead instances. See Service Discovery and Load Balancing.

21. What is a circuit breaker?

A wrapper that stops calling a failing dependency. It is closed normally, opens after repeated failures so calls fail fast, and after a cool-down goes half-open to try one call. It protects the caller's resources and gives the dependency room to recover. See Circuit Breakers, Bulkheads and Fallbacks.

22. What is a retry storm and how do you prevent it?

When a dependency slows down and every caller retries immediately, the extra load keeps it down. Prevent it with exponential backoff, jitter, a retry budget (a cap on retries as a share of traffic), retries only for idempotent operations, and timeouts. See Timeouts, Retries and Exponential Backoff.

23. How do timeouts, bulkheads and backpressure fit together?

Timeouts bound how long you wait. Bulkheads limit how much of your capacity one dependency can use, so one slow service does not exhaust all threads. Backpressure and load shedding push back on callers (for example with HTTP 429) when you are overloaded instead of collapsing. See Rate Limiting, Load Shedding and Backpressure.

Chains of services multiply risk. The next stand-in computes the availability of a serial chain and of redundant replicas, assuming failures are independent, which real failures often are not.

JS Availability of chains and replicas

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The numbers show why long synchronous chains hurt: every extra hop lowers the best availability you can offer, while redundancy raises it sharply. Both effects assume independent failures, so a shared database or a shared deployment bug makes the real figure worse.

Operations and security

24. What does observability need in a microservice system?

Three signals: logs (structured, with a correlation id), metrics (rates, errors, durations, saturation), and traces (one request followed across services). The correlation or trace id must travel in every call and message. See Observability: Structured Logs and Metrics and Distributed Tracing.

25. Rolling, blue-green and canary deployments: what is the difference?

Rolling replaces instances gradually. Blue-green runs a full second copy and switches traffic at once, with instant rollback. Canary sends a small share of traffic to the new version and increases it while watching metrics. See Deployment Strategies and CI/CD.

26. How do services authenticate each other?

Common options: mTLS (both sides prove identity with certificates, often via a service mesh), signed tokens such as JWTs carrying the caller and scopes, and network policies as an extra layer. The principle is zero trust: being inside the network is not proof of identity. See Authentication and Authorization Between Services.

27. How do you test and evolve APIs without breaking consumers?

Consumer-driven contract tests check that a provider still satisfies what each consumer actually uses. Evolve with backward-compatible changes (add optional fields, tolerant readers) and the expand-and-contract pattern for breaking ones. See Testing Microservices and API Versioning and Evolving Contracts.

Design prompts

For these, think aloud: clarify requirements, sketch services and data ownership, then discuss failure modes.

28. Design the checkout flow for an online shop.

Services: orders, payments, inventory, shipping, notifications. The order service starts a saga: reserve stock, charge payment, create the shipment; each step has a compensation (release stock, refund). Use an outbox for reliable events, idempotency keys on payment requests, and an order state machine (pending, paid, shipped, cancelled). Notifications consume events and never block checkout. Discuss what happens when payment succeeds but the response is lost. See Project: E-commerce with Orders, Payments and Stock.

29. How would you move a large monolith to microservices?

Do not rewrite. Put a routing facade in front, extract one loosely coupled capability first, copy and sync its data, compare in shadow mode, cut over reads then writes, and keep rollback possible. Add pipelines and monitoring before the second extraction. See Project: Strangling a Monolith.

30. A dependency is slow and the whole site is degrading. What do you do?

First stop the bleeding: check dashboards for which dependency and since when; lower its timeout, open the circuit breaker or switch the feature off with a flag; serve a fallback (cached or default data). Then diagnose with traces and recent deploys, fix or roll back, and close the loop afterwards with a blameless review: missing timeout, missing bulkhead, missing alert. Interviewers listen for order: mitigate first, root cause later.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the CAP theorem say about a network partition?

    Partitions happen in real networks, so the meaningful choice is whether to refuse requests (consistency) or answer possibly stale data (availability).
  2. 2. In the quorum model, which setting guarantees that a read overlaps the latest write with 3 replicas?

    R + W must exceed N. With N=3, W=2 and R=2 give 4 > 3, so any read set includes a replica that has the newest write.
  3. 3. Why do practical systems combine at-least-once delivery with idempotent consumers?

    Messages can be redelivered after failures. If handling twice equals handling once, the result behaves like exactly-once processing.
  4. 4. In an incident caused by a slow dependency, what comes first?

    Reduce the impact first. More retries would add load to a struggling dependency, and root-cause work can wait until users are protected.

Summary

  • Show the trade-offs: every pattern buys something and costs something.
  • Know the data story: private data per service, eventual consistency, sagas, outbox and idempotent consumers.
  • CAP is about the choice during a partition; quorums (R + W > N) make that choice tunable.
  • Resilience is a set of habits: timeouts, bounded retries with jitter, circuit breakers, bulkheads and load shedding.
  • Long synchronous chains multiply failure risk; redundancy and asynchrony reduce it.
  • In design and incident questions, clarify first, then mitigate before you diagnose.

Next: Microservices Cheat Sheet.