Warming up

All projects

Global Rate Limiter

A cluster-wide request quota that decides in nanoseconds, never overspends, and keeps serving when Redis goes down.

Year
2026
Status
Built
Stack
Go, Redis, Docker, ClickHouse
GoRedisDockerClickHouse

Context

Services running many replicas share one upstream API quota.

The problem

When each of N replicas enforces its own limit, the cluster can spend N times the upstream quota, causing 429s and overage bills.

Architecture

Three planes split by tempo: a hot path that is a single compare-and-swap on a local lease, an async control path that leases chunks of the global budget from a Redis ledger via an atomic Lua grant, and an async telemetry path batched to ClickHouse.

Decisions and trade-offs

Zero overspend as an invariant
Available budget plus every node's local lease never exceeds the limit, at every instant.
Fail bounded, not fail open
If Redis is lost, each node serves only a static slice of the limit, so the cluster total still can't exceed it.

Implementation

Lease refills overlap the hot path on a low-watermark trigger, and the whole system ships as one docker compose up.

Outcomes and lessons

All milestones built.