Video in progress
What is service discovery, and how do client-side and server-side discovery differ?
Service discovery is how a service finds out the addresses of another service's currently running instances. In client-side discovery, the client gets the list from a registry and balances itself; in server-side discovery, the client goes to a single address (an LB or a Kubernetes Service) and that makes the choice.
📖 Answer
Pods come and go, and IPs change. You can't hard-code which IPs order-service is running on.
Client-side discovery. Instances register themselves in a registry (Eureka, Consul) and send heartbeats. The client gets the list, caches it and picks one itself:
@Bean
@LoadBalanced // Spring Cloud LoadBalancer
RestClient.Builder restClientBuilder() {
return RestClient.builder();
}
// then: http://order-service/orders/42 — the name is resolved to an IP on the client
There's no extra hop, and the client can balance smartly. But you need a library for every language and framework, and the logic is spread across all services.
Server-side discovery. The client goes to http://order-service and the infrastructure handles the rest. In Kubernetes, a Service name resolves through DNS to a ClusterIP, and kube-proxy spreads traffic across the ready pods. The client knows nothing.
Today, for Spring Boot applications running on Kubernetes, you often don't need Eureka — the platform itself provides discovery. Eureka/Consul remain mostly on VMs or in mixed environments.
One thing: the list in a registry or in DNS can be slightly stale — a dead instance stays on the list for a few seconds. So you still need timeouts and retries.
Sign up to mark studied questions and save your progress.