In short. A live socket is a delivery path, not the chat history. Commit one logical send, fan it out asynchronously, and let authorized devices catch up from a durable position.
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.
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. At the scaled workload below, conversation-owned storage partitions need measured capacity and a recovery plan; the design does not claim that one Postgres instance serves the entire exercise.
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.
Derive the send, fan-out and reconnect budgets together
Hypothetical scaled planning scenario. Northwind is a fictional 40-person business; this is a capacity exercise for its chat architecture, not a claim about current users. Choose 100 million daily active users, each sending 50 messages per day. Accepted logical messages total 100,000,000 × 50 = 5,000,000,000 per day. Dividing by 86,400 seconds gives approximately 57,870 messages/s on average. A chosen peak multiplier of three gives about 173,611/s, rounded to 174,000/s for planning. The multiplier is an assumption.
At a chosen 500 bytes of message payload and metadata, daily logical growth is 5,000,000,000 × 500 = 2,500,000,000,000 bytes, or 2.5 decimal TB. Thirty days retain 2.5 × 30 = 75 TB. Three full payload copies retain 75 × 3 = 225 TB. Indexes, replication logs, backups, attachments and physical allocation are additional. These byte counts establish neither database throughput nor the number of machines.
Suppose each accepted message needs delivery to ten recipient devices. Daily delivery opportunities are 5,000,000,000 × 10 = 50,000,000,000. Peak fan-out under the same chosen multiplier is about 173,611 × 10 = 1,736,110 device deliveries/s before retries. A large conversation can concentrate that work on one owner even when unrelated conversations are distributed evenly.
Choose a reconnect wave involving 1% of the daily active users, modeled here as one million devices. Each lacks 40 messages, so catch-up requires 1,000,000 × 40 = 40,000,000 message transfers. At 500 bytes each, payload is 20,000,000,000 bytes = 20 GB. Transferring this in a chosen 100-second recovery window requires an average 20 GB ÷ 100 = 200 MB/s, before transport and authorization overhead.
Choose one authorized catch-up stream per device and a page capacity of 100 messages. Each device missing 40 messages needs ceil(40 ÷ 100) = 1 page; unused page capacity cannot be filled with another device’s response. The wave therefore requires 1,000,000 × 1 = 1,000,000 device-facing page requests. Meeting the same 100-second target requires 1,000,000 ÷ 100 = 10,000 successful pages/s alongside live work. At a separately chosen mean page-slot holding time of 0.2 seconds, stable average occupancy is 10,000 × 0.2 = 2,000 slots. A pool size alone is not proof that storage, network or membership checks can sustain the target.
If live traffic leaves capacity for only 2,000 successful catch-up pages/s, the backlog needs 1,000,000 ÷ 2,000 = 500 seconds. Shared backend fetches or several conversation streams per device require separate accounting; this model counts device-facing requests for one stream each. Enlarging the queue cannot meet the earlier 100-second target. Give recovery a bounded share of resources, observe lag and revise the target or the constrained capacity explicitly.
For one conversation within that workload, suppose durable sequence 120 exists and a device last confirmed 117. The missing range is 118 through 120, containing 120 − 117 = 3 messages. The cursor locates history; current membership decides whether the device may receive it. Advance the cursor only after the defined delivery acknowledgement, so a lost notification can be replayed without losing durable history.
In the wild: Slack separates startup work from live events
Slack’s Flannel engineering report describes loading less user and channel information at startup and fetching details on demand through an application-level edge cache. It also describes using cached startup information to reduce backend pressure during reconnects. The case shows that connection recovery involves metadata demand as well as message bytes.
The report discusses moving additional event fan-out toward the edge as future work at that time. Treat that distinction as part of the evidence: an announced next step is not a completed feature in the described system. Northwind can investigate whether startup metadata dominates its own reconnect path without copying Slack’s implementation or claiming its reported scale.
Ordering is a product contract
Per-conversation order is often sufficient. A universal order across unrelated conversations adds coordination without necessarily helping users. Client timestamps can describe local composition time, but they do not safely assign one authoritative order across disconnected devices.
Edits and deletions should identify the target message and a version or ordered event. The display can derive current state while retaining an appropriate audit history. Decide what deletion means for offline copies and notifications already delivered; the server cannot retroactively erase what a recipient has seen.
Presence is deliberately weaker state. An expiry or heartbeat policy can estimate whether a device appears connected, but should not authorize business actions or establish that a person is reading. Resource recovery and user meaning need different indicators.
A revoked member reconnects with an old cursor
Hypothetical scenario. A gateway caches membership, then misses a revocation event. The former member reconnects and requests messages after an old cursor. Returning log entries solely because the cursor is valid leaks the conversation.
Recheck the authority required by the read contract and invalidate derived membership state according to its declared freshness policy. A live connection established earlier is not indefinite permission. Revalidate attachment access separately rather than embedding permanent public object links in messages.
During a permission-service outage, choose a stated unavailable response where eligibility cannot be established. Record the affected path and membership version without copying private message bodies into unrestricted telemetry. Successful transport counts must not hide unauthorized delivery.
Avoid three messaging shortcuts
“Ordered frames mean durable application order.” Transport ordering on one connection does not assign history across reconnects, devices and writers.
“A push notification is delivery.” Provider acceptance, device receipt, application display and human reading have distinct evidence.
“A replay is a new send.” Reconcile the same logical identity. Creating a fresh identity on every retry defeats the deduplication boundary.
Evolve the design from observed pressure
Begin with a durable indexed log and bounded delivery workers. Isolate large-conversation fan-out from ordinary conversations. Partition by conversation when ownership and workload justify it, then handle a hot conversation explicitly rather than assuming more partitions split its order.
Measure accepted messages, unresolved sends, device lag, catch-up age, membership failures and fan-out saturation. Restore from backups and replay derived delivery intent under controlled limits. A broker restart should not require inventing missing history from gateway memory.
Reject synchronous delivery to every recipient before acknowledging a send unless that is the actual product requirement. It makes one offline device a dependency of the sender's acceptance. Reject unbounded reconnect pages and global ordering without a user-visible reason.
What this chat model leaves out
The model covers text history, membership and reconnect; attachment storage, encrypted group-key management and voice are separate designs. Workload, fan-out, payload size and recovery timing are illustrative. Real partitions need storage and queue measurements, and current authorization cannot retract information already delivered to a former member’s device.
Check yourself: review the chat contract
A send response is lost after commit. What should the retry identify?
The same logical send under the authenticated sender and conversation. Return or reconcile the recorded result rather than assigning another message identity.
The reconnect cursor is valid but membership was revoked. Should catch-up proceed?
No. A position identifies history, not permission. Evaluate current eligibility under the declared membership contract.
One group dominates delivery work. Does adding log partitions solve it?
Not automatically. Its authoritative order and recipient fan-out remain. Isolate and bound delivery work, examine the hot conversation and preserve the chosen ordering contract.
The system accepts messages at its planned peak but reconnect lag keeps increasing. Which budget is missing?
The catch-up path has its own storage, authorization and network demand. Compare its successful page rate with backlog arrival instead of using send throughput as proof.
Redis loses all presence entries. Should durable message history disappear?
No. Presence is a disposable hint in this design. Devices authenticate again and recover permitted history from the authoritative log.
Northwind decision log
Separate durable message acceptance from live delivery.
Synchronize by durable position after reconnecting.
Deduplicate delivery without erasing valid repeated messages.
Go deeper: group communication and reconnect
- Video lecture: Scaling Slack — Bing Wei. Watch first: follow the distinction between client state, cache load and real-time messaging.
- Book chapter: Distributed Systems, 4th edition, chapter 4: Communication — Maarten van Steen and Andrew S. Tanenbaum. Compare communication patterns without confusing a channel with durable history.
- Book chapter: Distributed Systems, 4th edition, chapter 8: Fault tolerance — Maarten van Steen and Andrew S. Tanenbaum. Study reliable group communication and recovery.
- Primary source: Flannel: An Application-Level Edge Cache to Make Slack Scale — Slack Engineering. Compare startup metadata, connection state and the durable message history.