Offline Messages and Push Notifications in a Chat System
How chat apps deliver to offline users: pending message queues, APNs and FCM push, collapsing notifications, multi-device sync and encrypted push payloads.
Published November 27, 2026
Most of the time, the person you are messaging is not staring at the app. Their phone is in a pocket, the app is suspended by the operating system, and there is no open connection to push to. Delivering reliably in that state needs two cooperating mechanisms: a server-side store of pending messages and the platform push services, Apple Push Notification service (APNs) and Firebase Cloud Messaging (FCM).
The concept
When the chat service routes a message and the session registry shows the recipient has no active connection, it stores the message in that user's pending queue (or inbox) and asks the push service to notify the device. The push notification is a wake-up call, not the transport of record. When the user opens the app, or the OS briefly wakes it, the client connects and downloads everything after its last sync cursor.
Push services are best-effort. They may delay, coalesce or drop notifications, and they impose payload limits (around 4 KB). They also see whatever you put in the payload, which matters for end-to-end encrypted apps. The common pattern is to send either a minimal "you have new messages" signal or an encrypted payload that the app's notification extension decrypts on the device before displaying it.
Delivering to an offline user
Push notification design concerns
| Concern | Approach |
|---|---|
| Reliability | Pending store is the source of truth; push may be lost |
| Privacy (E2EE) | Encrypted payload decrypted by a notification service extension, or no content at all |
| Spam / battery | Collapse keys and per-conversation coalescing; quiet hours |
| Multiple devices | Push to every registered device token; sync read state across devices |
| Stale tokens | Remove tokens when APNs/FCM reports them unregistered |
| Throughput | Batch sends, use HTTP/2 connections to APNs, FCM v1 API |
Collapsing notifications
Multi-device sync
Modern chat apps run on a phone, a desktop app and a browser at once. Each device keeps its own sync cursor per conversation, and each device has its own encryption identity in end-to-end encrypted systems, so the sender encrypts for every device of every recipient. Read state is synchronised by sending read markers to the user's other devices, which clear their notifications.
Practical examples
FCM v1 data message
A data-only message lets the app decide what to show after decrypting or fetching.
POST https://fcm.googleapis.com/v1/projects/my-chat/messages:send
Authorization: Bearer <oauth-token>
{
"message": {
"token": "<device-token>",
"android": { "priority": "HIGH", "collapse_key": "conv-u42-u77" },
"data": { "type": "new_msg", "conv": "u42:u77", "enc": "base64-ciphertext" }
}
}APNs request with a mutable notification
mutable-content lets the iOS Notification Service Extension decrypt before display.
POST /3/device/<device-token> (HTTP/2 to api.push.apple.com)
apns-push-type: alert
apns-collapse-id: conv-u42-u77
{
"aps": { "alert": { "title": "New message", "body": "…" }, "mutable-content": 1 },
"enc": "base64-ciphertext"
}Pending queue per user
A sorted set keyed by message id lets clients fetch everything after their cursor.
ZADD pending:77 1764238512345 "msg:c1f9"
ZRANGEBYSCORE pending:77 (1764238400000 +inf LIMIT 0 200
ZREMRANGEBYSCORE pending:77 -inf 1764238512345 # after device acksCommon mistakes
- Treating push notifications as guaranteed delivery and not storing pending messages.
- Putting plaintext message content in push payloads of an end-to-end encrypted app.
- Never cleaning up invalid device tokens, wasting throughput and risking provider throttling.
- One notification per message in busy groups, causing users to mute or uninstall.
- Syncing only from one device's perspective, so read messages stay unread on other devices.
Key takeaways
- Store pending messages server-side; push only wakes the device.
- APNs and FCM are best-effort with payload limits and see unencrypted content.
- Coalesce notifications and respect collapse keys.
- Track cursors and device tokens per device for multi-device sync.
FAQ
Why do some notifications arrive late?
Battery optimisation (Doze on Android, iOS budgets), network conditions, or normal-priority pushes being batched by the OS.
Can the server know a push was displayed?
Not reliably. Only the client connecting and acknowledging messages proves delivery.
How long should pending messages be kept?
Long enough to cover typical offline periods. WhatsApp has stated undelivered messages are deleted after 30 days.