Quick revision
The short answer
@LoadBalanced marks a RestClient.Builder or WebClient.Builder bean so that Spring Cloud adds an interceptor (for RestClient) or an exchange filter (for WebClient) to every client built from it. That interceptor treats the host in a URL such as http://inventory/stock as a logical service name, asks Spring Cloud LoadBalancer for an instance of that service, and rewrites the request to that instance's real host and port. Instances come from a ServiceInstanceListSupplier backed by discovery (Eureka, Consul, Kubernetes) or static configuration, the default choice is round-robin with random and custom strategies available, and Netflix Ribbon is no longer supported.
What to remember
In this answer, we saw that @LoadBalanced is a qualifier that makes Spring Cloud add a load-balancing interceptor to RestClient and RestTemplate builders, or an exchange filter to WebClient builders. That interceptor treats the URL's host as a service name, asks Spring Cloud LoadBalancer for an instance, and rewrites the request. Instances come from a ServiceInstanceListSupplier backed by Eureka, Consul, Kubernetes or static configuration, chosen round-robin by default with random or custom strategies available, and Ribbon is gone since Spring Cloud 2020.0. The usual mistakes are building clients outside the annotated builder and using it for external hosts.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
@LoadBalanced marks a RestClient.Builder or WebClient.Builder bean so that Spring Cloud adds an interceptor (for RestClient) or an exchange filter (for WebClient) to every client built from it. That interceptor treats the host in a URL such as http://inventory/stock as a logical service name, asks Spring Cloud LoadBalancer for an instance of that service, and rewrites the request to that instance's real host and port. Instances come from a ServiceInstanceListSupplier backed by discovery (Eureka, Consul, Kubernetes) or static configuration, the default choice is round-robin with random and custom strategies available, and Netflix Ribbon is no longer supported.
Why this question is asked
In a microservices system, instances of a service come and go all the time: deployments, autoscaling, failures. Hard-coding hostnames does not work, and putting a separate load balancer in front of every internal service adds cost and a network hop. Client-side load balancing lets each caller pick a healthy instance itself. Interviewers ask about @LoadBalanced because it is a small annotation hiding a lot of machinery, and because it causes a classic bug when the builder is created in the wrong way. In this answer, we will recap client-side load balancing, look at what the annotation actually does, follow a request through it, see where instances come from and how one is chosen, and finish with the common mistakes.
1A Quick Recap of Client-Side Load Balancing
Load balancing spreads requests over several instances of a service. With a server-side load balancer, the client sends every request to one address, and a separate component forwards it to an instance. With client-side load balancing, the client itself knows the list of instances and picks one for each request. There is no extra hop, and each client can make smarter choices, but each client needs a library that does it.
In Spring Cloud, that library is Spring Cloud LoadBalancer. It needs two things: a way to get the current instances of a service, usually from a service registry such as Eureka or Consul, or from Kubernetes, and a strategy for choosing one.
2What the Annotation Actually Does
@LoadBalanced is a qualifier annotation: on its own it only marks a bean. Spring Cloud's auto-configuration looks for builder beans with that mark and customises them. For RestClient.Builder and RestTemplate it adds a ClientHttpRequestInterceptor, the load balancer interceptor. For WebClient.Builder it adds an ExchangeFilterFunction that does the same job reactively. Every client we build from that builder carries the interceptor.
Notice that "inventory" is not resolvable by DNS. Without the interceptor, this call would fail with an unknown host error. With it, the interceptor replaces the logical name with the address of a real instance before the request leaves our service.
3Following a Request Through the Load Balancer
When we call the client, the interceptor reads the host part of the URL, inventory, and asks the load balancer client to choose an instance for that service id. The load balancer asks the ServiceInstanceListSupplier for the current instances, applies its strategy to pick one, and returns it. The interceptor rewrites the URI to that instance's host and port and lets the request continue. The response comes back as usual.
8 messages in order. Play them, or step through them one at a time.
The registry is not called on every request; the instance list is cached.
4Where the Instances Come From
The list of instances comes from a ServiceInstanceListSupplier. The default one is backed by the application's DiscoveryClient, which reads from whichever registry is on the classpath: Eureka, Consul, Zookeeper, or Kubernetes through Spring Cloud Kubernetes, which reads the endpoints of a Kubernetes Service. Suppliers can be wrapped to add behaviour, such as caching the list (on by default, so the registry is not queried per request), health-check filtering, or preferring instances in the same zone.
Without any registry, we can list instances in configuration with the simple discovery client. This is useful for local development and tests.
5How an Instance Is Chosen
Spring Cloud LoadBalancer uses round-robin by default: it goes through the instances in order, one request each, so with three instances each gets a third of the traffic. A RandomLoadBalancer is also provided, and we can supply our own strategy by implementing ReactorServiceInstanceLoadBalancer, for example to weight instances. The strategy is configured per service with @LoadBalancerClient.
Before Spring Cloud LoadBalancer, the same role was played by Netflix Ribbon. Ribbon went into maintenance and was removed from Spring Cloud in the 2020.0 release train, so any guide that configures Ribbon properties is out of date.
6Common Mistakes
The most common mistake is building a client that bypasses the annotated bean, for example calling RestClient.builder() directly in a method or injecting Spring Boot's plain auto-configured builder. That client has no interceptor, and calls to http://inventory fail with an unknown host. The client must be built from the @LoadBalanced builder, injected with the same qualifier.
The opposite mistake is using the load-balanced builder for external calls. A call to https://api.partner.com would be treated as a service named api.partner.com and fail because no such service is registered. So we keep two builder beans: a plain one for external hosts and a @LoadBalanced one for internal service names. Finally, builders are mutable, so we should not share one builder instance and modify it for different clients; we build each client from a fresh clone or from the injected prototype.
7Follow-up questions
Does @LoadBalanced retry on another instance if one fails?
Not by default. Spring Cloud LoadBalancer supports retries, including trying a different instance, when Spring Retry is on the classpath for blocking clients, or through its reactive retry support for WebClient, configured with spring.cloud.loadbalancer.retry properties; check your version. Those retries must be counted in the overall retry policy, so they do not multiply with application retries.
Does it work with HTTP interface clients?
Yes. We build the RestClient from the @LoadBalanced builder, wrap it in RestClientAdapter and create the interface client from it. The interface's calls go through the same interceptor, so the base URL can be http://inventory.
Is client-side load balancing needed on Kubernetes?
Not always. A Kubernetes Service already balances connections across pods. Client-side balancing helps when connections are long-lived and pooled, because Kubernetes balances per connection, not per request, so a few clients can stick to a few pods. Whether that matters depends on the traffic pattern.
8Conclusion
In this answer, we saw that @LoadBalanced is a qualifier that makes Spring Cloud add a load-balancing interceptor to RestClient and RestTemplate builders, or an exchange filter to WebClient builders. That interceptor treats the URL's host as a service name, asks Spring Cloud LoadBalancer for an instance, and rewrites the request. Instances come from a ServiceInstanceListSupplier backed by Eureka, Consul, Kubernetes or static configuration, chosen round-robin by default with random or custom strategies available, and Ribbon is gone since Spring Cloud 2020.0. The usual mistakes are building clients outside the annotated builder and using it for external hosts.
Open with
@LoadBalanced is a qualifier that I put on a RestClient.Builder, RestTemplate or WebClient.Builder bean. Spring Cloud's auto-configuration finds builders with that mark and adds a load balancer interceptor, or for WebClient an exchange filter function.
Then, if they want more
From then on, any client built from that builder treats the host in the URL as a logical service name. So for http://inventory/stock/A-1, the interceptor asks Spring Cloud LoadBalancer to choose an instance of inventory, gets back something like 10.0.3.22 on port 8080, rewrites the URI, and sends the request there.
The instances come from a ServiceInstanceListSupplier, which by default uses the DiscoveryClient, so Eureka, Consul or Kubernetes endpoints, and the list is cached rather than fetched per request. For local work I can list instances statically with the simple discovery client properties.
The default strategy is round-robin; there is a RandomLoadBalancer and I can plug in a custom one per service with @LoadBalancerClient. Ribbon used to do this, but it was removed in the 2020.0 release train.
The classic mistake is building a client from a plain RestClient.builder(), which has no interceptor, so the service name fails to resolve, and the opposite one is using the load-balanced builder for external hosts. I keep two builder beans for that reason.
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.
- Official documentation
- Spring Framework reference, Spring Web MVC
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 "What does @LoadBalanced do on a RestClient.Builder or WebClient.Builder bean in Spring...": https://scrivio-interview-library.netlify.app/spring-boot/http-clients/ea8654f0a5/