Video in progress
What is the difference between client-side and server-side service discovery, and what problem does Eureka's self-preservation mode cause?
In client-side discovery the client gets the list of instances from the registry and picks one itself (Eureka + Spring Cloud LoadBalancer). In server-side discovery the client talks to a single address and a load balancer or the platform makes the choice. In self-preservation, Eureka may stop removing dead instances from the registry.
📖 Answer
In client-side discovery, each service takes a copy from the registry and caches it locally (the Eureka client refreshes every 30 seconds by default). The advantage is no extra network hop, and you control the balancing algorithm yourself. The downside is that you need a client library in every language, and you have to account for working with a stale cache.
In server-side discovery (a Kubernetes Service, an AWS ALB) the client calls http://payment-service and the infrastructure handles the rest.
About self-preservation. If a certain percentage (85% by default) of the expected heartbeats doesn't arrive, the Eureka server concludes "the problem is in the network, not in the instances" and doesn't remove anyone from the registry. In a network partition that is the right call. But in a small dev environment, with a service that has one or two pods, it kicks in often. As a result, shut-down instances stay in the registry and clients send requests to dead IPs.
What reduces this problem in prod:
- on graceful shutdown the service deregisters itself from Eureka;
- a client-side retry to another instance (Spring Cloud LoadBalancer retry);
eureka.server.enable-self-preservation: falsein the dev environment.
And most important: because of the caches, the "instance went down" information doesn't reach every client immediately. There is a window of 30–90 seconds, and the design has to tolerate it.
Sign up to mark studied questions and save your progress.