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.ioHow 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
- Article Deploying Django to Production on Ubuntu with Gunicorn, Nginx and systemd Step-by-step Django deployment on Ubuntu. Gunicorn with systemd socket activation, Nginx reverse proxy, static files, HTTPS with Certbot and Celery.
- Article How to Verify Stripe Webhook Signatures in Django (and Process Events Safely) A production pattern for Stripe webhooks in Django. Verify signatures on the raw body, store each event once, process idempotently with Celery and sync real state.
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.