Redis (Remote Dictionary Server) is an open-source, in-memory data store originally developed by Salvatore Sanfilippo in 2009. Unlike traditional databases that read from and write to disk, Redis stores all data in RAM, enabling response times in the microsecond range — approximately 10 microseconds for a simple read, compared to milliseconds for disk-based databases. This performance profile makes Redis the go-to solution for applications requiring extremely low latency, including Twitter, GitHub, Snapchat, Stack Overflow, and any platform with real-time features.
Redis Pub/Sub for Chat
Redis's publish/subscribe (pub/sub) system is particularly valuable for real-time chat. In a pub/sub model, message publishers send messages to named "channels" without knowing who will receive them; subscribers listen to channels and receive messages as they arrive. For a chat application, each chat session gets a unique channel: when User A sends a message, the server publishes it to the session's Redis channel; the server process handling User B's connection is subscribed to that channel and immediately receives and forwards the message to User B via WebSocket.
This architecture scales horizontally: multiple server instances can handle different WebSocket connections while sharing message state through Redis. A single Redis instance can handle over 1 million pub/sub operations per second, making it suitable for very high-traffic anonymous chat platforms without becoming a bottleneck.
Redis and Ephemeral State
For anonymous chat platforms, Redis's in-memory nature is a privacy feature as well as a performance one. Ephemeral session state — who is in the matchmaking queue, which session a user is in, temporary username assignments — is stored in Redis with short TTLs (time-to-live values). When a session ends or TTL expires, the data disappears from memory without requiring an explicit delete operation. Redis is not a persistent database by default — it can be configured for persistence, but in anonymous chat use cases, the default in-memory behavior ensures session data is genuinely temporary rather than persistently stored and later "deleted."