Push Notifications and Background Work

Topics Covered

How Push Delivery Actually Works

The three parties in every push

Tokens: getting them, storing them, losing them

The provider side of the pipe

Storage, collapsing and expiry

Sending at scale and avoiding duplicates

What the interviewer is checking

Push notifications look simple from the user's side: something happens and the phone lights up. In a mobile system design interview they are one of the richest deep dive topics, because the delivery path crosses three parties you do not fully control and the platform rules shape every decision. This lesson covers the push pipeline, permission strategy, rich notifications, background work, the choice between polling and push to sync, and routing a tap to the right screen. The client architecture, the networking layer and the offline sync engine were covered in earlier lessons, so here we focus on how the outside world wakes your app and what your app may do once it is awake.

The three parties in every push

Neither iOS nor Android lets your server open a connection to a phone and push bytes into your app. Each platform keeps one persistent, battery efficient connection from the device to its own push service: Apple Push Notification service (APNs) on iOS, and Firebase Cloud Messaging (FCM) on Android, which rides on the Google Play services connection. Your server talks to the push service, the push service talks to the device, and the operating system decides whether and when your app process gets involved.

That gives three parties: your backend, which decides that a user should be told something; the platform push service, which stores and forwards; and the device operating system, which displays the notification or wakes the app under its own rules. A good answer draws all three and is explicit about which one owns which guarantee. Your backend owns what to send and to which tokens. The push service owns best effort delivery with limited storage. The operating system owns display, throttling and process lifecycle.

A push travels from your server, through the platform push service, to a device token the app registered earlier.

Tokens: getting them, storing them, losing them

A device token (APNs) or registration token (FCM) is an opaque address for one app install on one device. The app requests it at launch. On iOS you call registerForRemoteNotifications and receive the token in a delegate callback; on Android the Firebase messaging library hands you a token and calls onNewToken whenever it changes. The app then sends the token to your backend with the user and device identity, and the backend keeps a table that maps a user to the set of tokens for their installs.

Tokens change. They rotate after a reinstall, after a restore to a new phone, when the user clears app data, and occasionally for reasons the platform does not explain. So the client should send its current token on every launch and on every change callback, and the server should upsert by installation identifier rather than append blindly. The server learns about dead tokens from the push service: APNs returns a 410 status with a reason such as Unregistered, and FCM returns an UNREGISTERED or NOT_FOUND error. Delete the token when you see those responses, or your fan out wastes work on installs that no longer exist.

json
1{
2  "user_id": "u_381",
3  "installation_id": "inst_9f2c",
4  "platform": "ios",
5  "push_token": "a1b2...",
6  "app_version": "7.14.0",
7  "locale": "en-GB",
8  "notifications_enabled": true,
9  "updated_at": "2026-11-30T09:12:00Z"
10}

Two fields in that record deserve a mention in an interview. The app version lets the server avoid sending a notification type that an old build cannot render or route. The notifications_enabled flag reflects the current permission state, which the user can change in system settings at any time, so the app should refresh it on launch. Logging out must remove or detach the token, otherwise the next person to use the device receives the previous user's messages, which is both a privacy bug and a support nightmare.

The provider side of the pipe

On the server side, APNs uses an HTTP/2 API. Most teams authenticate with a token based key (a signed JWT generated from a key file) rather than per app certificates, because one key works across apps and does not expire yearly. Each request names the device token in the path and carries headers that matter for design: apns-push-type (alert, background, liveactivity, voip and others), apns-priority (10 for immediate delivery, 5 for delivery that may be batched to save power), apns-expiration and apns-collapse-id. FCM is reached through the HTTP v1 API using short lived OAuth access tokens from a service account; the older legacy API was shut down, so any design that mentions it is out of date.

http
1POST /3/device/a1b2c3... HTTP/2
2host: api.push.apple.com
3authorization: bearer eyJhbGciOiJFUzI1NiIs...
4apns-push-type: alert
5apns-priority: 10
6apns-collapse-id: thread-42
7apns-expiration: 1796040000
8
9{"aps":{"alert":{"title":"Ana","body":"Running 5 min late"},"thread-id":"thread-42","mutable-content":1},"conv":"42","msg":"m_9001"}

Payloads are small. Both services cap the main payload at about 4 KB, with a slightly larger allowance for VoIP pushes on iOS. That cap drives an important design rule: a push carries identifiers and a short preview, never the full object. The client fetches the authoritative data from your API, or from its local database after a sync. This also keeps sensitive content out of a channel you do not control.

Storage, collapsing and expiry

When the device is offline, the push services hold messages for a while, but not indefinitely and not all of them. APNs keeps only the most recent notification per app per device while the device is offline, and drops it once the expiration time passes. FCM keeps more, with a default time to live of about four weeks, but it also collapses messages that share a collapse key and limits how many non collapsible messages it stores per device. You should therefore treat the push channel as lossy. A push says something probably changed; the sync protocol from the offline lesson is what makes sure nothing is missed.

Collapse identifiers are a useful tool rather than a nuisance. A sports score app should not show twelve stale score updates when the phone comes back online; it should show the latest one. Setting a collapse key per game, and a short expiry for time bound alerts such as a ride arriving, gives the user the current truth instead of a backlog.

Sending at scale and avoiding duplicates

A single event can fan out to many tokens: a group chat with fifty members who each have two devices means a hundred sends. Do not send from the request path that created the message. Write the event, put a fan out job on a queue, and let a pool of push workers resolve recipients to tokens and call the providers. HTTP/2 lets one APNs connection multiplex many requests, and FCM accepts many concurrent HTTP v1 calls, so a small worker pool handles high volume as long as it reuses connections.

Providers push back under load. Treat 429 and 5xx responses as retryable with exponential backoff and jitter, and treat token errors as permanent. Retries create a duplicate risk: if a request timed out after the provider accepted it, a retry may show the same alert twice. Give each logical notification a stable identifier, use it as the collapse key where that fits and log it as the apns-id, and have the client ignore a message id it has already displayed or stored. Duplicate alerts are a common complaint in chat apps, and saying how you prevent them is a quick way to show production experience.

Finally, record outcomes. Log per send the provider response, latency and token age, and aggregate them into delivery dashboards. The provider only tells you it accepted a message, not that the user saw it, so pair server metrics with a client side received event sent on the next sync. The gap between accepted and received is your real delivery rate.

What the interviewer is checking

Interviewers listen for whether you understand that delivery is best effort. Strong candidates say the backend sends to all of a user's tokens, prunes dead ones from provider responses, keeps payloads small and idempotent with a message identifier, and relies on sync for completeness. Weak candidates assume a push is guaranteed, put whole chat messages in it, or forget that the user may have several devices. Drawing the three parties, naming the token lifecycle and stating that the inbox on screen comes from the local store, not from the notification, covers most of what this part of the round is looking for.

A push is a hint, sync is the truth

Treat every notification as a pointer that says something changed. The app renders from its local database and closes gaps with the sync protocol, so a dropped or collapsed push only delays an update instead of losing it.