All academies
Roadmap
Level 13Distributed Patterns 30 min

Service Discovery

How services find each other: registries, client vs server-side discovery, health checks, Consul, Eureka, and Kubernetes DNS.

Hands-on lab: Service Discovery SimulatorPair this lesson with its interactive simulator

The problem

In the cloud, service instances are cattle: they scale up and down, move hosts, and get new IPs constantly. Hardcoding addresses is impossible. Service discovery is the mechanism by which a caller finds a live, healthy instance of a service at request time.

Instance starts → registers with Service Registry
Registry tracks health via heartbeats
Caller looks up 'order-service'
Receives healthy instance list → routes request

Client-side vs server-side discovery

  • Client-side (Eureka + Ribbon style) — the caller queries the registry, caches the instance list, and load balances itself. Fewer hops, but every language needs a smart client library.
  • Server-side (Kubernetes Services, AWS ALB) — the caller hits a stable virtual address; a router/LB resolves to a healthy instance. Dumb clients, platform does the work.

The registries you'll meet

  • Consul (HashiCorp) — general-purpose registry + health checks + KV store; DNS and HTTP interfaces; works anywhere.
  • Eureka (Netflix) — the classic client-side registry from Spring Cloud; AP by design (prefers availability over consistency during partitions).
  • Kubernetes DNS — every Service gets a stable DNS name (order-service.shop.svc.cluster.local); kube-proxy + Endpoints do server-side discovery natively. If you run on K8s, you mostly get discovery for free.

Health checking is the hard part

A registry full of dead instances is worse than none. Instances prove liveness via heartbeats or the registry probes health endpoints. Deregistration must be prompt on failure (stop routing to a dead instance) but not trigger-happy (one slow GC pause shouldn't evict a healthy node).

Registries also face a CAP choice: during a network partition, do you serve possibly-stale instance lists (AP, Eureka) or refuse to answer (CP, etcd/ZooKeeper-backed systems)? For discovery, stale-but-available usually beats unavailable.

Key takeaways

  • Dynamic infrastructure makes hardcoded addresses impossible; discovery resolves names to healthy instances at runtime.
  • Client-side discovery = smart clients + registry; server-side = stable virtual address + platform routing.
  • Kubernetes gives server-side discovery natively via DNS + Services.
  • Health checking and CAP trade-offs (AP vs CP registries) are where discovery gets hard.

Knowledge check

Q1Multiple choice

In Kubernetes, how does service discovery primarily work?

Q2Multiple choice

Why is Eureka designed as AP rather than CP?

Q3Debugging

Requests intermittently hit an instance that crashed 2 minutes ago. What discovery mechanism is misconfigured?

Answer all questions to submit