The Real Fullstack

Design a Rate Limiter

The limit is 100 per minute. Why did one API key make 800 calls in the first minute after the launch?

シニアエンジニア10 分フローシミュレーターコード課題
redisapi-gatewayluakubernetes

この課題はまだ日本語に翻訳されていません。英語版を表示しています。

ミッション:Enforce ~100 requests per minute per key across all instances, then decide how the limiter behaves when its shared store goes down.背景 · 学習目標 ▾

Tallow Cloud's public API runs on 4 instances behind a load balancer, each with an in-memory fixed-window limiter. A partner's buggy script hammered the API at a window boundary, and every instance counted only its own share.

ミッション: Enforce ~100 requests per minute per key across all instances, then decide how the limiter behaves when its shared store goes down.

学習目標

  • Compare fixed windows, sliding windows and token buckets.
  • Share limiter state across instances atomically.
  • Choose fail-open vs fail-closed deliberately.
シミュレーションシミュレーション値

シミュレーションを実行すると出力が表示されます。

シミュレーションを実行
INCR rl:{user}:{minute}      # counter per calendar minuteEXPIRE rl:{user}:{minute} 60# 100 requests at 00:59 + 100 at 01:00 → both windows allow them: 200 in 2 seconds

簡略化

Worst-case admitted requests are computed analytically for one burst pattern. Real limiters also tolerate clock skew and network partitions. 教育用モデルです。数値は挙動を示すためのもので、ベンチマークではありません。

コンセプト

関連する課題

参考資料