The Quest Begins (The "Why")
I was building a simple rate limiter for a side‑project API. The idea was dumb‑simple: every time a request came in, I’d insert a row into a request_log table with the user ID and a timestamp, then count how many rows existed in the last minute to decide whether to allow or block the call.
At first, with a handful of requests per second, it felt like magic. Then the traffic started to creep up—first a few hundred, then a few thousand requests per second. The API latency began to climb, and the database CPU spiked. I opened the slow‑query log and saw the same offender over and over:
SELECT COUNT(*)
FROM request_log






