Technology · Database

Redis

How Sifat Ali uses Redis as a Celery broker, a cache, a WebSocket channel layer and fast ephemeral storage in Django and FastAPI backends.

What is Redis?

Redis is an open-source, in-memory data store used as a cache, message broker and real-time data structure server. It offers strings, hashes, lists, sets, sorted sets and streams with very low latency, plus key expiry and publish/subscribe messaging.

Official site: redis.io

How I use Redis

  • Message broker for Celery background jobs
  • Caching expensive queries and API responses
  • Channel layer for WebSocket and real-time features
  • Rate limiting, locks and short-lived state

The fast layer of a Python backend

Redis does several quiet but essential jobs in the backends I build. It is the Celery broker that carries background tasks to workers, the cache in front of expensive queries, the channel layer that fans WebSocket messages out across processes, and the home of locks and rate limits.

I have used Celery with Redis for background processing in production Django backends, including systems with ASGI and WebSocket features, where Redis connects real-time events across multiple worker processes.

Rules of thumb

  • Keys get explicit TTLs unless there is a reason they should live forever
  • Anything that must survive a restart is written to PostgreSQL first
  • Cache invalidation is designed when the cache is added, not after a bug report

Articles about Redis

Frequently asked questions

Why does Celery need Redis?

Celery needs a message broker to pass tasks from your web app to worker processes. Redis is a popular, simple and fast broker, and it can also store task results. RabbitMQ is the main alternative.

Should Redis store important data?

Treat Redis as fast, ephemeral infrastructure, such as caches, queues, locks and session-like state. Data that must never be lost, like billing records, belongs in PostgreSQL. Redis persistence options exist, but the database should remain the system of record.