Try
↑ ↓ move↵ openesc close
In this lesson · topic 6 of 7
  1. 1. A message that must arrive once, in order
  2. 2. Requirements, numbers, API and data model
  3. 3. Break the network and watch delivery
  4. 4. Loss, resends and the order they create
  5. 5. Gateways, connections and crashes
  6. 6. Receipts, offline inboxes and presence
  7. 7. The chat system in review

Topic 6

Receipts, offline inboxes and presence

6 min read

Delivery and read receipts

Sent means the server stored the message and acknowledged the sender. Delivered means the recipient’s device acknowledged it. Read means the recipient opened the conversation.

A device sends the delivered ack for the same reason the server needs it. Without it the server cannot stop resending. A read receipt can carry a sequence number meaning “I have read up to here”. One receipt then covers every earlier message, and a lost receipt is repaired by the next one. Send it when the screen has shown the message, and batch it so you do not write for every line.

Receipts are small but numerous. Each message can cause two more. Store only the highest read number per user per conversation, not every receipt.

Offline delivery

A message for an offline user is stored first and delivered later. The write to the message store is the commitment. The push to the connection is an optimisation. If the user is offline, there is no push, and nothing is lost.

When the client reconnects it says what it has: “conversation 9, last sequence 41”. The server replies with everything after that, in order. This is the same range scan as history. The client needs no special offline logic, and the server needs no queue per user.

In the lab, going offline moved the 99th percentile delay from 3 ticksmeasured with nobody offline to 24 ticksmeasured at 5 percent a tick. The median stayed at 0 ticksmeasured. The delay is the time the user was away, which is not a fault.

A phone with the app closed has no connection. The system must hand a short notice to the phone maker’s push service. That is outside this lesson. Keep the notice small and let the app fetch the message by sequence number.

Presence

Presence says who is online. Do not try to catch every disconnect. Use a heartbeat that expires. While connected, the client sends a ping every so often. The server writes online with a time to live a little longer than the interval. If the pings stop, the entry expires, and the user is offline.

This is the failure detector idea again, from Chandra and Toueg’s work on unreliable failure detectors. A longer expiry avoids false offline marks and shows a gone user as online for longer.

Presence is the costly part to broadcast. A user with 500 contacts would send 500 updates on every change. Send presence only for conversations that are open or visible, and only on change. Let a client ask for the presence of a short list when it needs it. Accept a delay of seconds. Nobody needs presence to the millisecond.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms