A lightweight WebSocket-based chat application built with Python and Redis. Messages sync instantly across multiple browser tabs and clients—no page refresh needed.
Opens two tabs. Type in one, see it appear in the other. That's it—simple real-time communication using WebSockets and Redis pub/sub.
The server handles bidirectional connections and broadcasts messages to all connected clients through Redis channels. Perfect for learning how WebSocket communication works or as a starting point for more complex chat features.
- Backend: Python (Flask/FastAPI)
- Real-time: WebSocket protocol
- Message Broker: Redis (pub/sub pattern)
- Frontend: HTML/CSS/JavaScript
Make sure you have these installed:
- Python 3.8+
- Redis server
Clone the repo:
git clone https://github.com/CodexAarogya/Realtime-ChatServer.git
cd Realtime-ChatServerInstall dependencies:
pip install -r requirements.txtStart Redis (if not already running):
redis-serverRun the server:
cd chatServer
python app.pyOpen your browser and go to http://localhost:8000/chat/
- Client opens a WebSocket connection to the server
- Server subscribes to a Redis channel for that client
- When a message is sent, it's published to the Redis channel
- Redis broadcasts the message to all subscribed clients
- Server pushes the message to connected WebSocket clients
This architecture lets you scale horizontally—multiple server instances can share the same Redis instance, and messages will still reach all clients.
Realtime-ChatServer/
├── chatServer/
│ ├── app.py # Main server file
│ ├── static/ # CSS, JS files
│ └── templates/ # HTML templates
├── requirements.txt
└── README.md
- ✅ Real-time bidirectional communication
- ✅ Multi-tab support (open multiple tabs, all stay in sync)
- ✅ Simple, clean UI
- ✅ Redis-backed message broadcasting
- ✅ Low latency message delivery
This is a foundation. Here's what could make it better:
- User authentication and unique usernames
- Chat rooms/channels
- Message persistence (store history in a database)
- Typing indicators
- Read receipts
- File/image sharing
- Better error handling and reconnection logic
Currently deployed on Vercel with Redis Cloud for the message broker. Works well for demos and small-scale usage.
For production deployments, consider:
- Setting up proper WebSocket load balancing
- Using a managed Redis service (Redis Cloud, AWS ElastiCache, etc.)
- Adding rate limiting and authentication
- Implementing proper logging and monitoring
- No message persistence yet—refresh the page and history is gone
- Single chat room (no support for multiple rooms)
- Minimal error handling
- No user identity management
Feel free to open an issue if you find bugs or have feature suggestions.
This is a learning project, but contributions are welcome. If you want to add features or fix issues:
- Fork the repo
- Create a feature branch (
git checkout -b feature/something-cool) - Commit your changes (
git commit -m 'Add something cool') - Push to the branch (
git push origin feature/something-cool) - Open a Pull Request
MIT License - feel free to use this however you want.
Built this as a weekend project to understand WebSocket communication and Redis pub/sub patterns better. If you're building something similar or have questions, feel free to reach out.
⭐ Star this repo if you found it helpful!