Autumn has switched off the Redis store that held its customers’ credit balances and replaced it with a set of Kafka-backed processes it calls balance workers. The Redis replacement cut median latency on usage tracking from 30 ms to 10 ms, and the system now handles 28% more check and track requests than before.
The company serves roughly 430 million API requests a day, and until this month most of them passed through Redis. That number is still growing quickly.
Why Redis stopped working for balances
Autumn picked Redis for two reasons: speed, and the ease of making a deduction atomic with Lua scripts. Each deduction was applied in Redis and flushed to Postgres later, so the database didn’t have to take a write on every request.
The gap between the Redis write and the flush was the problem. Race conditions could appear in several situations. Say a customer uses 30 credits and then receives a grant before the flush. The grant clears the cache and rebuilds it from Postgres, and the 30 credits of usage vanish.
That specific bug was fixed in September. Over four months the team shipped around 50 Redis-related fixes. At one point an engineer listed every race condition they could think of and doubted the list would ever end. Their conclusion: keeping more than one source of truth is flawed from the start.
The Sunday the cache disappeared
The deciding event came on Sunday 26 July. The Redis provider upgraded Autumn’s datastore to fix a CPU issue, and the new version had a bug that crashed both the primary and the replica. Autumn lost 40 GB of cached balances, and most API requests failed until the team recovered.
Restoring from a backup would have rolled balances back too far. So the team spent the rest of the day warming a fresh cache from Postgres. After that, a Redis replacement stopped being optional.
How the balance workers operate
The team load-tested several options before settling on balance workers. The design works like this:
- Each customer is hashed into one of a fixed set of Kafka partitions.
- One balance worker owns each partition at any given time.
- Check and track requests go to the worker that owns the customer’s partition.
- The worker holds balances in memory, calculates the deduction and writes the change to Kafka.
Postgres catches up in batches from the Kafka log. That makes Kafka the only source of truth, and the API doesn’t acknowledge a request until the Kafka commit succeeds.
Handling deploys and failures
Every deploy can shuffle partitions between workers. The incoming worker replays the log from the point where Postgres left off while the old worker keeps serving traffic. At takeover, the old worker is fenced off so it can’t write to Kafka any more. The new worker also warms the balances the old one held in memory, which now happens on every deploy without anyone giving up a weekend.
Kafka stalls and network jitter are covered too. If an append waits too long, the command goes to SQS and the API request is acknowledged. Autumn calls this the spool. It adds another layer of durability while keeping the single source of truth.
What the numbers show
Autumn compared a week of API traffic on Redis with a week on the balance workers after full rollout. The workers handled 28% more check and track requests. Track latency fell from 30 ms to 10 ms at the median and from 108 ms to 25 ms at the tail. Checks got slightly faster as well.
What the Redis replacement cost
This Redis replacement has trade-offs. Every customer now has one writer, so a single customer’s requests run one after another instead of concurrently. A large burst queues behind itself. Autumn accepted that on purpose, since per-customer ordering is the point, and overall latency is still well below the old Redis and Lua setup.
The log also sits in the hot path. If Kafka is slow, track acknowledgements are slow, which is why the spool exists. And there is more to operate: partition ownership, worker fencing, safe deploy handoffs and a committer that keeps Postgres current. A single Redis call never needed any of that. Autumn’s view is that the reliability gain outweighs the extra complexity.
What an ordered log makes possible
Because every balance change is now stored as an ordered event, other services can follow the log instead of polling Postgres or a cache. Autumn used that to build a service that sends usage events and webhooks, metering and enforcement inside a customer’s own cloud, and a complete history of how each balance changed over time. None of those were possible with balances sitting in a Redis cache.
The latency gain was welcome, but the engineer behind the project cares more about a different guarantee. When Autumn tells a customer it accepted a track, Kafka or SQS already holds the command, so there is something to replay if a worker dies. A single writer per customer also makes balance behavior predictable and easy to explain.
Source: Autumn