This project is a small backend example that shows how to:
- publish messages through an API,
- process them through Redis Pub/Sub,
- store them in MongoDB,
- read them back with pagination.
It is intentionally simple and meant for learning/demo purposes.
- Client sends
POST /publish/with a message. - API publishes that message to a Redis channel.
- Background listener receives the message from Redis.
- Listener saves the message into MongoDB.
- Client reads saved messages using
GET /messages/.
- FastAPI: HTTP API
- Redis: Pub/Sub transport
- MongoDB (Motor): message storage
POST /publish/- Body:
{"message":"hello world"} - Result: publishes a message to Redis
- Body:
GET /messages/?limit=10&cursor=<cursor>- Result: returns saved messages and
next_cursor
- Result: returns saved messages and
GET /health/- Result: basic Redis and Mongo connectivity check
- Create env file:
cp .env.dist .env- Install dependencies:
pip install -r requirements.txt- Run API server:
uvicorn main:app --reloadPublish:
curl -X POST http://127.0.0.1:8000/publish/ \
-H "Content-Type: application/json" \
-d '{"message":"hello world"}'Read messages:
curl "http://127.0.0.1:8000/messages/?limit=10"Health:
curl http://127.0.0.1:8000/health/Defined in .env.dist:
MONGODB_URIREDIS_HOSTREDIS_PORTREDIS_DBREDIS_CHANNELDEFAULT_MESSAGES_LIMITMAX_MESSAGES_LIMIT
pip install -r requirements-dev.txt
pytest -q