Scrivio Interview library
DebuggingIntermediate6 min read · updated 13 November 2026

A search service runs 12 replicas across three zones behind a load balancer that retries a request on another backend when the connection is reset. At 03:12 all 12 replicas crash within 40 seconds; each log ends with java.lang.OutOfMemoryError: Java heap space while expanding a wildcard query.

The JVMs run with -XX:+ExitOnOutOfMemoryError. Why did redundancy give no protection here, and what changes stop one bad input from taking down the whole fleet?

Redundancy protects against independent failures, but here all 12 replicas ran the same code and received the same input, a common-mode failure, and the load balancer's retry carried one query of death from replica to replica until the fleet was down. We stop it by bounding the work one request may cause, such as wildcard expansions, result size and query length, rejecting oversized queries with a 4xx; by retrying at the edge only within a budget and blocking fingerprints of requests that were in flight when a backend died; and by limiting exposure with shuffle sharding, cells and staged deployments.

Why this question is asked

Twelve replicas in three zones is a solid design, and it failed completely in 40 seconds. That makes this a good interview question: it shows the limit of redundancy, and the cause is subtle enough that teams often blame the hardware or the JVM first. In this answer, we will recap what redundancy actually protects against, reconstruct how one request crashed every replica, and then go through the fixes in three places: inside the service, at the edge, and in how requests and deployments are spread across the fleet. We will finish with how to find the offending request while replicas keep restarting.

1A Quick Recap: What Redundancy Protects Against

Redundancy works when failures are independent: a host loses power, a disk fails, a zone loses its network. Each of those hits some replicas and leaves the rest running, so extra copies absorb the loss.

A common-mode failure is one cause that hits every copy at once, because every copy shares it. Identical code with the same bug, the same configuration, the same certificate expiring at the same second, or the same input. Here the shared cause was a query whose wildcard expansion, for example a pattern like a* over a large index, built a huge in-memory structure. Every replica had the same code path and the same heap size, so every replica would die on that query. -XX:+ExitOnOutOfMemoryError then made the JVM exit at once instead of limping on, which is a sensible setting, but it also meant each crash reset its connections immediately.

2How One Query Visited the Whole Fleet

The load balancer was configured to retry a request on another backend when the connection is reset. That rule is meant to hide a single dying host from the client. Here it did the opposite. The query reached replica 1, which ran out of memory and exited. The connection reset, so the balancer sent the same query to replica 2, which also exited, and so on. Each attempt took a few seconds, so 12 replicas were gone in about 40 seconds.

Step throughA query of death spreading through retries
ClientLoad balancerReplica 1Replica 2Replica 3
search q=a*
forward query
expands wildcard, OutOfMemoryError, JVM exits
connection reset
retry same query on next backend
OutOfMemoryError, exits, reset
retry again
OutOfMemoryError, exits, reset
error after the fleet is down

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

The retry rule turned one bad request into a fleet-wide outage.

Clients make it worse. When the balancer finally returns an error, a client retry loop sends the query again, and it hits replicas that have just restarted. So the fleet keeps crashing as fast as it comes back, and from the outside it looks like random instability rather than one bad request.

3Fix 1: Bound the Work of a Single Request

The root fix is inside the service. No single request should be able to use unbounded memory or CPU. For a search service that means limits on wildcard and prefix expansions, on the number of terms a query may produce, on query length, on result size and on how deep a client may page. Search engines expose such settings, for example a maximum on the number of clauses or expansions, and our own code must add the rest.

Java
@PostMapping("/search")
ResponseEntity<?> search(@RequestBody SearchRequest req) {
if (req.query().length() > 512) return ResponseEntity.badRequest().body("query too long"); // 400
int terms = index.countExpansions(req.query(), 10_001); // stops counting at the cap
if (terms > 10_000) return ResponseEntity.unprocessableEntity().body("query too broad"); // 422
return ResponseEntity.ok(index.search(req, Math.min(req.size(), 100))); // cap result size
}

Notice that a rejected query is a 4xx, a client error. That matters for the next fix: load balancers and well-behaved clients do not retry 4xx responses, so the bad query stops at the first replica instead of travelling. We also add tests that send the worst queries we can think of and check that each is rejected quickly with the heap intact.

4Fix 2: Contain It at the Edge

The retry rule needs to be narrower. Retrying is safe when the request never reached the application, for example the connection was refused, or when the request is idempotent and we stay within a retry budget, such as retries adding at most 10 percent to traffic. Retrying because the backend died while processing the request is exactly the case to treat with suspicion, because the request may be the reason it died.

A stronger defence is a poison-request filter. When a backend dies, the gateway records a fingerprint, such as a hash of the method, path and normalised body, of every request that was in flight on it. If the same fingerprint is in flight when a second backend dies, the gateway blocks that fingerprint for a while and returns an error immediately. One death is bad luck; two deaths with the same request in flight is a pattern.

5Fix 3: Limit Common-Mode Exposure

Even with limits, some unknown bug will slip through one day, so we limit how much of the fleet any one client or request can reach. Shuffle sharding assigns each client a small, random-looking subset of replicas, for example 2 of the 12. A client sending poison queries can only take down its own 2 replicas, and almost every other client shares at most one replica with it, so they keep being served. Cells take the same idea further: independent copies of the whole stack, each serving a slice of customers.

Deployments are the other common-mode risk. If every replica runs identical new code at once, a new bug hits all of them together. Deploying in waves, one zone or one cell at a time with a pause and automated checks between waves, means a bad version takes out a slice, not the fleet.

6Follow-up questions

How would you find the offending request quickly while every replica keeps restarting?

First, stop the cycle: turn off the connection-reset retry at the balancer and enable rate limits so replicas stay up long enough to inspect. Then look for what the crashing replicas had in common. Access logs written at request start, rather than at completion, show what each replica was handling when it died, and the request present in every final log is the suspect. If the JVM writes heap dumps on OOM with -XX:+HeapDumpOnOutOfMemoryError, the dump shows the giant structure and often the query string. Tracing with request ids works too, as long as spans are exported before the process exits.

Is ExitOnOutOfMemoryError the wrong setting then?

No. A JVM that has hit OutOfMemoryError is in an unknown state, so exiting and restarting is safer than continuing. The problem was not the exit; it was that nothing prevented the query or stopped it from spreading.

Why not just give the JVMs more heap?

A query whose expansion grows with the index will eventually exceed any heap. More memory moves the threshold; limits on the work per request remove it.

7Conclusion

In this answer, we saw that redundancy fails against common-mode causes: identical replicas with the same input die together, and a retry on connection reset carried one query of death through the whole fleet. We fixed it by bounding the work per request and rejecting oversized queries with a 4xx, narrowing retries and blocking fingerprints of requests that were in flight at a crash, and limiting exposure with shuffle sharding, cells and wave deployments.

What to say in the interviewAbout 90 seconds aloud

Open with

Redundancy only protects against independent failures, like a dead host or a lost zone. Here every replica ran the same code and got the same input, so this was a common-mode failure, and twelve copies of the same bug fail together.

Then, if they want more

The spread came from the load balancer's retry rule: the wildcard query made replica one run out of heap and exit, the connection reset, the balancer retried the same query on the next replica, and within 40 seconds it had visited all twelve. Client retry loops then keep crashing replicas as they restart.

The real fix is in the service: bound the work any single request can cause, with limits on wildcard expansions, number of terms, query length and result size, and reject queries over the limit with a 4xx, which balancers do not retry, plus tests for the worst queries.

At the edge, I would only retry requests that never reached the application, or idempotent ones within a retry budget, and record fingerprints of requests that were in flight when a backend died, so a request present at two crashes gets blocked.

And to limit common-mode exposure, I would use shuffle sharding or cells so one client's traffic reaches only a few replicas, and deploy new versions in waves so a new bug never hits every replica at once.

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 "The JVMs run with -XX:+ExitOnOutOfMemoryError. Why did redundancy give no protection...": https://scrivio-interview-library.netlify.app/architecture/high-availability/5a657558f7/