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. 教学模型——数字用于说明行为,并非基准测试。

概念

相关挑战

参考资料