Chatify is a production-ready real-time chat application built using the MERN stack. It features instant messaging, reactions, OTP-based authentication, rate limiting, and a scalable architecture powered by Redis and Socket.IO.
- OTP via Phone: Integrated with Twilio.
- OTP via Email: Integrated with SendGrid.
- Secure auth via header: Implemented using JWT (JSON Web Tokens).
- Real-Time: 1-to-1 chat using Socket.IO.
- Reactions: Full emoji support for messages.
- Presence: Online/Offline status.
- Anti-Spam: Redis-based message rate limiting.
- Optimized Queries: MongoDB indexing for fast data retrieval.
- Scalability: Logic designed for scalable socket management. Implemented Cursor-based pagination.
- Security: Secure environment variable handling and middleware protection.
- Efficient message loading using cursor-based pagination.
- Loads messages in chunks instead of fetching entire chat history.
- Uses MongoDB
_idas a cursor for consistent ordering.
How it works:
- Messages are fetched in reverse chronological order.
- Each request returns:
messagesnextCursorhasMore
- Older messages are loaded when the user scrolls up.
Benefits:
- Faster initial load
- Reduced database load
- Scales well for long conversations
- File Handling: Image and file uploads via Multer.
| Layer | Technologies |
|---|---|
| Frontend | React.js, Zustand, Tailwind CSS, Socket.IO Client, Yup |
| Backend | Node.js, Express.js, Socket.IO, Redis, JWT, Cloudinary (Media Storage) |
| Database | MongoDB + Mongoose |
| Services | Twilio (Phone), SendGrid (Email), Upstash (Cloud Redis) |
Chatify uses a two-layer Redis-based rate limiting system to prevent spam while keeping the chat experience smooth.
Limits how frequently a user can send messages overall.
- Purpose: Prevents abuse, bot behavior, and accidental message floods
- Key:
msg:{senderID} - Example: Max 30 messages in 60 seconds per user
Applies stricter limits within a single conversation.
- Purpose: Stops spamming in individual chats without blocking the user globally
- Key:
msg:{senderId}:{conversationId} - Example: Max 15 messages in 10 seconds per user per conversation
- Built using Redis
INCR+EXPIRE - Executed before message persistence
- Avoids unnecessary MongoDB writes and file uploads
- Fine-grained abuse control
- High performance (in-memory operations)
- Scales efficiently for real-time messaging
Aansh Malhotra (Full Stack Developer)
Thank you for checking out Chatify! This project was built to demonstrate the power of real-time communication using the MERN stack and Redis.
If you have any questions or just want to connect, feel free to reach out.
Don't forget to give this project a β if you found it useful!