I recently built a complete Flask-Celery-Redis stack using Docker and Docker Compose. This setup is widely used in real-world web applications where background task processing is essential — for example, sending emails, processing uploads, or long-running API calls.
Stack Overview
- Flask: Python web framework for handling HTTP requests.
- Celery: A distributed task queue to run background jobs.
- Redis: An in-memory data store used by Celery as a message broker.
- Docker: Containerized all services and orchestrated them using Docker Compose.
What I Built
I created a small Flask app with a route that triggers a background task — a simple sleep
function to simulate long processing. Celery picks up the task and processes it asynchronously, and Redis handles the message queue.
Folder Structure
flask-celery-redis/
├── app/
│ ├── __init__.py
│ ├── tasks.py
│ └── views.py
├── requirements.txt
├── docker-compose.yml
├── Dockerfile
What I Learned
- How to decouple long-running tasks from the main app flow using Celery.
- How to define and connect multi-container environments using Docker Compose.
- How Redis serves as a reliable and fast broker for Celery.
- Importance of defining persistent volumes and networking in Docker Compose.
Challenges I Faced
-
Task not executing? I learned the hard way that Celery must run in a separate container and explicitly point to Redis in the correct Docker network format (e.g.,
redis://redis:6379/0
). - Flask not communicating with Celery? Fixed it by ensuring both services were on the same Docker Compose network.
Code & Demo
I founf the full source code on GitHub:
👉 GitHub Repository
Final Thoughts
This project gave me real-world insight into scalable architecture and asynchronous processing. It’s a foundation I now use in other Dockerized applications like Django, monitoring stacks, and even DevSecOps pipelines.
If you found this helpful or want to collaborate, connect with me on LinkedIn or check out more projects on my GitHub.