Scrivio Interview library
DebuggingIntermediate6 min read · updated 13 November 2026

A web app uses sticky sessions with a one-day cookie. After a rolling deploy, the three pods that came up first carry 70 percent of traffic while new pods sit nearly idle. Separately, one pod using IP-based affinity for an API gets traffic from 20,000 users behind one corporate network address.

Explain both imbalances and how you would fix them.

During the rolling deploy, the users of each stopped pod were rebalanced onto whichever pods were running at that moment, and the one-day cookie kept them there, so the first pods up collected most users and later pods only received new ones. The IP-based affinity sent every user behind one corporate NAT address to the same pod. The fix is to move sessions to a shared store and remove or shorten stickiness, use cookies or session ids instead of addresses where affinity must stay, and monitor requests per pod for skew that outlasts a deploy.

Why this question is asked

Load imbalance after a deploy is easy to dismiss as a warm-up effect, until the busy pods start to time out while new ones sit idle. Both imbalances in this question come from the same root: affinity overriding the balancer's job of spreading load. Interviewers ask it to see whether we can reason about what a balancer does over time, not just per request. In this answer, we will replay the rolling deploy step by step, explain the NAT problem, then fix both and add the monitoring that would have caught them.

1A Quick Recap: Affinity Beats Balancing

A balancer normally spreads each new request across healthy pods, for example round robin or least requests. Stickiness, or session affinity, changes that: once a user is assigned to a pod, the balancer keeps sending that user there until the stickiness expires or the pod disappears. So for sticky users, the balancing decision is made once, at assignment time, and then frozen. Whatever the pool looked like at that moment shapes the load for as long as the cookie lives, here a full day.

2Replaying the Rolling Deploy

Imagine six pods, A to F, each with about 1,000 sticky users. A rolling deploy replaces them one at a time. When A stops, its 1,000 users are balanced across the pods that exist right then: B to F plus the new A'. The balancer gives them new one-day cookies. When B stops, its users, now about 1,170, are spread over the pods available then, and so on. Pods that start early in the deploy are present for every one of these redistributions, so they collect a share of every wave. The last pod to start receives almost none of the moved users, only brand-new sessions.

Real deploys make this worse, because a new pod takes a few seconds to pass readiness, so each wave lands mostly on the older pods. The end state is what the team saw: the first three pods carry 70 percent of traffic, and the newest pods idle, because the cookies keep everyone where they landed until tomorrow.

Where sticky users end up during a rolling deploy
StepPods availableMoved users go to
A stopsA', B, C, D, E, Fspread over 6 pods, mostly old ones
B stopsA', B', C, D, E, FA' and the old pods gain again
C stopsA', B', C', D, E, FA', B' gain again
F stops (last)A' to F'F' gets only F's users and new sessions
after deployA' to F'cookies keep A', B', C' heavy for a day
Early pods are present for every wave of reassignment.

Notice that the balancer made a fair decision at every single step. The skew comes from freezing those decisions for a day while the pool changed underneath them.

3The Corporate NAT Problem

The second imbalance has a different mechanism. IP-based affinity hashes the client address to choose a pod. But the address the balancer sees is not a person; it is whatever address the packets come from. A large company sends all its employees' traffic through one or a few NAT gateways, so 20,000 users share one public address, hash to the same value and land on the same pod. Mobile carriers do the same with carrier-grade NAT, putting many subscribers behind a few addresses.

So one pod gets a load that has nothing to do with fair balancing, and adding more pods does not help, because the hash still sends that whole network to one of them. The fix is to stop using the address as a proxy for the user: use a cookie or session id for affinity, or better, no affinity at all for an API, where clients usually send a token with each request and any pod can serve them.

4Fixing It: Shared Sessions and Little or No Stickiness

The durable fix for both is to make affinity unnecessary. If session state lives in a shared store, any pod can serve any request, and the balancer can spread every request freely. With Spring Boot, Spring Session with Redis is a small change: the HttpSession API stays the same, and the session data moves to Redis.

XML
<!-- pom.xml -->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
# application.properties
spring.data.redis.host=sessions.internal
spring.session.timeout=30m
# HttpSession now reads and writes Redis: any pod can serve any user

With that in place, we turn stickiness off at the balancer, and new pods take their share of load the moment they pass readiness. If stickiness must stay for a while, for example because some part of the application still keeps state in memory, shorten it from a day to something like 10 or 30 minutes, so the skew evens out quickly after each deploy, and roll pods in a way that keeps capacity even, such as adding new pods before removing old ones.

5Monitoring for Affinity Skew

Both problems would have been visible early in one simple graph: requests per second per pod. Right after a deploy some skew is normal, but a skew that persists for more than a few minutes, or one pod consistently carrying several times the median, means affinity is overriding balancing. An alert on the ratio between the busiest pod and the median catches both the deploy pattern and a NAT hot spot, and per-pod CPU and latency show the same thing from the other side.

6Follow-up questions

What breaks if you turn stickiness off before moving sessions to a shared store?

Every request may land on a different pod, and each pod has its own in-memory sessions, so users appear logged out on every other request, carts flicker between states, and forms that store progress in the session fail. CSRF protection breaks too, because the CSRF token stored in the session on one pod is not found on the next. The order matters: move sessions to the shared store first, verify it under load, and only then remove stickiness.

Is Redis now a single point of failure for every login?

It becomes a critical dependency, so we run it with replication and automatic failover, for example a managed Redis or Valkey with a replica in another zone, and set short timeouts so a slow Redis fails requests quickly instead of blocking threads. Sessions are usually small and rebuildable by logging in again, so the impact of a short Redis failure is a forced re-login, not data loss.

7Conclusion

In this answer, we saw that a rolling deploy with a one-day sticky cookie concentrates users on the pods that started first, because each wave of moved users is reassigned to the pods present at that moment and then frozen. IP affinity piles everyone behind a NAT onto one pod. Moving sessions to a shared store with Spring Session and Redis lets us remove or shorten stickiness, cookies replace addresses where affinity remains, and a per-pod request graph catches both kinds of skew.

What to say in the interviewAbout 80 seconds aloud

Open with

Both imbalances come from affinity overriding balancing. In the rolling deploy, when each old pod stops, its sticky users are reassigned to whichever pods are running at that moment, and the one-day cookie freezes that choice.

Then, if they want more

The pods that start first are present for every wave, so they collect most users, and the last pods only get new sessions. That is why three pods carry 70 percent.

The IP-based case is simpler: the balancer hashes the source address, and 20,000 users behind one corporate NAT share that address, so they all land on one pod, and adding pods does not help.

My fix is to move session state into a shared store, for example Spring Session with Redis, then turn stickiness off so every request is balanced and new pods take load immediately.

If stickiness has to stay for a while, I would cut the duration to minutes, not a day, and roll pods by adding new ones before removing old ones. For the API, I would drop IP affinity and use a token or session id, or no affinity at all.

And I would watch requests per pod, alerting when the busiest pod stays well above the median after a deploy, because that is the sign affinity is winning.

About this answer

Last updated
13 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 official documentation for the version you use. 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 "Explain both imbalances and how you would fix them.": https://scrivio-interview-library.netlify.app/architecture/load-balancing-networking/c82d0c3f37/