Rate-limiting per-user API keys without a queue

Token buckets in Postgres, no Redis, and a hot-key strategy that doesn't pretend hot keys won't exist.

Amy Team1 min read

Every rate-limit blog post says "use Redis." Most products don't have a Redis. We didn't either, so we asked whether Postgres alone could carry the load — and the answer was, comfortably, yes.

A token-bucket row per user, an update ... returning for atomic decrement, and a sliding window cap to absorb burst skew. The hot-path is one round-trip; the worst-case is one round-trip; we never had to introduce a new datastore for a feature that's cheaper than the data it protects.

More in Amy Engineering

View all →

How is Amy's credit system

How we ship a credit-based ledger that survives partial failures, refunds, and webhook re-deliveries — without losing a single cent.

Henry Ng3 min read