Skip to content
System Design Lab
Microservice Patterns

Service Discovery

Instances come and go with every deploy, crash and scale event. Service discovery keeps callers pointed at the instances that exist right now — from the client side via a registry, or from the server side via a load balancer.

Intermediate 4 min read· Updated 2026-11-18

What you will learn

  • Explain why hard-coded addresses break in dynamic environments.
  • Compare client-side and server-side discovery.
  • Understand registration (self vs third-party) and staleness.
  • Recognise what Kubernetes and service meshes already do for you.

Before you start

Overview

A taxi company does not give customers a driver's phone number — drivers change shifts all day. Customers call the dispatcher, who knows which drivers are on duty right now.

In the cloud, instances get new addresses whenever they are deployed, rescheduled or scaled. A service registry keeps the current list: instances register on start-up (or a platform registers them), are removed when health checks fail, and callers find them through client-side discovery (ask the registry, load balance yourself) or server-side discovery (call one stable address; a router asks the registry).

Run it

At t = 12 s a rolling update replaces orders-2 with orders-4. Watch the failures and Served by the new orders-4 in each design, and try the cache refresh slider in B.

Loading simulation…

Client-side vs server-side

Client-side (Eureka, Consul + client)Server-side (Kubernetes Service, cloud LB, mesh)
Who picks the instanceThe caller's libraryA router / proxy
Extra hopNoYes (often on the same node)
Language supportNeeds a client per languageAny HTTP/gRPC client
StalenessUp to the cache refresh intervalUp to the health-check interval
Smart routingEasy (zones, versions) in the clientIn the proxy / mesh config

Examples

Kubernetes: server-side discovery built in
apiVersion: v1
kind: Service
metadata: { name: orders }
spec:
  selector: { app: orders }        # every ready pod with this label is an endpoint
  ports: [{ port: 80, targetPort: 8080 }]
# Callers use http://orders — DNS + kube-proxy route to ready pods; readiness probes remove bad ones.
Spring Cloud: client-side discovery with a load-balanced client
@Bean @LoadBalanced
RestClient.Builder restClientBuilder() { return RestClient.builder(); }

// "orders" is a service id resolved from the registry (Eureka/Consul), not a host name.
Order order = restClientBuilder.build().get().uri("http://orders/api/orders/{id}", id).retrieve().body(Order.class);

Trade-offs

BenefitsCosts
Client-sideNo extra hop; rich client-side routing.Discovery logic in every service and language; caches go stale.
Server-sideCallers stay simple; one place to configure routing.An extra hop and a component that must be highly available.
RegistrySingle source of truth for what is running.Critical dependency: if it is down or wrong, nothing can be found.

Production considerations

  • On Kubernetes, prefer the built-in Service/DNS discovery unless you need client-side features.
  • Keep DNS TTLs and client caches short, and make clients retry on another instance after a connection error.
  • Use readiness (not liveness) to decide registration, so warming instances get no traffic.
  • Run the registry replicated; let clients keep their last known list if it is briefly unavailable.

Further reading

Related topics