Designing Data-Intensive Applications
Case 3

Requirements and Constraints

Billions of users expect near-instant delivery, offline support, and privacy — on unreliable mobile networks.

Chat apps are connection-heavy. A user with one WebSocket can receive thousands of messages per day; the hard part is routing each message to the right connection set with minimal latency.

Diagram
In practice

WhatsApp famously runs Erlang/BEAM for massive connection counts. Message IDs are client-generated UUIDs so retries do not duplicate chats. Signal protocol handles E2E on devices.

WhatsApp at scale

When the receiver is offline, the server persists ciphertext and triggers APNs/FCM. On reconnect, the client syncs from its last acked sequence — no message loss without unbounded server memory.

Why these technologies?

Why Erlang/BEAM or similar (chat server)?

Millions of concurrent WebSocket connections per machine with preemptive scheduling and hot code reload. Node.js or Go work at smaller scale; BEAM is proven for telco-grade connection fan-in.

Why WebSocket (not HTTP polling)?

Bi-directional, low-overhead channel for instant delivery and typing indicators. Long polling wastes bandwidth; SSE is server→client only.

Why Durable message store (Cassandra / HBase / custom)?

Append-heavy writes at massive QPS with partition by chat_id. PostgreSQL struggles with write fan-out to billions of messages; the store optimizes for log-like access, not complex joins.

Why APNs / FCM (push gateway)?

Mobile OSes kill background apps — you cannot hold a WebSocket forever on a phone. Push wakes the app to pull pending messages when offline.

Why Redis (presence & typing)?

Ephemeral state with TTL: online status, typing indicators, connection routing hints. Loss on restart is acceptable — users reconnect. Wrong tool for durable message history.

Why Client-side E2E encryption (Signal protocol)?

Servers route ciphertext they cannot read — privacy promise. Trade-off: server-side search and moderation become harder.

Why Not Elasticsearch for every message?

Full-text search across all chats is expensive and often not a product requirement. WhatsApp optimizes delivery, not global search.

Key Takeaways
  • Delivery semantics: at-least-once with client-side deduplication by message ID.
  • Ordering: per-chat sequence numbers, not global total order.
  • Offline users: store-and-forward plus push notifications (APNs/FCM).
  • Groups fan out one write to many recipients — hotspot risk.
  • E2E encryption: servers route ciphertext; metadata still visible.
  • Low payload size favors custom protocols over verbose JSON.
messagingWebSocketpushE2E encryptionorderingRedisCassandra