KatInterview

Build a Real-Time Team Chat System Architecture

System DesignModel answer
MediumModel answerSystem Designdistributed-systemsmessagingwebsockets

Last updated

Architect a scalable backend for workplace messaging with channels, direct messaging, history retrieval, and live delivery guarantees.

Problem

You need to architect the backend infrastructure for a workplace communication tool that enables teams to exchange messages instantly. Your system must support organized group discussions, private conversations between individuals, and the ability to review past exchanges.

Core Capabilities

Your design should provide:

  • Communication modes: Support both group discussion spaces (with public and restricted access) and private person-to-person messaging
  • Historical access: Allow users to retrieve and browse through previous messages with pagination support
  • Delivery guarantees: Ensure messages appear in the correct sequence and prevent duplicate displays
  • User awareness: Track whether participants are currently active and show which messages haven't been viewed yet

Performance Targets

  • Response time: Messages should reach active recipients within 200 milliseconds
  • Reliability: The messaging infrastructure should maintain 99.99% uptime, with no message loss even during temporary outages
  • Persistence: Successfully acknowledged messages must be durably stored

Expected Load

  • User base: 10 million people use the system daily
  • Message volume: Up to 50,000 messages traverse the system each second during busy periods
  • Group sizes: Typical users participate in 50 discussion groups; popular public groups may contain 100,000 members
  • Retention: Message archives must remain accessible for 5 years minimum

Deliverables

Your architecture should address:

  1. Interface contracts: Specify the primary endpoints for posting messages, retrieving conversation logs, and maintaining live connections
  2. Storage strategy: Select appropriate database technologies and define schemas for messages and group memberships, including partitioning approaches
  3. Live distribution: Explain how you'll manage persistent connections and route messages to recipients, especially in large groups
  4. Consistency mechanisms: Detail how you'll assign ordering to messages and prevent duplicates across the system

Hints

Hint 1

Consider separating durable message storage from ephemeral real-time delivery—they have different requirements and failure modes

Hint 2

For large groups, avoid writing copies per recipient; instead broadcast to connection servers and let them handle local fan-out

Hint 3

Use conversation-specific sequence numbers rather than global timestamps for ordering, and make them gap-detectable so clients can request missing messages