Quick revision
The short answer
I would enable zone preference in Spring Cloud LoadBalancer, so each client sends traffic to instances in its own availability zone and falls back to other zones only when its zone has none. Because zone preference alone ignores speed, I would add health checks and response-time-aware or weighted selection so slow instances get less traffic, check that each zone has enough capacity for its local traffic and for a zone failure, and measure cross-zone traffic and latency per zone. On Kubernetes, the platform's topology-aware routing can achieve similar results without client changes.
What to remember
In this answer, we saw that zone preference in Spring Cloud LoadBalancer keeps calls inside the caller's zone and falls back only when the zone has no instances, that health checks and weighted or latency-aware selection are needed so a slow or failing zone does not get stuck with its traffic, that each zone needs capacity for local load and for a failed zone's share, that cross-zone traffic and latency should be measured before and after, and that Kubernetes topology-aware routing or a mesh can do similar work at the platform level.
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.
I would enable zone preference in Spring Cloud LoadBalancer, so each client sends traffic to instances in its own availability zone and falls back to other zones only when its zone has none. Because zone preference alone ignores speed, I would add health checks and response-time-aware or weighted selection so slow instances get less traffic, check that each zone has enough capacity for its local traffic and for a zone failure, and measure cross-zone traffic and latency per zone. On Kubernetes, the platform's topology-aware routing can achieve similar results without client changes.
Why this question is asked
Running in three availability zones protects us from a zone failure, but it has two everyday costs. Calls that cross zones add a little latency and, in most clouds, a data transfer charge on every gigabyte, which adds up quickly for chatty services. And zones are not always equal: one may have older hardware or a noisy neighbour. Interviewers ask this scenario to see whether we can use client-side load balancing for these trade-offs without creating new failure modes. In this answer, we will recap zones and the cost of crossing them, configure zone preference, deal with the slow zone, check capacity, measure the effect, and compare with the Kubernetes alternative.
1A Quick Recap of Zones and Cross-Zone Cost
An availability zone is a separate data centre, or group of them, within a cloud region, with its own power and network. Spreading instances across three zones means one zone can fail and the service keeps running. Calls between zones travel further than calls within a zone, typically adding around a millisecond, and most cloud providers charge for data transferred between zones, for example around one cent per gigabyte in each direction (check your provider's current prices).
With plain round robin across all instances, a client in zone a sends two thirds of its calls to zones b and c. So keeping traffic local is worth doing, as long as it does not hurt availability.
2Turning On Zone Preference
Spring Cloud LoadBalancer has a zone-preference instance supplier. Each client is told its own zone, and each instance advertises its zone through discovery metadata. The supplier then filters the instance list to those in the client's zone. If that leaves no instances, it returns the full list, so the client falls back to other zones instead of failing.
Notice one important limit. Zone preference falls back only when the local zone has no instances at all. If the two local instances are alive but overloaded or slow, the client keeps sending everything to them. On its own, zone preference optimises for cost and latency in the healthy case, but it can make a bad zone worse.
3Handling the Slow Zone
One zone's instances are slower, so we need selection that reacts to health and speed, not just location. The first layer is health checking. The health-check supplier pings each instance's health endpoint and removes instances that fail, so a zone whose instances are failing is treated as empty and traffic falls back to the other zones. Health checks catch broken instances, but not slow ones that still answer.
For slow instances, we can give them less traffic. Spring Cloud LoadBalancer has a weighted supplier, where instances advertise a weight in their metadata; we can lower the weights in the slow zone while we investigate. Better still is selection that measures response time: a custom ReactorServiceInstanceLoadBalancer can track recent latency or in-flight requests per instance and choose, for example, the less loaded of two randomly picked instances. That idea, called power of two choices, naturally moves load away from slow instances. A service mesh such as Istio, through Envoy's least-request balancing and outlier detection, provides this without custom code.
- All instances from discovery6 instances in 3 zones
- Remove failing instanceshealth-check supplier
- Any healthy instance in my zone?YesKeep only my zoneNoUse all healthy instances
- Pick by load or latencyweights or least loaded of two
- Send the requestrecord its latency for later choices
5 steps in order. Play them, or step through them one at a time.
Location is preferred, but health and speed can override it.
4Checking Capacity per Zone
Zone-local traffic changes how we size the service. With round robin, every instance shares the total load. With zone preference, each zone's instances must serve all traffic from callers in that zone. If callers are unevenly spread, for example 50 percent of callers in zone a, then zone a's orders instances get half the total load, even if they are only a third of the instances.
We also plan for a zone failure. If zone c fails, its callers are gone too, but if the orders instances in c fail while c's callers survive, those callers fall back to zones a and b. So each zone needs headroom for its own traffic plus a share of a failed zone's. A common rule with three zones is to size each zone so that two zones can carry the full load, which means each zone runs at no more than about two thirds of its capacity in normal times. Autoscaling per zone, rather than for the service as a whole, keeps this balanced.
5Measuring the Effect
We should not guess whether this works. Before the change we measure cross-zone traffic, for example from the cloud's flow logs or billing per service, and latency and error rate per zone pair. We tag client metrics with the caller's zone and the instance's zone, so a dashboard shows how much traffic stays local and how latency differs. After enabling zone preference, local traffic should rise to close to 100 percent in normal times, and the cost line for inter-zone transfer should fall. If the slow zone's latency still shows in user-facing numbers, the selection layer needs tuning.
6The Kubernetes Alternative
On Kubernetes, the platform can do zone-aware routing itself. Topology-aware routing, enabled with an annotation on the Service, makes kube-proxy prefer endpoints in the same zone when capacity allows, and newer versions offer a trafficDistribution field on the Service with a PreferClose setting (check your Kubernetes version for the exact names and status). The advantage is that every client, in any language, benefits without code changes. The trade-off is less control: the platform decides based on endpoint counts and its own rules, and it does not measure response time. A service mesh adds locality-aware balancing with outlier detection. Whichever layer we choose, we should do it in one place, so the platform and the client library do not both try to steer the same traffic.
7Follow-up questions
What happens if a zone has instances but they are all failing?
With zone preference alone, the client keeps sending to them, and calls fail. With the health-check supplier in the chain before zone preference, failing instances are removed, the zone appears empty, and traffic falls back to the other zones. That ordering is why we always combine the two.
Should we also keep databases zone-local?
Writes usually go to one primary, which lives in one zone, so cross-zone traffic is unavoidable there. Reads can go to a replica in the same zone if the application accepts slightly stale data. The same cost and capacity thinking applies.
Is it worth the complexity for a small system?
Probably not. If cross-zone traffic costs a few dollars a month and latency is fine, plain round robin is simpler and spreads load evenly. Zone preference pays off when traffic volume is high or latency budgets are tight.
8Conclusion
In this answer, we saw that zone preference in Spring Cloud LoadBalancer keeps calls inside the caller's zone and falls back only when the zone has no instances, that health checks and weighted or latency-aware selection are needed so a slow or failing zone does not get stuck with its traffic, that each zone needs capacity for local load and for a failed zone's share, that cross-zone traffic and latency should be measured before and after, and that Kubernetes topology-aware routing or a mesh can do similar work at the platform level.
Open with
I would start with zone preference in Spring Cloud LoadBalancer: each client gets its zone in spring.cloud.loadbalancer.zone, instances advertise their zone in discovery metadata, and the zone-preference configuration filters the list to local instances, falling back to all instances only when the zone has none.
Then, if they want more
That removes most cross-zone calls, saving the transfer cost and around a millisecond per hop. But zone preference alone is dangerous with a slow zone, because it only falls back when there are zero local instances.
So I would put the health-check supplier first, which removes failing instances, and add load- or latency-aware selection, for example weights in metadata or a custom balancer that picks the less loaded of two instances, so slow instances get less traffic.
Then capacity: with zone-local traffic, each zone's instances must handle that zone's callers, and I would size so two zones can carry the whole load, which means running each at about two thirds capacity and autoscaling per zone. I would measure cross-zone bytes and latency per zone pair before and after, with metrics tagged by caller and instance zone.
On Kubernetes, topology-aware routing on the Service, or a mesh with locality balancing and outlier detection, can do the same for every language without code changes; I would choose one layer to do it, not both.
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 Cloud documentation, Resilience4j documentation
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 "Your services run in three availability zones. Cross-zone traffic is costly and one...": https://scrivio-interview-library.netlify.app/spring-boot/spring-cloud/d7abb6dc75/