Distributed rate limiter
A rate limiting service in Go that runs as one binary, speaks HTTP and gRPC, and keeps limiting sensibly even when its own dependencies fail.
The problem
Rate limiting looks simple until it is shared. Many service nodes have to agree on one limit per tenant and resource, rules change while traffic flows, and the store that holds the counts can fail. A limiter that fails open lets abuse through; one that fails closed takes the product down with it.
This service is a complete reference implementation of that problem, built to run on its own and integrate with any system.
What it does
- Stateless nodes. Any node can answer any request; limiter state is shared.
- Several algorithms per rule: token bucket, fixed window and sliding window.
- Hot rule updates. Rules are stored in a database, published through an outbox and propagated by pub/sub invalidation, with a full sync worker as a safety net. No restarts.
- Lock-free reads. Each node keeps rules in atomic snapshots, so the hot path never waits on a lock.
- Batch evaluation for high-throughput clients, and identical semantics over HTTP and gRPC.
Failing gracefully
When the shared store is unhealthy, nodes fall back to a local limiter. The fallback is ownership aware and scaled by region, so a cluster of nodes does not quietly multiply the limit by the number of nodes. A degrade controller moves the system between normal, degraded and emergency modes based on health signals, and exposes which mode it is in.
Operating it
The service ships with metrics, tracing, health and readiness endpoints, configuration by file, environment or flags, benchmarks, and a chaos testing harness. It runs as a single binary, in Docker, or with a local Compose setup.