What happens after you tap send

Sent, delivered, read.

You tap send, a bubble appears on someone else's screen, and a moment later yours says Read. Getting it there takes a fraction of a second. This is what travels between the phones and the servers in that time, one frame at a time.

Dinner at 7?

  1. SEND
  2. ACK seq=1042
  3. EVENT → B
  4. DELIVERED
  5. READ_RECEIPT
Timings are illustrative.

Chapter 0

The cast

Chat apps differ in the details, but the cast is almost always the same. A gateway holds an always-on connection to every phone. A messaging service puts messages in order and stores them. The OS push service wakes phones that aren’t connected. And an object store holds anything too big to send inline.

Every diagram on this page uses a made-up protocol. Real apps name their frames and fields differently, but they are solving the same problems. How specific apps do it is in Real apps.

How the pieces of a chat app connectPhone Aapp + local DBPhone Bapp + local DBGatewaymillions of connectionsMessaging serviceassigns seq, deliversStoragechat logAPNs / FCMOS pushObject store / CDNalways onwakes a sleeping phonefiles go direct
Thick lines stay open. Dashed lines are used only when needed.

Chapter 1 · 12 steps

From send to read

The easy case: A and B both have the app open. Order comes from a seq number the server assigns, never from anyone’s clock. And “delivered” and “read” travel as a position, “everything up to here”, not one receipt per message.

Sequence diagramA's phone, Gateway, Messaging, Storage, B's phoneSEND1SEND + userId2APPEND seq=10423OK4ACK seq=10425EVENT seq=10426store, render7DELIVERED upTo=10428DELIVERED9READ upTo=104210read_pos[B]=104211READ_RECEIPT12

  1. 1A's phone → GatewaySEND

    The phone picks an ID before sending

    The moment you tap send, the app generates a clientMsgId, writes the message to its local database as "sending", and only then puts it on the wire. It goes over the connection the app opened at launch. No new TCP connection is made here.

    On the wire
    {
      "op": "SEND",
      "chatId": "c_8f2a",
      "clientMsgId": "a-7d1c9e",
      "type": "text",
      "body": "<ciphertext, 128 bytes>"
    }
  2. 2Gateway → MessagingSEND + userId

    The gateway doesn't look inside

    A gateway exists to hold open connections, lots of them, and it doesn't interpret what goes through. It stamps the frame with the user ID from the authenticated session and forwards it over an internal RPC.

    On the wire
    rpc Send {
      userId: 31337
      deviceId: "ios-2"
      frame: <SEND ...>
    }
  3. 3Messaging → StorageAPPEND seq=1042

    Number it per chat, then append

    The server assigns a sequence number that only ever goes up within this chat, and appends the message. That seq decides the order everyone sees. Phone clocks drift, so they never decide order.

    On the wire
    chat_id  | seq  | client_msg_id | sender | body
    c_8f2a   | 1042 | a-7d1c9e      | 31337  | ...
  4. 4Storage → MessagingOK

    Only after it's durable

    If the server acknowledged before the write was durable, a crash would lose a message the sender believes was sent. The ACK waits for the write.

  5. 5Messaging → A's phoneACK seq=1042

    Now it's "sent"

    From here on the diagram skips the gateway hop. A's phone finds its local row by clientMsgId and fills in the seq and server time. The bubble goes from "sending" to "sent".

    On the wire
    {
      "op": "ACK",
      "clientMsgId": "a-7d1c9e",
      "seq": 1042,
      "serverTime": 1795442112384
    }
  6. 6Messaging → B's phoneEVENT seq=1042

    Find B's connection and push

    Which gateway B is connected to comes from a session table (userId → gateway). If B is signed in on a phone and a laptop, both get it.

    On the wire
    {
      "op": "EVENT",
      "chatId": "c_8f2a",
      "seq": 1042,
      "from": 31337,
      "body": "<ciphertext>"
    }
  7. 7B's phonestore, render

    The recipient writes to disk first, too

    B saves the message locally before showing it, and moves its cursor (the latest seq it holds) to 1042. The next time it reconnects, that cursor tells the server where to resume.

  8. 8B's phone → MessagingDELIVERED upTo=1042

    "Got everything up to here"

    It's a position, not one ACK per message. If 50 messages arrive at once, one ACK covers them all.

  9. 9Messaging → A's phoneDELIVERED

    Delivered

    This is WhatsApp's second grey tick. LINE doesn't show this state at all, only "Read".

  10. 10B's phone → MessagingREAD upTo=1042

    B opens the chat

    Sent when the chat is actually on screen. It's also a position, so ten unread messages still cost one frame.

    On the wire
    { "op": "READ", "chatId": "c_8f2a", "upTo": 1042 }
  11. 11Messaging → Storageread_pos[B]=1042

    The read position lives on the server

    It's stored per user, not per device, so B's other devices clear their unread badge too.

  12. 12Messaging → A's phoneREAD_RECEIPT

    Read

    Every message A sent at or below 1042 is now marked read. Groups count this differently; that's in a later chapter.

Chapter 2 · 15 steps

The always-on connection

Plain HTTP only lets the server speak when it’s asked, so it has no way to push a message down to the phone. Chat apps work around that by opening one connection at launch and keeping it until the app goes away. Every round trip spent setting it up is time you spend staring at stale messages.

Discord documents its version: the server’s first frame (Hello, opcode 10) tells the client how often to heartbeat, and a client that drops can resume and have the events it missed replayed.

  1. 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.

  2. 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.

  3. 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.

  4. 4Gateway → B's phoneSYN-ACK

    TCP three-way handshake

    The server sets aside buffers for the connection.

  5. 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
  6. 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.

  7. 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 }
    }
  8. 8Gateway → Authverify(token)

    Check the token

    Signature and expiry, and sometimes a revocation list.

  9. 9Auth → GatewayuserId=31337

    Now we know who it is

    Every frame on this connection is treated as coming from user 31337 from now on.

  10. 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
  11. 11Gateway → B's phoneREADY

    Ready

    From here it's just frames in both directions.

  12. 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.

  13. 13Gateway → B's phonePONG

    Still alive

    The session entry's TTL gets extended here too.

  14. 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.

  15. 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)

Chapter 3 · 8 steps

Why it never arrives twice

On mobile, “sent it, never heard back” happens all the time. Resend naively and the other person gets the same message twice. The clientMsgId the phone picked before sending is what stops that.

Sequence diagramA's phone, Messaging, StorageSEND id=a-7d1c9e1INSERT seq=10422ACK seq=10423timeout4SEND id=a-7d1c9e5SELECT by clientMsgId6seq=10427ACK seq=10428

  1. 1A's phone → MessagingSEND id=a-7d1c9e

    A normal send

    Same as the first chapter so far.

  2. 2Messaging → StorageINSERT seq=1042

    The write succeeds

    As far as the server is concerned, the work is done.

  3. 3Messaging → A's phoneACK seq=1042

    Only the ACK goes missing

    An elevator, a tunnel. The message is stored; only the reply is lost. From A's side there's no way to tell "never arrived" from "reply lost".

  4. 4A's phonetimeout

    When in doubt, send again

    As long as it's in the outbox, the app resends after reconnecting. If it picked a new ID now, B would get the message twice.

  5. 5A's phone → MessagingSEND id=a-7d1c9e

    Resend with the same clientMsgId

    A retry reuses the original ID. That's what makes the send idempotent: doing it twice has the effect of doing it once.

  6. 6Messaging → StorageSELECT by clientMsgId

    Seen this before?

    A unique constraint on (chatId, sender, clientMsgId), or a dedup cache in front of it. The sender has to be part of the key: clientMsgId is picked by phones, and two phones can pick the same one.

    On the wire
    SELECT seq FROM messages
     WHERE chat_id = 'c_8f2a'
       AND sender = 31337
       AND client_msg_id = 'a-7d1c9e';
  7. 7Storage → Messagingseq=1042

    Yes

    It's already stored as 1042.

  8. 8Messaging → A's phoneACK seq=1042

    Same answer as the first time

    No second write, no second delivery, just the same ACK. To A it looks like the reply finally arrived. B has exactly one copy.

Chapter 4 · 9 steps

Delivered while the app is closed

Phone operating systems don’t let backgrounded apps keep talking to their servers; the battery wouldn’t last. To reach B with the app closed, the server borrows the notification channel that Apple and Google already keep open.

Sequence diagramA's phone, Messaging, APNs / FCM, B's phoneSEND1B not in sessions2push request3notification4extension runs5SYNC since=103861039 … 10427DELIVERED upTo=10428DELIVERED9

  1. 1A's phone → MessagingSEND

    B has closed the app

    Neither iOS nor Android lets a backgrounded app keep its own connection open for long. There is no line between B's phone and the server.

  2. 2MessagingB not in sessions

    Can't deliver directly

    The message is stored, so nothing is lost. B just needs to come and fetch it. The problem is getting B to come.

  3. 3Messaging → APNs / FCMpush request

    Ask the OS push service

    The app can't wake the phone itself, so it asks Apple (APNs) or Google (FCM). The OS keeps one shared connection for every app and the push arrives over that. Payloads are capped at 4 KB. An end-to-end encrypted app has no plaintext on the server, so the message text isn't in here.

    On the wire
    POST /3/device/<device-token>
    apns-push-type: alert
    {
      "aps": {
        "alert": { "title": "New message" },
        "mutable-content": 1
      },
      "chatId": "c_8f2a",
      "seq": 1042
    }
  4. 4APNs / FCM → B's phonenotification

    The OS receives it

    The app itself still isn't running.

  5. 5B's phoneextension runs

    Rewrite the notification

    With mutable-content set, iOS briefly runs the app's Notification Service Extension before showing anything. It can fetch and decrypt the message and replace "New message" with the real text.

  6. 6B's phone → MessagingSYNC since=1038

    Resume from the cursor

    The app reconnects (previous chapter) and sends its cursor. The server only has to return what comes after 1038. That's much harder to get wrong than "send me my unread messages".

    On the wire
    { "op": "SYNC", "cursor": { "c_8f2a": 1038 } }
  7. 7Messaging → B's phone1039 … 1042

    The gap arrives in one batch

    It's not just messages. Read receipts, unsends and membership changes sit in the same log. Apply them in order and the phone ends up in the same state as the server.

  8. 8B's phone → MessagingDELIVERED upTo=1042

    Got it up to here

    The cursor moves to 1042.

  9. 9Messaging → A's phoneDELIVERED

    A finds out too

    Right away if A is online, otherwise on A's next sync.

Chapter 5 · 10 steps

A letter the server can't read

TLS only protects the hop between phone and server; inside the server the message is plaintext. With end-to-end encryption, only the two phones hold a key that opens the body, and the server carries a sealed envelope.

Sequence diagramA's phone, Key server, Messaging, B's phonegenerate key pair1upload public key2B's public key?3pub_B, keyId=74ECDH → shared key5AES-GCM encrypt6SEND ct7EVENT ct8ECDH → decrypt9ratchet forward10

  1. 1B's phonegenerate key pair

    The private key never leaves the phone

    At install time the app generates an elliptic-curve key pair (Curve25519, say). The private key goes into the phone's secure storage and is never uploaded.

  2. 2B's phone → Key serverupload public key

    Only the public half is shared

    A public key is safe to show anyone. It's parked on the server for whoever wants to write to B.

    On the wire
    { "userId": 42, "keyId": 7, "pub": "Kq3…x25519 32 bytes" }
  3. 3A's phone → Key serverB's public key?

    The first message

    A fetches B's public key once and caches it.

  4. 4Key server → A's phonepub_B, keyId=7

    The key arrives

    A server that swapped in its own key here would be a man in the middle. That's why apps let you compare key fingerprints in person, and warn when a contact's key changes.

  5. 5A's phoneECDH → shared key

    Same key, never sent

    A combines its private key with B's public key (ECDH). B, combining its own private key with A's public key, gets exactly the same value. Run that through a key derivation function and you have a message key.

    On the wire
    shared = X25519(priv_A, pub_B)
    key    = KDF(shared, salt, "message")
  6. 6A's phoneAES-GCM encrypt

    Encrypt, with tamper detection

    AES-GCM produces an authentication tag along with the ciphertext. Flip one bit in transit and decryption fails.

    On the wire
    nonce = random(12)
    ct, tag = AES-256-GCM(key, nonce, plaintext, aad=header)
  7. 7A's phone → MessagingSEND ct

    A sealed envelope

    The server sees metadata: who, to whom, when, how big. It can't read the body.

    On the wire
    {
      "op": "SEND",
      "chatId": "c_8f2a",
      "keyIds": { "from": 3, "to": 7 },
      "nonce": "3tq…",
      "body": "9f1c…e0 (ciphertext + tag)"
    }
  8. 8Messaging → B's phoneEVENT ct

    Carried as is

    The server delivers it without understanding it.

  9. 9B's phoneECDH → decrypt

    B derives the same key

    B computes X25519(priv_B, pub_A), which equals what A computed, and decrypts with the same key. If the tag doesn't verify, nothing is shown.

  10. 10B's phoneratchet forward

    Protect the past

    Reuse one key forever and a single leak exposes every old message. Signal's Double Ratchet derives a new key per message and throws the old one away, so a leaked key can't read the past (forward secrecy).

Chapter 6 · 9 steps

Groups

A group looks like a 1:1 chat with more recipients. Once it gets big, two questions start to matter: where the copying happens, and how read receipts are counted.

Sequence diagramA's phone, Messaging, Storage, B's phone, C's phone, APNs / FCMSEND chat=g_room1APPEND seq=882ACK seq=883members(g_room)4EVENT seq=885EVENT seq=886push → D7READ upTo=888read by 19

  1. 1A's phone → MessagingSEND chat=g_room

    Send to a group

    A sends one message. The server decides who gets it.

  2. 2Messaging → StorageAPPEND seq=88

    Stored once

    Write once to the group's log and let everyone read it (fan-out on read). The alternative copies it into each member's inbox (fan-out on write): faster reads, but a 500-member group turns one message into 500 writes.

  3. 3Messaging → A's phoneACK seq=88

    Sent

    It doesn't wait for delivery to members.

  4. 4Messaging → Storagemembers(g_room)

    Who gets it

    Look up the members and their sessions. This usually goes onto a queue and a separate worker does the delivery.

  5. 5Messaging → B's phoneEVENT seq=88

    Online members get it now

    Pushed down B's connection.

  6. 6Messaging → C's phoneEVENT seq=88

    Online members get it now

    And C's.

  7. 7Messaging → APNs / FCMpush → D

    Offline members get a notification

    D isn't connected, so it's the OS push route from the earlier chapter. This is also where the server decides whether to batch notifications or skip a muted chat.

  8. 8B's phone → MessagingREAD upTo=88

    Counting readers

    Keep each member's read position and "read by N" for seq 88 is just the number of members with upTo ≥ 88.

  9. 9Messaging → A's phoneread by 1

    The count goes up

    A sees "Read by 1", and the number climbs as others open the chat. With E2EE there's a second problem: you don't want to encrypt the body once per member. WhatsApp gives each sender a "Sender Key", hands it to every member over their 1:1 encrypted sessions, and encrypts the body once. LINE uses a shared group key and regenerates it when membership changes.

Chapter 7 · 10 steps

Photos and video

Push a 20 MB video through the same pipe as text and every “ok” queued behind it waits. Big files take a different road; the message only says where to find them.

Sequence diagramA's phone, Media API, Object store, Messaging, B's phoneresize, encrypt1want to upload2signed URL3PUT blob4200 OK5SEND type=image6EVENT7GET objectId8blob9verify → decrypt10

  1. 1A's phoneresize, encrypt

    Processed on the phone first

    The app downsizes the image, makes a thumbnail, and encrypts it with a random key used for this file only.

    On the wire
    fileKey = random(32)
    blob    = AES-256-GCM(fileKey, image)
    digest  = SHA-256(blob)
  2. 2A's phone → Media APIwant to upload

    Ask for a place to put it

    Tell the server the size and type, get an upload target back.

  3. 3Media API → A's phonesigned URL

    Upload straight to storage

    Pushing several megabytes through the messaging servers would stall everyone's chats. Instead the app gets a short-lived signed URL and PUTs directly to storage.

    On the wire
    PUT https://blob.example.com/o/3f9a…
      ?X-Expires=600&X-Signature=…
  4. 4A's phone → Object storePUT blob

    Stored still encrypted

    Storage can't even tell it's an image.

  5. 5Object store → A's phone200 OK

    Uploaded

    Only now can the message itself go out.

  6. 6A's phone → MessagingSEND type=image

    The message is a claim ticket

    It carries where the file is and how to open it, not the file. fileKey is inside the end-to-end encrypted body.

    On the wire
    {
      "type": "image",
      "objectId": "3f9a…",
      "fileKey": "<inside E2EE body>",
      "sha256": "b1e4…",
      "thumb": "<tiny JPEG>",
      "w": 1179, "h": 2556
    }
  7. 7Messaging → B's phoneEVENT

    Thumbnail first

    B sees a blurry thumbnail straight away. The full file is fetched on tap, or automatically on Wi-Fi.

  8. 8B's phone → Object storeGET objectId

    Fetched from a nearby CDN

    A hundred group members opening the same photo puts no load on the messaging servers.

  9. 9Object store → B's phoneblob

    Encrypted bytes

    Even cached on the CDN, it's unreadable without the key.

  10. 10B's phoneverify → decrypt

    Check the hash before opening

    B checks the SHA-256 against the value in the message, then decrypts with fileKey. A mismatch means the file was swapped somewhere along the way.

Chapter 8

Try it

Both phones are yours. Take B offline and send, then bring it back. Switch on “Drop the next ACK”, send, then resend. The wire log underneath shows every frame the server sees.

A
Server
seqclientMsgIdfrombody

delivered up to: A=0 B=0 · read up to: A=0 B=0

B
Wire log
  1. Nothing on the wire yet. Send something.

Chapter 9

Real apps

Everything above is a composite. Here is what the apps themselves have published. A dash means we found no primary source, not that the feature is missing.

AppPhone ↔ serverEnd-to-end encryptionGroups
LINEIts own gateway, LEGY. SPDY from 2012, HTTP/2 today, moving to TLS 1.2 / 1.3.on by defaultLetter Sealing: ECDH over Curve25519, AES-256-GCM (v2).A shared group key, regenerated when members change.
WhatsAppNoise Pipes with Curve25519, AES-GCM and SHA-256.on by defaultBuilt on the Signal Protocol.Sender Keys, handed out over pairwise sessions. The server fans out.
Signal—on by defaultPQXDH key agreement (announced in 2023 to replace X3DH for new chats) and the Double Ratchet.—
iMessageGoes through APNs, which deletes it once delivered.on by defaultPQ3 (from iOS 17.4).—
Messenger—on by defaultSignal protocol. Rolled out as the default for personal chats starting December 2023.—
TelegramMTProto 2.0.opt-inOnly in Secret Chats, which you open separately: 1:1 and tied to one device. Regular chats are cloud chats.Group chats are cloud chats: client–server encryption, stored in the Telegram cloud.
DiscordGateway over secure WebSocket. The server's Hello (opcode 10) sets the heartbeat interval; a dropped client resumes and gets missed events replayed.partialText is not end-to-end encrypted. Since March 2026 every voice and video call uses DAVE, built on MLS; Stage channels are the one exception.—

LINE

  • Events are stored per account as "Operations", each with a revision number. Clients call fetchOperations(clientRev, count) over long polling; an empty result is 204 No Content.
  • Letter Sealing v2 is on by default for 1:1 and group chats when the clients support it. Sender and recipient IDs are not encrypted.
  • Message storage moved from Redis to HBase as volume grew, with Redis kept as a cache.

Sources:LINE Encryption Overview v2.2LINE Engineering: Adopting SPDY in LINELINE DEVDAY 2019: LINTLINE Engineering: LINE Storage

WhatsApp

  • Every linked device has its own identity key, and each message is encrypted separately for each device.
  • Attachments are encrypted with AES-256-CBC plus an HMAC-SHA256 and uploaded to a blob store.
  • The second check mark appears once the message reaches the recipient, and both turn blue once it has been read. In a group, each waits for every member. In a one-to-one chat, either person can turn read receipts off, and then the blue never comes.

Sources:WhatsApp Encryption OverviewWhatsApp Help: How to check read receipts

Chapter 10

Further reading