Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

How does service discovery with Eureka work for a Spring Boot client, and how does it compare with Kubernetes service discovery?

With Eureka, each Spring Boot instance registers itself with the Eureka server and keeps its lease alive with heartbeats, while clients fetch the registry, cache it locally, and call services by logical name, resolved to a concrete instance by the DiscoveryClient and Spring Cloud LoadBalancer. Because of the caching, changes take some seconds to reach callers, so they may still call an instance that just stopped. Kubernetes already provides discovery and load balancing through Services and DNS, and Spring Cloud Kubernetes can expose them as a DiscoveryClient, so running Eureka on Kubernetes usually duplicates the platform unless we need client-side features.

Why this question is asked

Service discovery answers a simple question with a hard edge: where is the orders service right now? In a world of autoscaling and rolling deployments, instances come and go every few minutes, so hard-coded addresses do not work. Interviewers ask about Eureka and Kubernetes together because many teams run Spring Cloud on Kubernetes and need to decide which discovery mechanism to use. In this answer, we will recap the problem, walk through how Eureka registration and lookup work, see why its caches cause delays, then look at Kubernetes discovery and compare the two.

1A Quick Recap of Service Discovery

Service discovery is the mechanism that turns a logical service name, such as orders, into the network address of a healthy instance, such as 10.0.4.17:8080. There are two broad styles. In client-side discovery, the calling application looks up the list of instances and picks one itself. In server-side discovery, the caller sends the request to a stable address, and something in the infrastructure, a load balancer or a proxy, forwards it to an instance.

Eureka, from the Spring Cloud Netflix project, is client-side discovery. Kubernetes Services are server-side discovery, provided by the platform.

2How Eureka Registration and Lookup Work

When a Spring Boot application with the Eureka client starter starts, it registers with the Eureka server, sending its service name, host, port and status. It then sends a heartbeat, a renew request, every 30 seconds by default. If the server misses heartbeats for the lease duration, 90 seconds by default, it treats the instance as expired and removes it.

On the calling side, the Eureka client fetches the registry from the server, every 30 seconds by default, and keeps a local copy. When the code calls http://orders/api/orders/42 through a RestClient or WebClient builder marked @LoadBalanced, Spring Cloud LoadBalancer asks the DiscoveryClient for the instances of orders, picks one (round robin by default) and replaces the host name with that instance's address.

Java
@Bean
@LoadBalanced
RestClient.Builder lbRestClientBuilder() {
return RestClient.builder();
}
// in a service
Order o = builder.build().get()
.uri("http://orders/api/orders/{id}", 42) // "orders" is a service name, not a host
.retrieve().body(Order.class);
// resolved to, for example, http://10.0.4.17:8080/api/orders/42
Step throughEureka registration and a call
Orders instanceEureka serverCheckout appLoadBalancer
register orders at 10.0.4.17:8080
heartbeat every 30 s
fetch registry every 30 s
orders: [10.0.4.17, 10.0.4.18]
choose an instance of orders
10.0.4.17:8080 from local cache
GET /api/orders/42

7 messages in order. Play them, or step through them one at a time.

3Why Registry Caching Delays Changes

Caching keeps Eureka fast and resilient: callers do not ask the server on every request, and they keep working from their copy even if the Eureka server is briefly down. The price is staleness. The server itself caches its responses, the client refreshes its copy every 30 seconds, and Spring Cloud LoadBalancer has its own instance cache too. Each layer adds up to tens of seconds before a change reaches the caller.

So when an instance stops, callers may keep sending it requests for some seconds, and if it stopped without deregistering, until its lease expires. Those requests fail with connection refused or timeouts. New instances also take a while to receive traffic. Callers should therefore use timeouts and retry on another instance for idempotent requests, and services should deregister before they stop.

4How Kubernetes Does Discovery

In Kubernetes, a Service is an object that gives a set of pods a stable virtual IP address and a DNS name, such as orders.shop.svc.cluster.local, or just orders within the same namespace. Kubernetes keeps the list of the Service's endpoints up to date, adding pods when their readiness probe passes and removing them when they fail it or begin terminating. kube-proxy, or the cluster's network plugin, then load-balances connections to the Service's address across those endpoints.

For the application this is invisible: it calls http://orders:8080 and the platform does the rest, in any language, with no client library. Spring Cloud Kubernetes can also implement the DiscoveryClient interface by reading Services and endpoints from the Kubernetes API, which is useful if code already uses DiscoveryClient or needs client-side load balancing features.

Eureka compared with Kubernetes discovery
AspectEurekaKubernetes Services
StyleClient-sideServer-side, platform provided
RegistrationApp registers and heartbeatsAutomatic from pods and readiness
LookupCached registry in each clientDNS name and virtual IP
Load balancingSpring Cloud LoadBalancer in the appkube-proxy or network plugin
LanguagesJava clients mainlyAny
Extra to runEureka server clusterNothing, part of the platform

5Should We Run Eureka on Kubernetes?

Usually not. Kubernetes already knows which pods exist and which are ready, so Eureka would be a second registry that can disagree with the first, plus a server cluster to run and upgrade. Its caching delays also add on top of Kubernetes' own propagation.

There are cases where client-side discovery still adds value: custom load-balancing rules, such as zone preference or weighting by instance metadata, services that span several clusters or non-Kubernetes hosts, or a gradual migration where some services still run on virtual machines. In those cases Spring Cloud Kubernetes' DiscoveryClient or a service mesh are often better choices than Eureka, but Eureka remains a valid option when the estate is mixed.

6Follow-up questions

What happens if the Eureka server goes down?

Clients keep using their cached registry, so existing services continue to call each other, but new instances cannot register and removed instances are not noticed. Running Eureka as a cluster of peers in different zones avoids a single point of failure, and the Eureka server also has a self-preservation mode that stops expiring leases when it suddenly misses many heartbeats, on the theory that the network, not the instances, is at fault.

Does a Kubernetes Service balance individual HTTP requests?

kube-proxy balances connections, not individual requests. With long-lived HTTP/2 or gRPC connections, one client may stick to one pod. In that case client-side load balancing over the endpoint list, or a service mesh that balances per request, gives a better spread.

Why did Spring Cloud move from Ribbon to Spring Cloud LoadBalancer?

Ribbon, the Netflix client-side load balancer, went into maintenance and was removed from Spring Cloud. Spring Cloud LoadBalancer is the Spring-maintained replacement; it works with any DiscoveryClient, including Eureka, Consul and Kubernetes, and supports blocking and reactive clients.

7Conclusion

In this answer, we saw that Eureka instances register and send heartbeats, clients fetch and cache the registry, and calls by logical name are resolved through the DiscoveryClient and Spring Cloud LoadBalancer, with caching delaying changes by some seconds. Kubernetes provides discovery and load balancing itself through Services, DNS and readiness-based endpoints, which Spring Cloud Kubernetes can expose as a DiscoveryClient, so Eureka on Kubernetes is usually redundant unless we need client-side features.

What to say in the interviewAbout 80 seconds aloud

Open with

With Eureka, every Spring Boot instance registers with the Eureka server at startup and then sends a heartbeat every 30 seconds by default; if the server misses heartbeats for the lease duration, 90 seconds by default, it drops the instance.

Then, if they want more

Client applications fetch the registry, also every 30 seconds by default, and cache it locally. In code, we call services by logical name, for example http://orders with a LoadBalanced RestClient or WebClient, and Spring Cloud LoadBalancer asks the DiscoveryClient for the instances and picks one.

Because there are caches on the server, in the client and in the load balancer, a change takes some seconds to reach callers, so they can still call an instance that just stopped. That is why we need timeouts, retries on another instance and deregistration on shutdown.

In Kubernetes, discovery is built in: a Service gives a stable DNS name and virtual IP, the endpoint list follows pods and their readiness probes, and kube-proxy balances connections, for any language and with no library. Spring Cloud Kubernetes can expose those Services as a DiscoveryClient if code relies on it.

So running Eureka on Kubernetes mostly duplicates what the platform already does, and I would only keep it for client-side features or a mixed estate with services outside Kubernetes.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How does service discovery with Eureka work for a Spring Boot client, and how does it...": https://scrivio-interview-library.netlify.app/spring-boot/spring-cloud/1b06c6c21e/