1B's phone → DNSgw.example.com ?
Look up the gateway
On launch, or after switching networks, the app resolves the gateway's name. The answer usually differs by region so the phone lands on a nearby site.
2DNS → B's phone203.0.113.17
An address comes back
With a short TTL, this is also where traffic gets moved off a site that's going down.
3B's phone → GatewaySYN
TCP three-way handshake
On a mobile network one round trip can take 50–100 ms. The round trips from here to the end of TLS are what you feel between opening the app and seeing new messages.
4Gateway → B's phoneSYN-ACK
TCP three-way handshake
The server sets aside buffers for the connection.
5B's phone → GatewayACK + ClientHello
Start TLS 1.3
The ClientHello already carries a key share, so TLS 1.3 finishes in a single round trip.
On the wire
ClientHello
supported_versions: TLS 1.3
key_share: x25519 <32 bytes>
alpn: h2
6Gateway → B's phoneServerHello … Finished
An encrypted channel exists
Both sides derive the same keys from the key shares. Everything after ServerHello, including the certificate, is already encrypted; the phone checks the certificate before trusting the channel.
7B's phone → GatewayHELLO token=…
Say who you are
The app sends the access token it got at login. Whether this rides on HTTP/2 streams, WebSocket or MQTT depends on the app; what matters is one long-lived connection that carries frames both ways.
On the wire
{
"op": "HELLO",
"token": "eyJhbGciOi…",
"device": "ios-2",
"cursor": { "c_8f2a": 1038 }
}
8Gateway → Authverify(token)
Check the token
Signature and expiry, and sometimes a revocation list.
9Auth → GatewayuserId=31337
Now we know who it is
Every frame on this connection is treated as coming from user 31337 from now on.
10Gatewayregister session
An address book for delivery
The gateway writes userId → (gateway, connection) to a shared store. Delivery looks here to decide which gateway to hand a message to.
On the wire
SET session:31337:ios-2 = gw-17/conn-88412 EX 300
11Gateway → B's phoneREADY
Ready
From here it's just frames in both directions.
12B's phone → GatewayPING
Go quiet and you get forgotten
Carrier NATs and middleboxes silently drop TCP connections that carry nothing for a while. So the app sends a tiny frame every few tens of seconds to few minutes. Shorter keeps the line alive; longer saves battery.
13Gateway → B's phonePONG
Still alive
The session entry's TTL gets extended here too.
14B's phone → GatewayPING
Wi-Fi just switched to LTE
A new IP address makes the old TCP connection useless. The OS may report that the network changed, but nothing reports the dead socket itself; the missing PONG is what proves it.
15B's phonewait, reconnect
Don't all come back at once
Wait 1 s, 2 s, 4 s… and add random jitter. Otherwise, when a gateway restarts, millions of phones reconnect in the same instant.
On the wire
delay = min(cap, base * 2^attempt) * random(0.5, 1.0)