How do you deliver messages to a user who is offline?
Sketch your own answer first, then compare it with the one below.
A strong answer
Store each message first and treat the push to the connection as an optimisation. If the user has no connection, nothing else is needed.
On reconnect the client reports the last sequence number it holds for each conversation. The server returns everything after it, in order. This is the same range read as history, so there is no per-user queue.
For a phone with the app closed, send a small notice through the platform push service and let the app fetch by sequence number.
Sources
- Leslie Lamport (1978). Time, clocks, and the ordering of events in a distributed system.
- Ian Fette, Alexey Melnikov (2011). RFC 6455: The WebSocket Protocol.