Redis for caching, rate limits, and queues
Redis for caching, rate limits, and queues
Redis is a server that keeps data structures in memory and runs one command at a time. That second property is the reason it shows up in nearly every backend: a counter incremented by INCR from fifty processes at once is still exactly right, because no two commands interleave. Relay uses that for three different jobs, and the same client, redis.asyncio, serves all of them.
The customer lookup runs on every chat turn and the answer rarely changes, so it gets cached. The /chat endpoint calls a paid model, so each API key gets a sliding-window rate limit. And escalation emails should not hold up a response, so they go on a queue for a worker. Three problems, one store, and a rule that applies to all three: every key gets an expiry, or Redis becomes a leak you cannot find.
Continue reading
Pro unlocks every video lesson, the full notes and runnable code across the Python with AI course, from the language itself to agents, MCP, Langfuse and deployment.