A production-grade real-time chat application built with the MERN stack and Socket.io, featuring a custom 5-layer Redis architecture for scale, security, and performance.
🔗 Live Demo: https://chat-app-psi-teal.vercel.app/ 📦 Repo: github.com/AMANkumar0004
ChatApp is a full-stack real-time messaging platform designed to go beyond a typical CRUD chat app. It implements production-style patterns for rate limiting, session control, caching, and push notifications — all backed by a self-designed Redis layer.
| Layer | Tech |
|---|---|
| Frontend | React, Socket.io-client |
| Backend | Node.js, Express |
| Real-time | Socket.io |
| Database | MongoDB |
| Cache / Infra | Redis (Upstash) |
| Hosting | Vercel (frontend), Render (backend), Upstash (Redis) |
| Notifications | Web Push (VAPID) |
This is the core differentiator of the project — Redis isn't just used for caching, it powers five distinct subsystems:
-
Sliding Window Rate Limiting Protects API and socket endpoints from abuse using a sliding window counter implemented with Redis
INCR/EXPIRE. -
Single-Device Session Control Each user's active JWT session is tracked in Redis (
activeSession:userId), so logging in on a new device invalidates the old session and emits asession_kickedevent over the socket connection. -
Bloom Filters for Signup Availability Username/email availability checks are pre-filtered with a Redis-backed Bloom Filter before hitting MongoDB, cutting down unnecessary DB reads during signup.
-
Message Caching Recent conversation history is cached in Redis to reduce read load on MongoDB and speed up chat load times.
-
Web Push Notifications (VAPID) Offline users receive push notifications via the Web Push protocol, with subscription data managed through Redis.
- 🔐 JWT-based authentication with single active session per user
- 💬 Real-time 1:1 messaging via Socket.io
- 🟢 Online/offline presence tracking (Redis Hashes)
- 🚦 API rate limiting to prevent abuse
- 🔔 Push notifications for offline users
- ⚡ Cached message history for fast chat loading
- 🧩 Bloom filter–backed signup validation
Client (React)
│
├── REST API ──────► Express Server ──────► MongoDB (persistent data)
│ │
│ └────► Redis (Upstash)
│ ├── Rate limiting
│ ├── Session store
│ ├── Bloom filter
│ ├── Message cache
│ └── Push subscriptions
│
└── WebSocket ─────► Socket.io Server ──► Presence + real-time events
- Node.js (v18+)
- MongoDB instance (local or Atlas)
- Redis instance (Upstash recommended)
- VAPID keys for Web Push
# Clone the repo
git clone https://github.com/AMANkumar0004/chatapp.git
cd chatapp
# Install dependencies
cd server && npm install
cd ../client && npm installCreate a .env file in /server:
PORT=5000
MONGO_URI=your_mongodb_uri
JWT_SECRET=your_jwt_secret
REDIS_URL=your_upstash_redis_url
VAPID_PUBLIC_KEY=your_vapid_public_key
VAPID_PRIVATE_KEY=your_vapid_private_key
CLIENT_URL=http://localhost:3000# Start backend
cd server && npm run dev
# Start frontend
cd client && npm start| Service | Platform |
|---|---|
| Frontend | Vercel |
| Backend | Render |
| Redis | Upstash |
| Database | MongoDB Atlas |
- Group chat support
- Message read receipts
- End-to-end encryption
- Typing indicators
Aman Kumar GitHub: @AMANkumar0004 LinkedIn: aman-kumar-ak004
MIT