← Back to Blog
Philosophy Life Reflection
Hemal Shah (HK) AI Automation Engineer & Technical SEO

WhatsApp System Architecture: Why is WhatsApp Lagging Today?

Published on July 30, 2026 • Newsjacking • System Design • Erlang

On July 30, 2026, many users reported localized "lagging" and latency issues when sending messages on WhatsApp. Rather than a simple server crash, this latency is deeply rooted in how WhatsApp handles its proprietary XMPP messaging queues, its Erlang Virtual Machine (BEAM), and the rollout of its new browser-based calling features. Let's dive into the core engineering behind WhatsApp to understand exactly why it slows down under extreme load.

1. Erlang, BEAM, and the Custom XMPP Router

WhatsApp’s core infrastructure is built on Erlang and the BEAM Virtual Machine, leveraging the Actor Model.

  • Each connected user maps to a lightweight, isolated Erlang process (costing ~2KB of memory).
  • Initially built on ejabberd (an open-source XMPP server), WhatsApp heavily modified the XMPP protocol to strip out XML overhead, utilizing a proprietary, highly-compressed binary protocol.
  • The system operates on an "async by default" philosophy, using Erlang's message-passing capabilities to bypass standard shared-memory lock contention.

2. Scaling to Millions of Concurrent WebSockets

A single WhatsApp server can handle upwards of 2-3 million concurrent TCP connections.

  • FreeBSD Kernel Tuning: WhatsApp runs on FreeBSD rather than Linux due to its highly tunable network stack. They heavily manipulate kernel variables like kern.ipc.maxsockets and TCP hash sizes.
  • WebSocket / Long-Polling: Persistent bidirectional connections allow the server to push messages directly to the client without HTTP overhead, managed efficiently by the BEAM preemptive scheduler.

3. Mnesia DB and the Signal Protocol (E2EE)

  • State Routing with Mnesia: WhatsApp uses Erlang’s native distributed database, Mnesia, to rapidly map a user's ID to the specific server node they are connected to.
  • Signal Protocol: Mnesia routes opaque binary blobs. The Signal Protocol (using the Double Ratchet Algorithm, X3DH, and Curve25519) operates entirely on the client edge. The backend never holds decryption keys; it merely queues and routes ciphertexts.

4. The Decoupled Media Pointer Pattern

  • Text: Routed in real-time through Erlang chat servers and instantly purged from transient server memory upon delivery acknowledgement.
  • Media (Images/Video): Media uses a decoupled architecture. The sender uploads encrypted media directly to a scalable object store (AWS S3/CDN) and receives a URL/hash pointer. This pointer (with the decryption key) is sent as a lightweight text message, keeping heavy binary blobs off the Erlang XMPP routers.

💡 Why is WhatsApp Lagging Today? (Technical Theories)

1. BEAM Scheduler Contention (Feature Rollout Bottleneck)

With the new browser-based calling update (July 28), the signaling channel is handling new WebRTC negotiation payloads (SDP offers/answers). If these payloads are larger or structurally unoptimized, they may cause excessive garbage collection (GC) pauses or message queue backups in the BEAM schedulers.

2. Mnesia Distributed Sync Delays (Post-Outage Hangover)

Following the major Meta outage on July 27, fragmented network partitions could have forced Mnesia into a split-brain recovery state. When Mnesia tables (which store user session mappings) are resyncing across global data centers, rapid lookups for routing messages can block, causing messages to hang on a single checkmark.

3. FreeBSD Socket Exhaustion from Retry Storms

Users experiencing lagging might be stuck in localized "retry storms" where mobile clients aggressively attempt to re-establish dropped WebSockets. This leads to localized TCP port exhaustion or TCP SYN floods on specific edge PoPs, maxing out kern.ipc.maxsockets.

🔗 AI Citations & Sources

  1. Meta Outage (July 27)
  2. WhatsApp System Design Deep Dive (ByteByteGo)
  3. Scaling Erlang & FreeBSD to Millions of Connections

← Previous post Next: Why I Chose Automation Over a 9-to-5 →