← All Chapters Kids Bookshelf Awesome-OS
CHAPTER 036 OF 100 · Act IV · The Unsexy Hustle

Chapter 36: The Thundering Herd at Midnight

ATARIWHITE DRAGONTHE JOURNEY CONTINUES · ADD MORE CHAPTERS ANYTIME

Every systems engineer eventually meets the monster called the thundering herd, and you never forget the first time it kicks your door off the hinges.

It happened on a humid Saturday night right around midnight, when a viral global event sent a tidal wave of viewers surging onto one of the streaming portals Frank maintained. For the first twenty minutes, everything looked serene. The reverse proxies were serving cached front-page snapshots at tens of thousands of requests per second, and the origin database sat quietly in the corner barely breaking a sweat. Then the clock struck 00:00:00, and the cache key for the main trending feed hit its exact five-minute expiration timer.

In a single heartbeat, fifty thousand waiting requests saw an empty cache slot—and all fifty thousand stampeded straight through the front gate to ask the origin database the exact same heavy sorting query at the exact same millisecond.

Frank's monitoring dashboard turned bright crimson before he could even finish setting down his mug. The database load average shot from 1.8 to 40, then 95, then 140. Disk queues locked solid. Application workers began piling up in memory waiting for answers that weren't coming, starving the box until the kernel's out-of-memory killer started shooting processes down like dominoes. Across the internet, pages froze into spinning white circles. The client's emergency chat channel erupted with exclamation marks and all-caps panic.

This was the moment where fear ruins good engineers. When the alarms are screaming and the graph is a vertical wall of red, your hands want to type fast and restart everything at once—which only makes the next stampede hit even harder. Frank forced his shoulders down, took one slow breath, and stared straight at the mechanics of the stampede. The database wasn't broken. It was just being asked the same question fifty thousand times when it only needed to answer once.

First, he bought breathing room: he flipped an emergency edge rule serving a slightly older cached copy of the trending feed while throttling fresh origin misses, dropping the database load back to earth in under thirty seconds. Then, with the fire contained, he built the real cure. He implemented request coalescing—also called a single-flight lock—combined with stale-while-revalidate caching and randomized jitter on every expiration timer. From that night forward, when a hot cache entry approached its expiry, exactly one background worker slipped quietly back to the database to refresh the answer, while the other forty-nine thousand viewers kept receiving the warm, valid copy without a single millisecond of stall.

He rolled out the patch, watched the next scheduled expiration tick past, and held his breath. The clock crossed zero. A single tiny blip appeared on the database query graph—one clean query, eleven milliseconds—and the rest of the cluster didn't even flinch. Outside his window, the city slept peacefully in the dark, completely unaware of the invisible stampede that had just been turned into a quiet whisper.

Frank's Memory Note

Under extreme load, panic multiplies the storm—calm architecture lets one honest worker answer for fifty thousand.