Hypothetical scenario. Northwind adds support chat. Dev keeps messages in the WebSocket gateway while an offline recipient is away. Maya asks what the sender’s success mark means if the gateway restarts before that recipient returns.
Priya: “Did we accept a message, deliver it, display it or establish that it was read?”
Dev: “Those observations need different evidence, even when the connection is healthy.”
Build the baseline around durable logical sends and recoverable conversation history. The chat case has its own workload and scope; attachments, voice and group-key management remain excluded. Decide what acceptance promises before choosing the live delivery path.
Which message observation does each acknowledgement mean?
A sender submits text to a conversation they may currently use. Acceptance means the service has durably recorded that logical send under the chosen failure contract. Delivery, display and reading are later observations. The interface should distinguish them rather than mark a message read when a server merely writes bytes to a connection.
Choose per-conversation order for the baseline. Independent conversations do not need one universal ordering point. A client-generated timestamp can help display composition time, but a disconnected device cannot use it to assign authoritative history. The accepted conversation sequence determines catch-up positions.
Socket success does not establish message history
A socket write can succeed locally while the peer disconnects before processing it. A server can receive a frame and crash before durable storage. Presence can remain stale after a lost connection. These are ordinary partial failures, not unusual exceptions to add after the happy path.
RFC 6455 specifies WebSocket handshake and framing for a persistent communication channel. It does not establish the application's durable history, deduplication, membership policy or offline synchronization. Polling and sockets can both serve a sound application contract; choose transport from latency, connection and operational requirements.
Do not use a connection identifier as the identity of the human, message or conversation. A person can have several devices and connections, while one logical send can have several attempts. Losing a connection must not erase the operation identity needed for reconciliation.
Distinguish message acceptance from live transport
Hypothetical scenario. A device sends message operation K to conversation C. The conversation authority verifies membership, assigns sequence 101 and durably records message M plus K's result. Only then does its acceptance reply establish that message history contains M. A WebSocket frame reaching a gateway establishes a different, earlier fact.
| Record / key | Fields | Meaning |
|---|---|---|
| Conversation / C | owner epoch, next sequence, membership version | Sequence authority |
| Message / C + sequence | M, sender, content reference, operation K | Accepted history |
| Device cursor / C + device | last acknowledged sequence | Device observation |
Live fan-out publishes M to connected devices, each of which may report delivery or read state under a separate policy. A disconnected device can still synchronize from durable sequence history. The server must not claim all devices received M merely because the sender got acceptance.
Partition conversations by a stable authority key when that matches the required ordering scope. A very large room can outgrow one sequencer or fan-out path; splitting it changes ordering or distribution responsibilities and needs a stated trigger. An owner change recovers the accepted prefix and fences the old owner. The retry K then returns M and sequence 101 rather than inserting another message.
Make the conversation log authoritative
Route each conversation to an authoritative write boundary. Authenticate the sender, validate current membership and atomically assign a conversation sequence with the accepted message. Preserve the client operation identifier so a repeated send returns the existing logical result instead of appending another message.
After commit, fan-out notifies connected devices. A missed notification is recoverable because the authoritative log remains available. A reconnect request supplies its last confirmed sequence and fetches a bounded next page. Do not advance the device cursor merely because a gateway attempted delivery.
Read receipts belong to an explicit user or device action. Whether opening one device marks history read everywhere is a product decision. Likewise, define whether a newly joined member sees earlier messages and whether a departed member retains access to previously received history.
For Northwind’s initial support service, a Postgres transaction can bind a client send identity to one accepted conversation sequence. Redis can hold disposable presence or connection hints, but those hints do not replace the durable conversation history. Additional conversation owners require measured capacity and a recovery plan; this design makes no benchmark claim about one PostgreSQL instance.
Keep gateways responsible for authenticated connections and owners responsible for accepted history. Publish fan-out intent after the durable commit and make repeated deliveries recognizable by message identity. A slow offline device then consumes recovery budget rather than holding the sender’s commit open indefinitely. The per-conversation owner is also the place to define membership changes relative to new messages.
Count messages and device work separately
Hypothetical worked example. Select one thousand active users, each sending twenty accepted logical messages in one day. The daily count is 1,000 × 20 = 20,000 messages. This is a selected planning cohort, not a claim about Northwind’s staff or actual customers.
At a chosen five hundred bytes per logical message and metadata record, daily payload is 20,000 × 500 = 10,000,000 bytes, or ten decimal MB. Thirty days retain 10 × 30 = 300 MB. Three complete payload copies contain 300 × 3 = 900 MB, before indexes, logs, attachments and allocation.
If every accepted message has three recipient devices, delivery opportunities are 20,000 × 3 = 60,000 per day. Offline devices and repeated delivery attempts can change when and how often transport work occurs. This count does not mean sixty thousand new authoritative messages. Derive connection memory and peak bursts from additional explicit assumptions before provisioning.
In the wild: startup metadata is another workload
Slack’s Flannel report describes reducing initial metadata loading and using an application-level edge cache. It demonstrates that client startup requires more than message payload transfer. This public account does not specify Northwind’s storage design or establish its capacity.
A successful socket write leaves no history
Hypothetical failure scenario. A gateway receives a send, writes a recipient frame and replies accepted before durable storage. It then crashes. One device saw the message; another reconnects and finds no accepted history. The service has no coherent fact from which to reconstruct its promise.
Commit the logical send and its delivery intent at the chosen authoritative boundary before acknowledging durable acceptance. A lost response is recovered through the same send identity. The message can then be delivered repeatedly without creating another accepted send. The gateway’s connection memory remains replaceable transport state.
Choose a coherent first deployment
Use a modular gateway, a conversation write boundary, an indexed durable log and bounded delivery workers. Separate their responsibilities without demanding separate deployments before the workload justifies them. PostgreSQL can implement the proposed initial local transaction, provided the selected uniqueness and sequence rules are actually enforced.
A connection route is a hint about where a device may be reached, not authority over the conversation. Redis presence can expire without losing durable history. Define missing-notification recovery through authorized log reads before optimizing the live path. The next page exercises that recovery during reconnect and membership changes.
Reject synchronous delivery to every device as a prerequisite for acceptance unless Maya actually requires that contract. It would make an offline recipient a dependency of every sender. Also reject a global message order without a user-visible reason. Both decisions would add coordination unrelated to the baseline promise.
Challenge the proposed mechanism
Two devices retry K while the conversation owner changes. What decides accepted order?
Reveal the design reasoning
The recovered authoritative history and its operation identity decide. Fence the old owner, recover K if accepted, and allocate a sequence only for a genuinely new accepted intention. Transport connection order cannot replace that history.
Decision and reconsideration: Choose per-conversation ordering explicitly. Report acceptance, device delivery and read receipts as separate facts.
Defend message acceptance
The send committed but its response disappeared. What should another attempt identify?
Recover the same send
The same authenticated sender, conversation and logical send identity. Inspect the recorded result rather than appending another message under a fresh identity.
A WebSocket write succeeded. Does that establish that the person read the message?
Separate transport and user evidence
No. Transport, device receipt, application display and human reading are distinct boundaries. Define the evidence for each interface state.
Redis loses presence hints. Should accepted messages disappear?
Keep durable authority separate
No. Presence is disposable in this design. Devices reconnect, authenticate and retrieve permitted history from the authoritative conversation log.
Durable history gives an offline device somewhere to return. Page 44 brings many devices back together and asks how to bound catch-up without starving live messages or carrying obsolete permission.
Northwind decision log
Commit one logical send before acknowledging durable acceptance.
Keep per-conversation history separate from live socket routing.
Next, bound catch-up and reauthorize devices during recovery.
Go deeper: channels and indirect communication
- Book chapter: Distributed Systems: Concepts and Design, fifth edition, chapter 5: Remote Invocation — George Coulouris, Jean Dollimore, Tim Kindberg and Gordon Blair. Inspect the remote-call boundary.
- Book chapter: Distributed Systems: Concepts and Design, chapter 6: Indirect Communication — the same authors. Compare messaging mechanisms with durable application history.
- Video lecture: Scaling Slack — Bing Wei. Trace client state and messaging pressure.
- Primary document: RFC 6455: The WebSocket Protocol — IETF. Inspect the transport contract without expanding it into application delivery guarantees.