Requirements
1:1 and group chat, delivery and read receipts, presence, history, multi-device sync, push when offline. p99 delivery under 200 ms for online users.
Design
Key decisions
- Stateful gateways hold connections. A registry maps each user to their gateway node(s).
- Ordering per channel via a monotonically increasing sequence. Clients sort by
seqand detect gaps. - Idempotent sends: the client generates a
clientMsgId, and the server dedupes on it. - Storage: write-heavy and append-only, read by recency. Wide-column stores (Cassandra/ScyllaDB) partitioned by channel and time bucket.
- Sync: on reconnect, the client sends its last
seqper channel and the server returns the delta. - Large groups: fan-out on read instead of on write for channels with thousands of members.
Cheatsheet
The whole topic on one page. Click to open full screen.
Sources & further learning
Videos, courses, docs and books I recommend for this topic.
Related topics
Event-Driven Architecture
Services announce facts ("EntryPublished") and others react asynchronously — decoupling producers from consumers in time, space and knowledge.
Message Queues vs Event Streams
RabbitMQ/SQS-style queues distribute work; Kafka-style logs retain ordered events for many consumers and replay. Know which one your problem needs.
Sharding & Partitioning
Split data across nodes so storage and throughput scale horizontally — choosing shard keys, range vs hash, hot spots and rebalancing.