← All Research
ARTICLE · SYSTEMS SCHEDULING

Rate Limiting Is Not Enough: From Token Limits to Physical Resource Scheduling

Traditional rate limiters cap request volume while ignoring how long heavy jobs occupy real workers. Adaptive scheduling learns task durations and dispatches work according to each worker's estimated free time.

TAGS: Rate Limiting, Worker Scheduling, EWMA, Queueing Theory, Resource Management

Core Thesis

Traditional rate-limiting strategies such as Leaky Bucket and Slot Bucket manage API transaction volume in virtual space: they track and restrict tokens over time. This model falls apart for heavy, unpredictable, compute-bound tasks such as LLM generation or media processing. Rate limiters assume execution capacity is instantaneous, so they do not protect against worker-pool starvation, backpressure, or failures under real load. Robust systems need adaptive physical worker scheduling that accounts for execution concurrency and learns task durations online.

Article Structure Blueprint

1. Introduction: The Lie of the Green HTTP 200

  • The scenario: A gateway's Leaky Bucket rate limiter accepts requests within its configured limits, but concurrent, multi-second jobs cause downstream services to run out of memory, accumulate context-switching latency, and fail.
  • The diagnostic: Why did the limiter allow requests through without warning as the servers became overloaded?
  • The core insight: Rate limiting constrains volume but ignores execution time and physical concurrency.

2. Phase 1: The Classic Leaky Bucket (The Virtual Ideal)

  • How it works: Smooth bursts by spacing requests according to virtual token costs.
  • Why it looks fast on paper: Simulations show very low queue latency.
  • The fatal assumption: Starting a job is treated as equivalent to executing it instantly. Constant-rate admission can saturate a fixed worker pool when jobs run for seconds.

3. Phase 2: Slot Bucket Scheduling (The Discrete Compromise)

  • How it works: Groups execution costs into discrete time windows to bound peak capacity.
  • The trade-offs: Slot boundaries add quantization delays and exchange average latency for capacity limits in each time block.
  • Why it still fails in practice: The scheduler does not know whether work from a previous slot has physically finished. Ten 14-second jobs admitted in one 10-second slot can overlap with work in the next slot, creating latent backpressure.

4. Phase 3: The Adaptive Worker Horizon Scheduler (The Ground Reality)

  • Bridging the gap: Track the physical horizon of each worker thread or process.
  • Handling unpredictability with online EWMA: Learn runtimes for different job profiles as results arrive, accounting for stochastic output, dynamic token generation, and runtime effects.
  • Greedy horizon slotting: Assign each incoming job to the worker expected to become free earliest, reducing queue delay.

5. Evaluating the Latency Curves: Why Realism Beats Illusion

  • Visualizing the sweep: Compare the latency curves for Leaky Bucket, Slot Bucket, and the Adaptive Scheduler, including why the first two appear faster.
  • The illusion: Leaky Bucket looks faster because its model acts as if server capacity were unlimited.
  • The math of reality: M/M/c queueing models predict nonlinear latency growth as request rates approach the capacity of physical workers. The Adaptive Scheduler reflects that growth and exposes queueing pressure before the cluster fails.

6. Conclusion: The New Paradigm for Heavy APIs

  • Rate limiting is a gatekeeper; scheduling is an orchestrator.
  • For compute tasks that take meaningful time, ask when the next worker will be free, not only how many requests can be accepted.