KatInterview

Design a Real-Time Messaging Platform with High-Velocity Group Analytics

System DesignModel answer
HardModel answerSystem Designsystem-designdistributed-systemswebsockets

Last updated

Architect a low-latency chat platform supporting 1:1 and large group channels, with real-time state synchronization and live streaming identification of high-activity groups.

Architect a global real-time messaging system supporting both 1:1 direct chats and large public/private channels. The platform needs to handle millions of simultaneous socket connections while maintaining strict low-latency guarantees.

A critical product requirement is real-time detection of high-velocity groups (the Top 100 "trending" or "hot" chat rooms based on recent activity), providing these stats via API without impacting core messaging throughput or primary database performance.

Key Requirements

Functional:

  1. Real-time message exchange for 1:1 and group chats (up to 10,000 members per room).
  2. Multi-device state synchronization and persistent offline backfills.
  3. Live delivery status and read receipts.
  4. Continuous identification of the Top 100 most active groups globally over a moving window (e.g., last 5 minutes).

Non-Functional:

  1. Latency: $p_{99} \le 200\text{ ms}$ for real-time delivery across connected devices globally.
  2. Scalability & Availability: Scale to tens of millions of concurrent connections; fault-tolerant under network partitions.
  3. Consistency: Per-channel strict message ordering guarantees; eventual cross-channel consistency.

Expected Scope

Your design should present:

  • Scale estimates and resource projections.
  • System architecture diagram and payload schemas.
  • Storage strategy (relational vs. wide-column vs. ephemeral state stores).
  • Connection state management for stateful WebSocket clusters.
  • Fan-out optimization for large groups ($N=10,000$).
  • Stream-processing pipeline for real-time Top-K analytics.

Hints

Hint 1

Decouple the ingestion/persistence layer from message delivery using an event streaming platform (e.g., Kafka) partitioned by conversation ID to maintain per-room message ordering.

Hint 2

Avoid publishing group messages to recipient sockets one-by-one; instead, perform local fan-out at the connection server level or leverage gateway-level pub/sub topics.

Hint 3

Use a stream processing framework (e.g., Apache Flink) with sliding windows and a Heavy-Hitters algorithm (Count-Min Sketch + Min-Heap) to maintain Top-K analytics off the primary storage hot path.