This system implements ephemeral, TTL-based chat rooms using Redis as the primary datastore and WebSockets for real-time messaging.
All rooms, messages, and user memberships automatically expire after a configured TTL.
- Admin creates a chat room
- A Room ID is generated and shared with participants
- Users join the room using the Room ID (and optional password)
- WebSocket connection is established for real-time messaging
- TTL starts when admin starts chat or first message is sent
- When TTL expires, all room data is automatically deleted
- Admin – Creates and manages the room
- Client/User – Joins room and participates in chat
- Redis – Stores room metadata, messages, and members
- WebSocket Server – Handles real-time messaging
Endpoint
POST /createRoomRequest Body
{
"roomName": "string",
"password": "string"
}Response
{
"roomId": "string"
}- Room is created without TTL initially
- TTL starts when admin starts chat or sends first message
Endpoint
POST /joinRoomRequest Body
{
"roomId": "string",
"password": "string"
}Client-Side Session
{
"sessionId": "string",
"userId": "string"
}userIdis generated based on username or UUID- Stored in
localStorageto persist across reloads
Endpoint
/wsConnection Metadata
{
"sessionId": "string",
"userId": "string",
"socketId": "string"
}- All messages flow through WebSocket
- Server validates room existence and TTL
room:<roomId> → HASH
{
"admin": "adminId",
"roomName": "string",
"ttl": "time"
}TTL
EXPIRE room:<roomId> <ttl_in_seconds>
room:messages:<roomId> → LIST
Each entry:
{
"message": "string",
"timestamp": "DateTime",
"userId": "string"
}TTL
EXPIRE room:messages:<roomId> <ttl_in_seconds>
room:roomUser:<roomId> → SET
[userId1, userId2, userId3, ...]
TTL
EXPIRE room:roomUser:<roomId> <ttl_in_seconds>
-
TTL is not started at room creation
-
TTL starts when:
- Admin clicks Start Chat, OR
- First message is sent
-
All related keys share the same TTL
-
When TTL expires:
- Room metadata is deleted
- Messages are deleted
- User membership is deleted
- Room becomes inaccessible
DEL room:<roomId>
DEL room:messages:<roomId>
DEL room:roomUser:<roomId>
This immediately invalidates the room for all users.
userIdstored inlocalStorage- Allows session continuity across reloads
- No server-side authentication required (ephemeral design)
- ⚡ O(1) Redis access
- 🧹 Automatic cleanup via TTL
- 🔒 No permanent data storage
- 🚀 Real-time messaging with WebSockets
- 🧠 Simple, scalable, and stateless backend