LESSON 04 · One-to-one flow

Follow one message end to end

Persist a message once, then try live delivery or notify an offline recipient.

SYSTEM VIEW

The message path

Diagram view
Ana sees—
Stored copies—
Devices have it—

Watch Ana’s “lunch?” get through a lost acknowledgement and a retry, then reach Ben’s laptop and his sleeping phone.

  1. Ana’s phone sends “lunch?” with the conversation ID and k-71, an idempotency key it made for this one send. A retry will carry the same key. The Chat service first checks that Ana is a member of the conversation.

    Key
    k-71
    Text
    lunch?

    What changed

    • “lunch?” sent with key k-71
    • Membership checked
  2. The Chat service assigns message 1042 at position 88 and stores it in Message history. Only then does it acknowledge, so “sent” will mean stored. But the acknowledgement is lost in a dead zone, and Ana’s phone can’t tell whether the send was stored.

    What changed

    • Message 1042 at position 88
    • 1 stored copy
    • Acknowledgement lost
  3. Ana’s phone retries with the same key, k-71. The Chat service looks the key up, finds message 1042 and returns it without writing another row. Ana’s phone now shows “sent”, and Message history still holds one copy.

    What changed

    • Retry with k-71
    • Key found: same 1042 returned
    • Still 1 stored copy
  4. The Delivery worker takes message 1042 and checks each of Ben’s devices for a live route. His laptop is connected to a gateway, so “lunch?” goes to it at once. His phone is asleep, with no live route.

    What changed

    • Delivery worker
    • “lunch?” live on Ben’s laptop
    • Ben’s phone asleep
  5. Ben’s phone is asleep, so the Delivery worker asks the Push provider to wake it. A notification is only a hint: Apple’s APNs keeps just the latest per app for an offline device, so earlier ones can vanish.

    What changed

    • Push provider
    • Notification wakes Ben’s phone
    • Push is a hint
  6. Woken, Ben’s phone asks the Chat service for everything after position 87. Message history, the source of truth, returns position 88: “lunch?”. Both of Ben’s devices now have message 1042.

    What changed

    • Fetch after position 87
    • Position 88 on Ben’s phone
    • 2 of 2 devices
  7. Ana’s “sent” means accepted: message 1042 is stored with an ID, nothing more. Delivered means a device has it, as Ben’s phone now does; read means Ben has seen it. These acknowledgements may reach Ana late, or never.

    Accepted
    stored, with an ID
    Delivered
    on a device
    Read
    by a person

    What changed

    • “Sent” means accepted: stored
    • Ben’s phone: delivered, unread
    • Read: not until Ben sees it
  8. Safe retries have a price: the Chat service looks up the key on every send, from Ana or Ben, and keys are kept for a few days. A unique index on conversation and key in Message history covers both.

    Per send
    1 key lookup
    Keys kept
    a few days
    Index
    conversation + key

    What changed

    • 1 lookup per send
    • Keys kept a few days
    • Unique index: conversation + key

Space plays · ← → step · Home resets

THE IDEA

How it works

The sender submits a client-generated idempotency key, a token identifying one logical send, with the conversation ID and text. The chat service validates membership, assigns a server message ID and position, persists the record, and acknowledges acceptance. Only then should the sender show a durable “sent” state. A retry with the same key must not create a second message.

Follow one send. Ana’s phone sends “lunch?” with key k-71. The service stores it as message 1042, position 88, but the acknowledgement is lost in a dead zone. Her phone retries k-71, and the service finds the existing row and returns message 1042 without writing another. Ben’s laptop, connected to a gateway, receives a live push. Ben’s phone is asleep, so it gets a notification, wakes, and fetches everything after position 87.

The delivery worker checks each recipient device’s live route. It pushes to connected devices and may ask the notification service to wake inactive ones. Push notifications are hints; clients retrieve history from storage to fill gaps. Apple’s APNs, for instance, keeps only the most recent notification per app for an offline device, so earlier ones can vanish.

Distinguish accepted, delivered to a device, and read by a person. These acknowledgements may arrive later or never. A network timeout after persistence is ambiguous to the sender, which is why idempotency and client-side reconciliation matter. The cost is a lookup on every send and keys retained for a few days; a unique index on conversation and key covers both.

DECISION POINT

The server saves a message but its acknowledgement is lost. The sender retries. What should the service return?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • Persist before claiming durable acceptance.
  • Retries and offline catch-up need stable IDs and idempotency; push is not the source of truth.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
RecallQUESTION 01

What should “accepted” mean in this design?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 3 checkpoints answered correctly to complete this lesson.