Hi DEV Community! π
I'm Geetansh Garg, a Senior Software Engineer passionate about scalable backend systems, clean architecture, and real-world problem solving. This is my first post here, and I wanted to kick things off by sharing one of the most exciting problems Iβve been working on lately.
π§© The Problem
We needed to deliver real-time notifications to users in a FastAPI-based product. But it wasnβt just about sending messages β we had to handle:
- Scalable delivery (thousands of users)
- Persistence (so no message is lost)
- Unread tracking
- Internationalization (i18n)
- Prioritization & retries
The traditional Redis Pub/Sub model just didnβt cut it β messages would be lost if a user was offline. So we decided to re-architect using Redis Streams for reliable and replayable messaging.
π οΈ The Stack
- FastAPI: Async Python framework for APIs and WebSockets
- Redis Streams: Durable, ordered messaging system
- PostgreSQL: To store notification history and unread status
- WebSockets: For pushing updates in real-time to the user
- Pydantic & SQLAlchemy: For models and data validation
- Docker + AWS Lambda (future): For production-ready deployment
π How It Works
- A notification is created (user action, cron job, webhook, etc.)
- It's pushed into a Redis Stream with metadata like
user_id
,priority
,lang
, etc. - A Redis Stream consumer reads it, stores it in PostgreSQL, and pushes to the WebSocket server.
- If the user is connected β great, they get it instantly!
- If not, itβs stored, marked as unread, and delivered when they come back online.
β¨ Key Highlights
- β Message durability with Redis Streams
- π Replay logic in consumer to handle restarts
- π Multi-language templates per user
- π Secure WebSocket authentication using JWT and
x-api-key
- π¬ Push fallback logic coming soon (Slack/Email integration)
π What's Next?
Iβm looking to open-source this soon and write detailed breakdowns of:
- Redis Streams vs Pub/Sub for real-time systems
- Notification retry and backoff strategies
- WebSocket gateway with reconnect handling
π¬ Letβs Connect!
Have you built similar real-time systems? Or explored Redis Streams for production workloads?
Letβs connect, geek out, and share learnings!
Also, Iβm open to feedback β especially since this is my first post π
Top comments (0)