Scrivio Interview library
ScenarioAdvanced7 min read · updated 13 November 2026

A chat platform holds 6 million concurrent WebSocket connections on 300 gateway pods. A routine deploy restarted pods in batches of 30; each batch dropped about 600,000 clients, which reconnected and synced at once, and delivery latency rose from 200 ms to 90 seconds for everyone.

Explain why a routine gateway deploy became a platform-wide incident, and what you would change in the gateways, the clients and the sync path so restarts and gateway failures stay invisible to users.

A reconnect is far more expensive than a normal request: each one does a TLS handshake, a token check, a presence update, a session registry write and a history sync per active conversation, so 600,000 clients reconnecting at once multiplied load on auth, the registry and the message store far beyond peak. The fix is gentle draining that spreads disconnects over minutes, clients that reconnect with exponential backoff and full jitter and sync only the delta from a cursor, shared dependencies protected by caching, rate limits and priorities, a session registry that tolerates churn, and a reconnect-storm load test sized to a whole zone.

Why this question is asked

Long-lived connections change the rules of deployment. With ordinary HTTP services, restarting a pod loses a few in-flight requests. With WebSocket gateways, restarting a pod disconnects every client on it, and they all come back at once. This incident shows how a routine deploy turned into a platform-wide outage. Interviewers ask it because it tests whether we can see the full cost of a reconnect and design the gateways, the clients and the sync path together. In this answer, we will measure what a reconnect costs, see why batches of 30 pods overwhelmed the platform, and then fix the gateways, the clients, the shared dependencies and the registry, and prove the fix.

1A Quick Recap of the Incident

6 million clients hold WebSocket connections across 300 gateway pods, about 20,000 per pod. The deploy restarted 30 pods at a time, so each batch dropped about 600,000 clients. Those clients noticed within a second or two and reconnected immediately, landing on the remaining pods and then on the new ones. Delivery latency for every user rose from 200 ms to 90 seconds, because the whole platform was busy handling reconnects.

2What One Reconnect Really Costs

A reconnect is not one request. The client opens a TCP connection and does a TLS handshake, which is CPU-heavy on the gateway. It presents its token, which the gateway validates, often by calling the auth service. The gateway writes the session to the registry and publishes a presence update, I am online, which fans out to the user's contacts. Then the client syncs: for each active conversation, it asks the message store for what it missed.

Suppose a client has 15 active conversations. Then 600,000 reconnects mean 600,000 handshakes and token checks, 600,000 registry writes, presence fan-out to perhaps tens of millions of contacts, and 9 million history queries, all within a few seconds. Normal peak traffic for the message store might be 100,000 queries per second; this batch alone asked for ninety times that. Queues built up everywhere, and live messages waited behind sync traffic. That is why every user saw 90-second delays, not just the reconnecting ones.

Work caused by one batch of 600,000 reconnects
StepPer clientFor the batch
TLS handshake1600,000
Token validation1 auth call600,000
Session registry write1600,000
Presence updatefan-out to contactstens of millions of notifications
History syncabout 15 queriesabout 9,000,000 queries

3Draining Gateways Gently

The first fix is in how gateways stop. When a gateway is told to shut down, it first stops accepting new connections, so the load balancer sends new clients elsewhere. Then it closes its existing connections gradually over several minutes, for example 20,000 connections over 5 minutes is about 70 per second, sending each client a close frame with a reconnect hint that says to reconnect after a random delay. The pod's termination grace period in Kubernetes, terminationGracePeriodSeconds, must be longer than the drain, or Kubernetes will kill the pod midway.

We also roll fewer pods at a time. Instead of 30 pods per batch, rolling 3 or 5 at a time with a drain of several minutes each means the reconnect rate stays a small fraction of normal traffic. A deploy of 300 pods then takes longer, perhaps an hour or two, but it is automated and invisible.

Step throughGraceful drain of one gateway pod
  1. Receive termination signalpreStop hook starts the drain
  2. Stop accepting new connectionsreadiness fails, load balancer stops sending clients
  3. Close connections gradually over 5 minutesabout 70 per second, with a reconnect hint
  4. All connections closed?
    YesExit cleanlyNoKeep draining until the grace period ends
  5. Next pod starts drainingonly 3 to 5 pods at a time

5 steps in order. Play them, or step through them one at a time.

4Making Clients Reconnect Politely and Sync Only the Delta

Gateways can crash without warning, so clients must also behave well on their own. A client that loses its connection waits a random time before reconnecting, using exponential backoff with full jitter: the first wait is anywhere between 0 and 1 second, then 0 to 2, 0 to 4, up to a cap of perhaps 60 seconds. If the server sends a retry-after hint, the client honours it. This spreads even a sudden crash of many pods over tens of seconds instead of one instant.

The sync itself must be small. Each client keeps a cursor per conversation, the last seq it has, and asks only for messages after it. Usually that is zero or a few messages, not the last 50 for every conversation. The server also caps sync batch sizes and lets clients sync lazily: recent conversations first, others when opened.

Java
// Client reconnect with exponential backoff and full jitter
int attempt = 0;
while (!connect()) {
long cap = Math.min(60_000, 1_000L << attempt); // 1 s, 2 s, 4 s ... capped at 60 s
long wait = Math.max(serverRetryAfterMs, ThreadLocalRandom.current().nextLong(cap));
sleep(wait); // e.g. 0.7 s, then 1.6 s, then 3.1 s
attempt++;
}
syncAfterCursors(recentConversationsFirst()); // only the delta, newest conversations first

5Protecting the Shared Dependencies

Even with gentle draining, the dependencies should protect themselves. Token validation can be done locally on the gateway by checking a signed token's signature and expiry, or cached for a few minutes, so reconnects do not each call the auth service. Sync requests are rate-limited per gateway, so a surge of reconnects queues on the gateway rather than flooding the message store.

Priorities matter most. Live delivery of new messages comes first; history sync comes second; presence fan-out comes last and is the first thing to shed, because a contact appearing online a minute late harms nobody. With separate queues or thread pools for each, a sync surge can never again delay live messages for everyone.

6Making the Session Registry Tolerate Churn

The session registry maps users to gateways. During a reconnect storm, entries change rapidly, and some point to gateways that have just closed. Each entry should carry a time to live refreshed by heartbeats, so stale entries expire on their own within, say, 30 seconds, without explicit cleanup.

And routing must tolerate a stale entry. If the message service sends a message to a gateway that no longer holds the user, the gateway reports that, and the message simply stays in the store, as for an offline user, possibly with a push notification. The client will fetch it on reconnect through its cursor. Nothing fails, and nothing is lost.

7Proving the Fix

Finally we prove it. A reconnect-storm load test drops the connections of the largest failure domain at once, such as a whole zone, a third of all clients, and measures delivery latency during recovery. We also alert on reconnect rate and on the depth of the sync queue, so an unusual storm, from a deploy, a crash or a network event, is visible in seconds.

8Follow-up questions

Why do the clients reconnect at the same moment even after a crash?

Because they all detect the lost connection within the same second and, without jitter, all retry immediately or after the same fixed delay. Jitter is what breaks that synchronisation; without it, retries stay clustered and each wave hits the platform together.

Could the gateways hand over connections without disconnecting clients?

Not for a WebSocket over TCP in general; a connection belongs to the process holding it. What we can do is make the handover invisible: tell the client to reconnect, let it open the new connection before closing the old one, and resume from its cursor. Some clients support this make-before-break pattern, which removes even the brief gap in delivery.

Why not simply add more gateway pods during deploys?

More gateways would hold the connections, but the expensive part is the work each reconnect causes in auth, the registry and the message store. Spreading reconnects over time and making each one cheap addresses the cause; extra gateways only address the smallest part of the cost.

9Conclusion

In this answer, we saw that a gateway deploy became a platform-wide incident because each reconnect triggers a handshake, a token check, registry and presence writes and a history sync, and 600,000 of them at once overwhelmed every shared dependency. Gentle draining with smaller batches, clients that back off with jitter and sync only the delta, cached token checks, rate limits and priority for live delivery, a registry with heartbeat expiry and a store-and-sync fallback, and a reconnect-storm test sized to a zone make restarts invisible to users.

What to say in the interviewAbout 80 seconds aloud

Open with

The deploy became an incident because a reconnect is not one request. Each one costs a TLS handshake, a token check, a session registry write, a presence update fanned out to contacts and a history sync for every active conversation.

Then, if they want more

Restarting 30 pods dropped 600,000 clients who all reconnected within seconds, so auth, the registry and the message store got many times their normal peak, and live delivery queued behind sync for everyone. I would fix it in four places.

Gateways drain gently: stop accepting new connections, then close existing ones gradually over several minutes with a reconnect hint, roll only a few pods at a time, and set the termination grace period longer than the drain.

Clients reconnect with exponential backoff and full jitter, honour a server retry-after, and sync only the delta after their per-conversation cursor, with the server capping batch sizes. Shared dependencies protect themselves: validate or cache tokens locally, rate-limit sync per gateway, shed presence first, and give live delivery priority over history sync.

And the session registry uses heartbeat TTLs, with messages to a stale gateway falling back to store and sync. Then I would prove it with a reconnect-storm test the size of a zone and alert on reconnect rate and sync queue depth.

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 why a routine gateway deploy became a platform-wide incident, and what you would...": https://scrivio-interview-library.netlify.app/architecture/system-design-problems/85f29811d2/