System Design HLD Example: Chat and Messaging Platform
Scenario context
A distributed chat system must balance low-latency delivery with strong per-conversation ordering.
π― System Scenario & Requirements
System Goal
A distributed chat system must balance low-latency delivery with strong per-conversation ordering.
Actors & Components
- Application or API tier
- Core service under design
- Operator or SRE observer
Functional Requirements
- A distributed chat system must balance low-latency delivery with strong per-conversation ordering.
- The architectural crux is the WebSocket Gateway for persistent stateful connections and Cassandra for append-heavy message storage partitioned by conversation.
- By using a Kafka-driven Fan-out model and Redis-based Presence heartbeats, the system can handle millions of concurrent users while ensuring noβ¦ This walkthrough focuses on Lessons Learned from Building Production Chatβ¦
Constraints & Assumptions
- The source does not isolate a separate failure mode.
- Limits that matter for the scenario are called out in the stage decisions above.
β‘ Execution Stages & Decision Trace
Stage 1 β End-to-end outcome
After working through the stages, you should be able to explain: - Hot Conversation Partitions Are Real and Painful.
- A Cassandra partition for a single high-traffic public server or channel β 10 million messages per day β concentrates all writes on one Cassandra node, creating a hot partition that degrades p99 write latency for thatβ¦
Deep Dive
Scenario context
A distributed chat system must balance low-latency delivery with strong per-conversation ordering. The architectural crux is the WebSocket Gateway for persistent stateful connections and Cassandra for append-heavy message storage partitioned by conversation. By using a Kafka-driven Fan-out model and Redis-based Presence heartbeats, the system can handle millions of concurrent users while ensuring noβ¦β¦
This walkthrough focuses on Scenario context.
Before making a design choice, clarify:
- A distributed chat system must balance low-latency delivery with strong per-conversation ordering.
- The architectural crux is the WebSocket Gateway for persistent stateful connections and Cassandra for append-heavy message storage partitioned by conversation.
- By using a Kafka-driven Fan-out model and Redis-based Presence heartbeats, the system can handle millions of concurrent users while ensuring noβ¦ This walkthrough focuses on Lessons Learned from Building Production Chatβ¦
Concepts in play: system-design-hld-architectures, btree-vs-lsmtree, caching, consistency-replication
Stage 1 β End-to-end outcome
- After working through the stages, you should be able to explain: - Hot Conversation Partitions Are Real and Painful.
- A Cassandra partition for a single high-traffic public server or channel β 10 million messages per day β concentrates all writes on one Cassandra node, creating a hot partition that degrades p99 write latency for thatβ¦
- The Gateway tier is stateful; everything behind it β Message Service, Fan-out Workers, Presence Service β must be stateless and independently scalable.
Observable outcome: - The Gateway tier is stateful; everything behind it β Message Service, Fan-out Workers, Presence Service β must be stateless and independently scalable.
End-to-end outcome
After working through the stages, you should be able to explain:
- Chat is a stateful problem (persistent WebSocket connections) that must be solved with a stateless mindset (horizontal scaling behind the gateway).
- The Gateway tier is stateful; everything behind it β Message Service, Fan-out Workers, Presence Service β must be stateless and independently scalable.
Alternatives considered
Alternatives considered
The source focuses on one primary design.
Failure and degraded modes
Failure and degraded modes
- Detection: The source does not isolate a separate failure mode.
- User or operator impact: The source does not isolate a separate failure mode.
Key learnings
- Chat is a stateful problem (persistent WebSocket connections) that must be solved with a stateless mindset (horizontal scaling behind the gateway).
- The Gateway tier is stateful; everything behind it β Message Service, Fan-out Workers, Presence Service β must be stateless and independently scalable.
- After working through the stages, you should be able to explain: - Hot Conversation Partitions Are Real and Painful.
