We got rid of Redis and made our API 4x faster

Our Redis write-behind cache kept losing writes, so we replaced it with an ordered log and one writer per customer. Track p99 went from 108 ms to 25 ms.

Owen · 25 Nov 2026 · 5 min read

This month, we switched off the Redis store that held our credit balances. We handle roughly 430 million API requests a day at Autumn (a number that is growing quickly). And until this month, the majority of them went through Redis. We spent quite a lot of time fixing bugs in that setup. What convinced us to make the move was spending a Sunday rebuilding a cache that had been inadvertently deleted by our Redis provider.

How we ended up here

Redis was originally chosen because of how fast it is, and how easy it is to make deduction atomic with Lua. The deduction would be applied in Redis and flushed to Postgres later. This gave us fast writes without updating Postgres on every request.

The problem was that during this window between Redis apply and flush to the db, race conditions are possible in multiple scenarios. For example, a customer uses 30 credits and then gets a grant before the flush. A grant would clear the cache and rebuild from Postgres meaning that usage of 30 credits would be lost.

Both end on 150. It should be 120: 30 credits were used and never charged.flushednothing to flushuse 30 creditsadd 50 creditsRedis150only in Redis−30lostPostgres150+0 writtenshould be 120 · 30 never charged

We fixed this case in September. In 4 months we shipped around 50 Redis-related fixes. At one point I had scoped out every possible race condition and upon seeing how many there were, it was hard to see myself ever getting to the end of the list. Having more than one source of truth is fundamentally flawed.

The Sunday we lost the cache

On Sunday 26 July, our Redis provider upgraded our datastore to fix a CPU issue. The new version had a bug and the primary and replica both crashed. Because of this we lost 40 GB of cached balances and most of our API requests failed until we could resolve this.

The rest of the day was spent warming a fresh cache from Postgres as using a backup would've rolled balances back too far.

After this, and seeing the list of possible race conditions, we understood we had to rip out Redis.

Building the balance workers

The solution that was agreed upon after a lot of discussion and load testing a few options was a set of processes we call 'balance workers'. How this works is:

  • Each customer is hashed into one of a set of Kafka partitions
  • One balance worker 'owns' each partition at a time
  • When the API gets a check or track request, it sends it to the worker that owns the customer partition
  • The worker keeps the customer's balances in memory, works out the deduction and then writes the mutation to Kafka
EdgeAPI serversBalance workersKafka logPostgresLoadbalancerW1W2W3W4W5W6W7W8W9W10W11W12+280 writtencatches upin batches

Postgres catches up in batches from the Kafka log, therefore Kafka becomes the sole source of truth (acknowledges aren't returned from the API until the Kafka commit is successful).

What happens if a worker goes away

Every deploy can move partitions around, so when this happens the incoming worker replays the Kafka log from where Postgres left off while the existing worker is still serving. On takeover we fence off the old worker so it can't keep writing to Kafka. The new worker also warms the balances the old worker had in its own memory (which happens on every deploy, and doesn't need the full team spending a Sunday to do).

The balance worker design also gracefully handles network jitter to Kafka, or general Kafka stalls. If an append to the log is waiting after a certain amount of time, we send the command to SQS and acknowledge the API request. This is called the spool and adds another layer of durability while retaining the single source of truth design.

Every partition has exactly one owner. Kill a worker or stall Kafka to see what happens.API servers503 · retry200 OKSQS spool0emptyWorker 1restartingp1p2p3Worker 2restartingp4p5p6Worker 3restartingp7p8p9Worker 4restartingp10p11p12Worker 5restartingp13p14p15Worker 6restartingp16p17p18Kafka logslow · waiting 0 msp1p2p3p4p5p6p7p8p9p10p11p12p13p14p15p16p17p18
All healthy

How it performed

A comparison of a week of API traffic on Redis and the balance workers after full rollout.

MetricRedis + Lua (14–21 Sep)Balance workers (13–20 Nov)Change
Track p5030 ms10 ms3× faster
Track p99108 ms25 ms4.3× faster
Check p5011 ms3 ms3.7× faster
Check p9977 ms54 ms1.4× faster
Busiest second of tracks5,3937,54840% more
Check + track requests that week1.8B2.3B28% more

The workers handled 28% more check and track requests, and track latency dropped from 30 ms → 10 ms at the median and 108 ms → 25 ms at the tail. Checks also got slightly faster.

What it cost

This architecture isn't a complete win - we had to give up a few things. Now that every customer has a single writer, each customer's requests are handled one after another rather than concurrently. So if a customer sends a massive burst, it queues behind itself. This is a deliberate trade as ordering per customer is the whole point, and overall latency is still well below the Redis + Lua setup.

The log is now in the hot path - we don't acknowledge tracks until Kafka (or the spool) has it, so if Kafka is slow then track accepts are slow. That's why I built the spool.

There is more to run - partition ownership, worker fencing, safe deploy handoffs and a committer that keeps Postgres caught up from the log are all mechanisms a single Redis call never needed. This is more complex to operate, but the robustness and reliability more than pays for it.

What it opened up

Now that every balance change is saved as an ordered log of events, other services are able to follow it rather than simply reading from Postgres or from a cache. This enabled us to build a service for sending usage events and webhooks off the back of the log, metering/enforcing usage within a customers own cloud, and a full history of how each customer's balance changed over time. None of these would've been possible with balances sitting in a Redis cache.

Looking back

The latency improvement was great to see but the change I care about most is what now happens when we tell a customer we have accepted a track. Kafka or SQS has the command, so we have something to replay that we can't lose on worker death. Giving every customer a single writer made the behaviour of balances predictable and easy to explain.

Autumn is drop-in billing for AI companies.