Linora

0306. Global rate limits: local token buckets with a periodic Postgres sync

Status: Accepted (2026-11-28). Supersedes the rate-limit part of 0301 (“per-replica buckets plus edge LB caps are enough”). Also covers SR-06 (trusted proxies), SR-10 (IPv6 keys, eviction) and SR-13 (lockout keys).

Context

API rate limits were per replica: with N replicas a client got N times the rate, and the brute-force lockout allowed N times the attempts. They must become global with a tiny hot-path cost, at 100k+ users per instance. The options:

  1. a Postgres write per request;
  2. a shared counter in the realtime tier;
  3. local buckets that sync periodically.

Decision

Option 3: local token buckets, synced through an UNLOGGED Postgres table every 250 ms.

Alternatives

Consequences