Skip to content
Low Level Design Mastery Logo
LowLevelDesign Mastery

Design a Chat Room Manager

Design a real-time messaging core with presence tracking and scalable notifications.

Design a chat room manager system that supports multiple chat rooms, user management, message queuing, and presence tracking. The system should handle concurrent users, notify users of new messages, manage user presence states (online/offline), and support different message routing strategies. The design should be extensible and thread-safe.

In this problem, you’ll design a system that acts as a broker between message senders and receivers while ensuring strict thread safety and low-latency delivery.


Design a backend for a chat service that supports multiple rooms, tracks user status, and ensures messages are routed correctly and safely.

Functional Requirements:

  • Room Management: Create, join, and leave multiple chat rooms.
  • Messaging: Send text messages to specific rooms and broadcast to members.
  • Presence Tracking: Monitor and display user status (Online, Away, Offline).
  • Message History: Retrieve a log of recent messages when joining a room.
  • Routing Strategies: Support different delivery rules (e.g., Broadcast vs. Direct Mentions).
  • Notifications: Inform members of new messages and presence changes in real-time.

Non-Functional Requirements:

  • High Concurrency: Handle thousands of simultaneous messages and joins/leaves.
  • Low Latency: Message delivery should feel instantaneous.
  • Thread Safety: Ensure room member lists and message queues aren’t corrupted by concurrent updates.
  • Scalability: Design the logic to be adaptable for a distributed environment.

The manager acts as a hub, coordinating between ChatRooms, Users, and NotificationServices.

Diagram
classDiagram
    class ChatRoom {
        -String id
        -List~User~ members
        -List~Message~ history
        -MessageRouter router
        +addMember(user)
        +broadcast(message)
    }
    
    class User {
        -String username
        -PresenceState status
        +receive(message)
        +updateStatus(newState)
    }
    
    class Message {
        -User sender
        -String content
        -long timestamp
    }

    class MessageRouter {
        <<interface>>
        +route(message, members)
    }

    ChatRoom "1" *-- "many" User
    ChatRoom --> MessageRouter
    User --> PresenceState

Diagram

If a room has 10,000 members, sending a message one-by-one in a single thread will be extremely slow.

Solution: Use Asynchronous Execution. The ChatRoom should put the message into a high-speed EventBus or ExecutorService. Worker threads then pick up the notification tasks and push them to users in parallel.

A user’s state affects how they receive messages (e.g., “Away” might suppress desktop notifications).

Solution: Use the State Pattern. Each User has a PresenceState object (OnlineState, AwayState). The receiveMessage() logic can change behavior based on which state object is currently active.

Users join and leave rooms constantly while messages are being broadcast.

Solution: Use Concurrent Collections. Use a CopyOnWriteArrayList or a ConcurrentHashMap for the member list. This allows the broadcast thread to iterate safely over the members even if someone leaves the room at the exact same moment.


By solving this problem, you’ll master:

  • Observer Pattern - Building real-time pub/sub systems.
  • Concurrency Control - Managing shared lists in high-traffic scenarios.
  • Event Routing - Implementing complex logic for message distribution.
  • State Management - Coordinating user lifecycles and presence.

Ready to see the full implementation? Open the interactive playground to access:

  • 🎯 Step-by-step guidance through the 8-step LLD approach
  • 📊 Interactive UML builder to visualize your design
  • 💻 Complete Code Solutions in Python, Java, C++, TypeScript, JavaScript, C#
  • 🤖 AI-powered review of your design and code

After mastering the Chat Room Manager, try these similar problems: