Why your Cache won't save you from a "Thundering Herd" ๐Ÿ‚

์ž‘์„ฑ์ž

์นดํ…Œ๊ณ ๋ฆฌ:

โ† ํ”ผ๋“œ๋กœ
DEV Community ยท Pratik ยท 2026-07-23 ๊ฐœ๋ฐœ(SW)

Pratik

We’ve all been there: you add Redis, and your latency drops. But have you planned for the Thundering Herd?
The Problem A Thundering Herd occurs when a massive, synchronized search of processes or user requests hits a backend resource at once.
The Pseudo-Code Risk Most of us write logic like this:

let data = await cache.get(key);
if (!data) {
data = await db.query(query); // The Bottleneck!
await cache.set(key, data);
}
return data;

If 100k users hit this code at the same time while the cache is empty, you don’t get one DB queryโ€Š-โ€Šyou get 100,000 concurrent DB queries. This causes latency spikes, cascading failures, and potential total system downtime.
How to Fix It (The Senior Dev Way)
Distributed Locks: Only the request that grabs the lock can hit the DB.
Jitter: Never let your services retry at the same time. Add a few seconds of randomness to “spread” the load.
Single In-Flight: Use request coalescing to merge 1,000 identical requests into 1 single database call.
Early Re-caching: Don’t wait for the cache to expire. Use a background process to refresh the data before it hits the TTL (Time to Live).

Real-world examples include:
Flash Sales: Millions clicking “Buy Now” at 12:00 PM.
Home Page Banners: When a global banner expires, every visitor triggers a cache miss at once.
Service Reboots: Hundreds of services trying to build connection pools the moment a DB comes back online.

How do you handle high-concurrency at your job? Let’s discuss in the comments! ๐Ÿ‘‡

์›๋ฌธ์—์„œ ๊ณ„์† โ†—

์ถ”์ถœ ๋ณธ๋ฌธ ยท ์ถœ์ฒ˜: dev.to ยท https://dev.to/pratik_12b3f8bf3b50e48bae/why-your-cache-wont-save-you-from-a-thundering-herd-2482

์ฝ”๋ฉ˜ํŠธ

๋‹ต๊ธ€ ๋‚จ๊ธฐ๊ธฐ

์ด๋ฉ”์ผ ์ฃผ์†Œ๋Š” ๊ณต๊ฐœ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ•„์ˆ˜ ํ•„๋“œ๋Š” *๋กœ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค