Skip to content
anythingai.space
Backend for AIintermediate11 min · 10 steps

Caching with Redis

Use Redis as a fast cache and coordination layer (session state, cached embeddings and answers, rate-limit counters, locks, queues), always with expiry and never as the only copy of important data.

model calls avoided/day0
saved/day$0
same question againAssistant APIModel / embedderslow, paid per callsame call ×1000Postgressession reads per turn
heavy workdatarequesterrorsignal
metrics are illustrative
1 / 10
ProblemStep 1 of 10

Paying again for answers you already have

Thousands of users ask near-identical questions: "How do I reset my VPN?". Each one embeds the same text and calls the model for the same answer. Every chat turn also reloads session state from Postgres, and every request needs a rate-limit counter that must be atomic and fast.

The database can do all of this, but slowly and expensively. The repeated work costs money and latency on every turn.

Lesson 11 of 20 in Backend for AI