All interview questions

Microservices Interview Questions

Splitting a system into services makes network failures and independent deployments part of its design. Practice explaining how you would handle those costs, and when you would keep the system together.

Try answering aloud before opening each explanation.

Try the Microservices practice demo

Foundations

When is a modular monolith a better starting point than microservices?

Keep one deployable when boundaries are changing quickly, one team owns the system and independent scaling is not needed. Enforce module boundaries in code. Split a module when there is a concrete benefit worth the cost of a network contract, extra infrastructure and independent failure modes.

How can you tell whether two proposed services have the wrong boundary?

Look for changes that routinely require modifying and deploying both, or rules that need an atomic write to both sets of data. Those are signs the boundary cuts across one business capability. Measure release coupling and call frequency before choosing where to move responsibility.

Does database per service require a separate database server for every service?

The requirement is ownership: other services do not read or mutate the service's tables directly. Separate schemas or logical databases can share infrastructure if privileges and isolation suffice. Dedicated infrastructure is useful when load, recovery or availability requirements differ.

What do you trade when replacing a synchronous call with a queue?

A queue buffers work while the consumer is temporarily unavailable and lets producers finish earlier. The caller loses an immediate result and must account for delayed processing, duplicates and growing backlog. If a user needs a decision now, asynchronous acceptance alone may not satisfy the requirement.

What should a service discovery mechanism tell a caller?

It maps a logical service name to endpoints the caller can reach. Registration, health and DNS caching determine how fast the view changes. Discovery does not guarantee a request will succeed: endpoints can become unhealthy between lookup and use, so callers still need deadlines and failure handling.

Applied

How do you stop each layer of a request chain from spending the full timeout?

Propagate a deadline or remaining time budget from the entry point. Reserve time to return the response and bound each dependency call by the remaining budget. Stop starting new work once the deadline cannot be met; cancellation helps avoid spending resources on abandoned requests.

What is the difference between a circuit breaker and a bulkhead?

A circuit breaker temporarily rejects calls to a failing dependency so it has a chance to recover. A bulkhead isolates resources such as concurrency slots so one dependency or tenant cannot consume them all. A failing dependency can require both faster rejection and resource isolation.

Why can an event be delivered twice even with a transactional outbox?

The outbox makes the state change and publication intent atomic, not broker delivery. A relay can publish and crash before marking the record dispatched. Consumers should deduplicate using a durable event ID or make the business action naturally idempotent.

What makes a saga compensation different from rolling back a database transaction?

Compensation is a new business action after already committed steps. It can fail or need a policy decision, and external effects such as a sent email cannot be undone. Persist the workflow state, retry safely and make unresolved cases visible to operators.

How does a read projection handle messages delivered out of order?

Use a source version per entity when projecting full states, so an older message cannot overwrite a newer one. For incremental events, detect missing versions and replay or rebuild rather than dropping needed changes. Specify what users see while the projection catches up.

Production scenarios

What happens if three layers each retry a failing dependency twice?

If each initial request can make three attempts, a fully exhausted chain can produce up to 27 calls at the final layer. Choose one retry owner, cap attempts within the deadline, use jitter and retry only operations that can safely be repeated.

How do you find the cause of one slow request crossing five services?

Propagate trace context and look at the request's critical path rather than summing all span durations. Compare slow and healthy traces, then use dependency latency and error metrics to check whether the example is representative. Include queue wait if the request crosses messaging.

How do you replace an event field when consumers deploy independently?

Introduce the new field without removing the old one. Update consumers to accept both versions, then update producers and verify compatibility through a rollout window. Retain the old reader path as long as old events can be replayed, or define a versioned conversion.

How do you know if a growing queue is a temporary burst or sustained overload?

Compare arrival and successful processing rates, and track the age of the oldest unprocessed message. If consumers consistently process less than arrivals, adding buffer only delays the failure. Look for a throughput bottleneck, isolate poison messages and apply backpressure where needed.

What evidence would justify rolling back a canary service release?

Define guardrails before the release: error rate, latency, resource saturation and a business success metric. Compare the canary with a similar traffic cohort on the previous version. Check whether migrations and written data remain backward-compatible before assuming a binary rollback is safe.

Further reading

Official documentation

Related question sets