sydepsystem design atlas

Real-time Messaging (WhatsApp-style)

Persistent connections deliver messages instantly, with offline durability.

AdvancedSocialMessaging
SenderClientRecipientClientConnection GatewayNetworkingMessage RouterComputePresence StoreStorageOffline Delivery QueueMessagingMessage StoreStoragePush NotificationsMessaging

Clients hold a persistent connection to a gateway that routes messages to online recipients instantly and durably stores anything undelivered, with presence tracked separately so read receipts and online status stay fast.

When to use it

  • Sub-second delivery matters and polling for new messages is unacceptable
  • Messages must survive a recipient being offline and be delivered on reconnect

Trade-offs

  • Long-lived connections need sticky routing and careful connection-count capacity planning
  • Multi-device delivery (same account, several devices) adds fan-out complexity per message

Components used

Mobile AppAPI GatewayManaged App ServiceCacheMessage QueueDocument DatabaseNotification Service

How it works

  • Clients hold a persistent connection to a gateway, which tracks which server each user is attached to so messages can be routed to the right one.
  • Messages are persisted before delivery is attempted, so an offline recipient receives them on reconnect rather than losing them.
  • Delivery and read receipts are themselves messages flowing back through the same path.

Used in the wild

  • Consumer chat applications.
  • In-app support and direct messaging.
  • Any low-latency bidirectional communication between users.

Good to know

  • Connection state is the scaling problem, not message throughput. Millions of mostly idle connections consume memory and file descriptors continuously, which is why these gateways are frequently written in languages with cheap concurrency.
  • End-to-end encryption forces server-side search and multi-device sync to be redesigned entirely, because the server can no longer read the content it stores.