Service discovery in system design interviews

Service discovery is how one service finds the current network addresses of another when instances start, stop and move all the time. A registry keeps the list of healthy instances for each service name, instances get into it by registering themselves or by a platform registering them, and callers find them either directly (client-side discovery) or through a load balancer, DNS name or sidecar proxy that looks them up for them (server-side discovery).

By Published 6 min read

1. What service discovery is

In a fixed data centre, a service's address could live in a configuration file for years. With containers and autoscaling, the orders service might run on 12 instances at 9 a.m. and 40 at noon, each with a new address, and any instance can be replaced at any time. Discovery answers "where can I send a request for orders right now?" with a fresh, healthy list. It sits next to load balancing: discovery produces the candidates, load balancing picks one.

2. Why interviewers ask about it

Once a design has several services, interviewers ask how they find each other and what happens when an instance dies mid-request. The topic tests whether you understand dynamic infrastructure: registration, health checks, caching, and the failure of the discovery system itself. It also links to sharding and consistent hashing and to consistency and CAP, since the registry is itself a replicated store.

3. The registry and health checks

Ways an instance gets in and out of the registry
ApproachHow it worksTrade-off
Self-registrationOn start, the instance registers its address and renews a lease with heartbeats; on clean shutdown it deregistersSimple; every service needs the client code, and a crashed instance lingers until its lease expires
Third-party registrationThe platform (an orchestrator or a registrar process) watches instances and updates the registryServices stay unaware of discovery; the platform must be trusted and highly available
Ways an instance gets in and out of the registry. Scroll sideways on a small screen.
  • Liveness vs readiness. A process can be alive but not ready (warming a cache, waiting on its database). Register an instance for traffic only when it is ready, and take it out before shutdown so in-flight requests can finish (drain).
  • Active checks. The registry or a health checker calls a health endpoint every few seconds and removes instances after several failures in a row.
  • Leases and TTLs. Each registration expires unless renewed. Short leases remove dead instances quickly but add heartbeat traffic and risk removing healthy ones during a brief network hiccup.
  • Passive checks. Callers or proxies notice errors on real traffic and temporarily eject a bad instance (outlier detection), which reacts faster than periodic checks.

4. Four ways callers find services

Discovery styles
StyleHow a call is routedGood atCosts
Client-sideThe caller's library queries or watches the registry, caches the list and picks an instance itselfNo extra hop; smart balancing (least requests, zone-aware)A discovery library in every language you use
Server-sideThe caller sends to a load balancer address; the balancer reads the registry and forwardsThin clients; one place to change behaviourAn extra hop and a component to scale and keep available
DNSA service name resolves to instance addresses (A records) or to host and port (SRV records)Works with any client, nothing to installClients and resolvers cache answers, sometimes longer than the TTL, so changes propagate slowly
Service mesh sidecarA proxy next to each instance receives the address list from a control plane and routes, retries and ejects outliersUniform behaviour, plus mutual TLS and telemetryMore moving parts and some added latency per hop
Discovery styles. Scroll sideways on a small screen.

Container orchestrators usually combine these. In Kubernetes, for example, a Service gets a stable DNS name and virtual IP, and the platform keeps the list of ready pods behind it up to date, so most application code simply calls the name. A mesh, where used, adds sidecars on top of that.

5. The registry's own consistency and failure

  • Strongly consistent registries (built on consensus, as etcd, ZooKeeper and Consul's servers are) give every reader the same view but refuse writes when they lose a majority. Good for configuration and leader election, where a wrong answer is dangerous.
  • Availability-leaning registries keep answering during a partition with possibly stale data. Netflix's Eureka is the usual example of this choice. For discovery, a slightly stale list is often better than no list: a dead entry costs one failed call that the caller can retry elsewhere.
  • Cache on the caller. Whatever the registry, clients and sidecars should keep the last known list and keep using it if the registry becomes unreachable, rather than dropping all instances.
  • Guard against mass deregistration. If a network problem cuts the registry off from most instances, removing them all would leave callers with nothing. Some registries stop expiring leases when too many disappear at once (a self-preservation mode), and some clients refuse to apply an update that empties a list.

6. Trade-offs

  • Fresh or stable. Watching the registry for changes gives near-instant updates; polling every 30 seconds is simpler and more forgiving. Pair either with passive ejection so callers stop hitting a bad instance before the registry notices.
  • Library or proxy. Libraries avoid a hop and allow per-call logic; proxies give one behaviour across languages and can be upgraded without redeploying services.
  • DNS simplicity or control. DNS needs nothing new, but you cannot easily control client caching, and plain A records carry no weights or health detail.

7. How it shows up in common prompts

Discovery in the walk-throughs
PromptWhat must be foundDetail worth raising
Nearby friendsWhich pub/sub node owns a user's channelConnection servers watch the node map in a coordination store
Live commentsGateway servers for new viewersDrain gateways before deploys so viewers reconnect gradually
Stock exchangeThe current primary matching engine for a symbol groupFailover must update every gateway at once; a stale primary address is dangerous
Job schedulerHealthy workers and the current leaderLeases with expiry decide who is alive
WhatsAppWhich chat server holds a recipient's connectionA session registry, updated on every connect and disconnect
Discovery in the walk-throughs. Scroll sideways on a small screen.

8. Interview questions on service discovery

Questions you may be asked and what a strong answer covers
QuestionA strong answer covers
Client-side or server-side discovery?Hop count, language support, where balancing logic lives
How does a new instance start receiving traffic?Readiness check, registration, callers' caches refresh
How is a crashed instance removed?Lease expiry or failed health checks, plus passive ejection by callers
What if the registry is down?Callers keep the last known list; new instances cannot register until it is back
Why not just use DNS?It works, but caching delays changes and records carry little health or weight data
How do you deploy without dropped requests?Deregister, drain in-flight work, then stop; the reverse for start-up
Should the registry be CP or AP?Discovery tolerates staleness, so availability often wins; leader election needs consistency
Questions you may be asked and what a strong answer covers. Scroll sideways on a small screen.

9. Mistakes to avoid

  • Registering on process start instead of when the instance is ready.
  • No plan for the registry failing. It is a dependency of every call.
  • Trusting DNS TTLs to remove a dead instance within seconds.
  • Killing instances without draining, which turns every deploy into a burst of errors.
  • Confusing discovery with load balancing. Name both: one finds candidates, the other picks.

10. How to talk about it in the interview

Fictional example

An instance dies during a request
Interviewer
The orders service has 20 instances and one crashes. How does the cart service stop sending it traffic?
Candidate
Two ways, at different speeds. The cart's sidecar sees connection failures and ejects that instance within a few failed calls. Meanwhile the instance misses its heartbeats, its lease expires after about 15 seconds, and the registry pushes an updated list to every sidecar.
Interviewer
And if the registry itself goes down?
Candidate
Sidecars keep using the last list they received, so calls continue. New instances cannot join until it recovers, which is why I would run it as a replicated cluster across zones.

Practicing with Natively

Discovery questions tend to be short and come in clusters, so a mock interview where someone fires them at you is better practice than reading. Natively can transcribe that call, suggest an angle such as draining or the registry outage when you hesitate, and draw a sidecar and registry diagram on request. Afterwards you can review which answers were crisp and which wandered.

Questions people ask

What is service discovery?

The mechanism that lets a service find the current, healthy network addresses of another service whose instances start, stop and move. A registry holds the list per service name, and callers look it up directly or through a load balancer, DNS name or sidecar proxy.

What is the difference between client-side and server-side discovery?

In client-side discovery the caller's library reads the registry and picks an instance itself, which avoids a hop but needs a library per language. In server-side discovery the caller sends to a load balancer or proxy that does the lookup, which keeps clients simple but adds a component and a hop.

Can DNS be used for service discovery?

Yes. A service name can resolve to instance addresses or to SRV records with ports. It works with any client, but resolvers and clients cache answers, so removing a dead instance can take longer than its TTL suggests.

What happens if the service registry goes down?

Well-built callers keep using the last list they received, so existing traffic continues, but new instances cannot register until the registry recovers. That is why registries run as replicated clusters across zones.

Where to go next

Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.

Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP