This is my submission for the Redis AI Challenge: Beyond the Cache.
What I Built
For this challenge, I built a full-featured, real-time chat application from the ground up using Node.js and Socket.IO, with Redis as the powerful engine driving all its core features. This project goes far beyond a simple demo and includes a polished user interface, a robust server architecture, and even a fun AI Bot persona.
The final application includes:
- ✅ Real-Time Messaging: Instant message delivery to all connected users.
- ✅ User Presence System: A live "Online Users" list that updates instantly.
- ✅ Persistent Message History: Chat history is saved and loaded seamlessly.
- ✅ Live "Typing..." Indicator: A classic chat feature to enhance user experience.
- ✅ AI Chatbot Persona: Users can talk to an interactive bot by starting a message with
@bot
. - ✅ Admin Controls: Buttons to clear chat history or perform a full server reset.
Demo
Please feel free to test the live application! Open it in a few different browser tabs to see all the real-time features in action. And don't forget to say hello to our AI Bot!
-
🔴 Live Demo:
https://youtu.be/JvSZ9KUW_5E
-
🔵 GitHub Repository:
https://github.com/diassynthesis/Redis-AI-Challenge---Beyond-the-Cache.git
How I Used Redis 8
Redis is the heart of this application. I used three distinct Redis data structures to build its most important features, demonstrating its power as a true multi-model database. This project was built and tested on Redis v8.
1. Redis Pub/Sub for Real-Time Messaging
To ensure messages were delivered instantly to all users, I used Redis's lightning-fast Pub/Sub mechanism. When a user sends a message, the server publishes it to a Redis channel. A dedicated client subscribed to this channel immediately receives the message and broadcasts it to all web clients. This creates a scalable and incredibly fast messaging backbone.
javascript
// Server: Publishing a new message to the Redis channel
await publisher.publish('chat_messages', JSON.stringify(messageObject));
// Server: The subscriber listens and broadcasts to all clients
await subscriber.subscribe('chat_messages', (message) => {
io.emit('chat message', JSON.parse(message));
});
2. Redis Lists for Durable Message History
A chat app isn't useful if messages disappear. I used a Redis List as a high-speed, capped-size database for chat messages. Every new message is added with LPUSH, and LTRIM keeps the list at the latest 100 messages. When a new user joins, LRANGE fetches this history instantly.
JavaScript
// Saving a message to the history list
await publisher.lPush('chat_history', messageJson);
await publisher.lTrim('chat_history', 0, 99);
3. Redis Sets for Live Presence Management
To accurately track who is online without duplicates, a Redis Set was the perfect tool. SADD adds a user when they connect, SREM removes them on disconnect, and SCARD provides an instant and accurate count of online users. This is a highly efficient and mathematically pure way to handle presence.
JavaScript
// Adding a new user to the online set
await publisher.sAdd('online_users', socket.id);
// Getting the total count instantly
const userCount = await publisher.sCard('online_users');
Development and AI Collaboration
This project was an incredible learning experience, made possible through a unique collaboration with an AI assistant. From the initial architecture to writing the final lines of code, I worked in partnership with the AI.
The most challenging and rewarding part of this journey was debugging. Together, we identified and solved several subtle but critical "race condition" bugs. This iterative process of testing, reporting, and implementing AI-suggested solutions was invaluable. It not only helped create a stable and resilient final application but also provided a deep, practical education in the complexities of real-time systems. This project is a testament to the power of human-AI collaboration in modern software development.
---
## Future Enhancements & To-Do
This project provides a solid foundation for a real-time chat application, but there are many exciting features that could be added in the future to make it even more powerful.
* **Implement Full-Text Search:** The next major feature would be to integrate **RediSearch**. This would allow users to perform fast, complex searches across the entire chat history, making it easy to find old messages and conversations.
* **Integrate a True AI Chatbot:** While the current `@bot` is a fun persona, a future version could integrate with a real Large Language Model (LLM) via an API. This would enable the bot to have intelligent conversations, answer user questions, or even provide real-time chat moderation.
* **Select the user or Users to whom we want to send a message. Actually the message is send to all connected users.
License
This project is licensed under the MIT License. You can find the full license text in the GitHub repository.
<!-- Don't forget to add a cover image (if you want). -->
<!-- Thanks for participating! -->
<!-- ⚠️ By submitting this entry, you agree to receive communications from Redis regarding products, services, events, and special offers. You can unsubscribe at any time. Your information will be handled in accordance with [Redis's Privacy Policy](https://redis.io/legal/privacy-policy/). -->
Top comments (0)