§01 context
A rate limiter inside one process can't enforce an API quota shared by several workers. valve gives those workers one budget, stored in Redis or Valkey, and queues outbound calls until there's room to send them.
It reads the provider's rate-limit headers and shares cooldowns across workers. A memory store supports single-process use, and the library has zero runtime or peer dependencies.
§02 hard parts
The hard parts
- 01
One budget across workers
Atomic Redis and Valkey scripts check and reserve capacity together, so workers can't independently spend the same quota. Rate calculations use the store's clock to keep decisions consistent across processes.
- 02
Listening to the provider
Retry-After and rate-limit headers update a shared cooldown. Every worker using that budget pauses before starting more calls, and the fetch wrapper can retry rate-limit responses after the pause.
- 03
Keeping queued work under control
Calls can carry a cost, priority, deadline and abort signal. Queue bounds and local concurrency limits keep a busy process from accepting more work than it can handle.
stack
- TypeScript
- Redis
- Valkey
- Lua
next →
projector-remote
A Go server that lives inside my projector and turns any phone into its remote.