Reach a phone even when the app is closed, through the phone maker's push service.
A push notification is a short message that appears on a phone or in a browser, even when your app is closed. Your server does not talk to the phone directly. It hands the message to the platform's push service, which delivers it.
An app that is not running cannot keep its own connection open for hours. That would drain the battery. Instead, the phone keeps one shared connection to its maker's push service: Apple's APNs for iPhones, Google's FCM for Android, and browser push services for web push. Your server talks to that service, and the service reaches the phone.
When the user installs the app and agrees to notifications, the app asks the operating system for a device token. The app sends that token to your server and you save it next to the user id. A user with a phone, a tablet and a browser has three tokens. Tokens can change, so the app must send the new one when it does.
| Platform | Push service | Address you store | Notes |
|---|---|---|---|
| iPhone and iPad | Apple Push Notification service (APNs) | Device token | Your server authenticates to Apple, using a key or a certificate |
| Android | Firebase Cloud Messaging (FCM) | Registration token | Also used to reach other platforms through one API |
| Browsers (web push) | The browser's own push service | A subscription (an endpoint and keys) | Needs a service worker and the user's permission |
| Kind | What the user sees | Typical use | Caution |
|---|---|---|---|
| Visible (notification) | An alert on the screen | Messages, offers, alerts | Users can mute or block them |
| Silent (data) | Nothing. The app wakes and runs briefly | Tell the app to sync | The system may limit or delay these |
| Topic message | An alert sent to everyone who subscribed | News, sport, a region | Good for broadcast, not for private data |
POST to the push service
to: <device token>
ttl: 1800 <- seconds the service may hold it
priority: normal | high
collapse_key: "chat-42" <- a newer message replaces an older one
payload: {
title: "Sam",
body: "Dinner is ready",
data: { messageId: "m-981" } <- an id, not the secret content
}A simplified, deterministic model. Delays, the 500 pushes per second per worker and the TTL values are illustrative. Real push services are best-effort: they may delay, merge or drop messages, and each platform has its own limits and rules.
| Term | Meaning in easy words |
|---|---|
| Push notification | A message delivered to a device by a platform push service |
| Device token | The address of one app install on one device, issued by the platform |
| APNs | Apple's push service for iOS and macOS |
| FCM | Google's push service for Android, and a common API for other platforms |
| Web push | Push for browsers, using a service worker and a subscription |
| Payload | The small message you send (title, body, and a little data) |
| TTL (time-to-live) | How long the push service may hold a message for an offline device |
| Silent push | A data-only push that wakes the app but shows nothing |
| Topic | A named group, so one send reaches every subscriber |
| Collapse key | A label so a newer message replaces an older waiting one |
| Fan-out | Turning one event into many sends, one per recipient |
| Choice | We gain | We lose |
|---|---|---|
| Long TTL | More offline users still get it | A stale message may arrive late and look odd |
| Short TTL | Only fresh messages are shown | Offline users miss it for good |
| High priority | Fast delivery for urgent things | More battery use. The platform may limit abuse |
| Data in the payload | The app can show it without a network call | Size limits and privacy risk |
| Id in the payload, fetch later | Small and safer | An extra request when the app opens |
| Topics | One call reaches many people | No per-user personalisation |