WhatsApp System Design: Persistent Connections, Message Delivery, Offline Queues, and E2EE
This is a reference design for a WhatsApp-like messaging platform, grounded in public Meta engineering information—not a claim about WhatsApp's complete private backend topology.
Keep Persistent Client Connections
Realtime messaging works best when online clients maintain long-lived connections so servers can push new messages immediately. Meta has publicly described WhatsApp servers pushing messages to connected clients over persistent connections.
At scale, connection servers need efficient routing, heartbeats, reconnect handling, and ownership of which gateway currently holds each device connection.
Give Every Message a Stable ID
The sender should create or receive a stable message ID so retries do not create duplicate messages.
A useful lifecycle is:
created → accepted by server → delivered to device → read
Acknowledgements must be idempotent because mobile networks can reconnect and replay requests.
Queue for Offline Devices
If the recipient is offline, keep the encrypted message pending until an eligible device reconnects or retention policy expires.
Push notifications can wake/notify a mobile client, but the push channel should not become the authoritative message store.
E2EE Changes the Server Design
WhatsApp uses end-to-end encryption for personal messaging. The server's job is primarily routing/delivery of encrypted payloads while encryption keys and plaintext semantics remain at endpoints according to the protocol.
Multi-device support also means one account may have several independently connected devices and cryptographic identities.
Separate Media From Message Transport
Large images/videos/documents should not travel repeatedly through the same small-message path. Upload encrypted media to object/media storage, then send an encrypted reference/metadata message so recipients download the media separately.
Group Messaging
Group messages introduce fan-out. The system needs membership/version checks and efficient delivery to many recipient devices while preserving retries and per-device delivery state.
Do not require every recipient to be online before accepting the sender's message.
Final Takeaway
A WhatsApp-like architecture is built around persistent connections, idempotent message IDs, offline delivery, per-device state, separate media delivery, and end-to-end encryption as a first-class constraint. The server coordinates delivery; it should not depend on reading message plaintext to make the basic messaging system work.
References
BUILDING A DIGITAL PRODUCT?
Talk to Lofingo about modern web apps, high-performance software engineering, and production digital platforms.
EXPLORE SERVICES →