Urgent.News

What's breaking now, across thousands of outlets.

Tech

Your Rate Limiter Is a Stampede at the Window Boundary

The fixed window lets double the traffic through at the boundary, the distributed counter is an agreement problem in disguise, and the token bucket is the honest answer. The page came at 00:00:37 on a Tuesday. The database was falling over and the rate limiter's dashboard said everything was fine. Limit: 5,000 requests per minute. Busiest minute on record: 4,800. The limiter was telling the…

The fixed window rate limiter lets through double the traffic at the boundary, as the distributed counter is an agreement issue. The token bucket offers a more honest solution. The page was accessed at 00:00:37 on a Tuesday, but the database was struggling and the rate limiter's dashboard appeared fine. The limit was set to 5,000 requests per minute, with the busiest minute recording 4,800 requests.

The limiter was telling the truth, but the database was still failing. Around 23:59:59, two thousand requests landed in the last second of one window, and at 00:00:01, another two thousand requests arrived in the first second of the next window. Despite each window reporting under the limit, the database received four thousand eight hundred requests in roughly two seconds, highlighting the stampede.

This is not a bug in the limiter, but the design working as specified. Two common defaults can fail silently under load: no limiter at all or a fixed-window counter. The fixed-window counter, while simple and cheap, fails because the limit is enforced per window but experienced time as a continuum. The third option is to focus on bursts rather than averages, choosing the algorithm based on the worst second you can tolerate.

The three key questions to consider are: what guarantees does each algorithm provide at the boundary, how does it break when counters need to live on multiple machines, and what should clients do when no requests are allowed.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

CSS Container Style Queries: Let the Parent Set the Theme

Every design system eventually grows a modifier class problem. The card needs a dark version for the footer, a compact version for the sidebar, and a "highlighted" version for the pricing page.

  • Container style queries let parents set custom properties influencing descendants' styles.
  • @container rule with style function checks computed values of custom properties on ancestors.
  • Range queries added in 2023 enable styling based on numeric values, improving nuance.

More from Monday 12 October →