Durable Object RPC Rate Limit
A globally consistent token bucket rate limiter, one Durable Object per API key, consumed over native RPC rather than fetch: the fronting Worker calls take() and peek() directly on a stub from env.LIMITER.getByName(apiKey), so each key shards to its own strongly consistent bucket worldwide. Bucket state lives in DO SQLite and survives eviction, the schema is initialized inside blockConcurrencyWhile and refilled inside transactionSync, and refill is alarm driven: an alarm is armed only while the bucket is below capacity and goes quiet once full, so an idle key costs nothing. The Worker maps the RPC result to RateLimit-Limit, RateLimit-Remaining, RateLimit-Reset, and Retry-After headers. This is the accounting-correct counterpart to the eventually consistent Rate Limiting binding.
npx shadcn@latest add https://ui.aryank.space/r/durable-object-rpc-rate-limit.jsonInstalls from ui.aryank.space. To add it by hand, copy the files in Files below, or register the @compronents namespace via the docs.
One Durable Object per API key holds a strongly consistent token bucket in DO SQLite; the fronting Worker calls take() over RPC, and an exhausted bucket rejects until it refills.
@cloudflare/[email protected]