All jobs / Backend developer / Performance

Backend developer interview question · 3–5 years

The interviewer asks: “The cache expires and 2,000 requests hit the database at once. How do you prevent that?” Strongest answer?

The strongest answer

Stampede control: single-flight / lock around the rebuild, jittered TTLs, and a stale-while-revalidate window so only one request (or a small set) refills. Don't let every waiter run the same query.

Why it works

Exactly. The thundering herd is a known pattern. Jitter plus a rebuild lock is the standard fix; serving stale briefly is allowed if the product can live with it.

What a good answer covers

Answers that fall short

Who gets asked this

More Performance questions