Push notifications look simple from the outside: send a message, a phone buzzes. Underneath, you are coordinating two gatekeepers (Apple Push Notification service and Firebase Cloud Messaging), thousands of device tokens that expire without warning, operating-system policies that throttle you, and users who can disable you with one tap. Teams that treat push as a “send” API end up with low delivery rates, duplicate messages and deep links that open the wrong screen.
This article describes an architecture that holds up in production, with specific attention to the parts that most often go wrong.
How the two services work
Both platforms follow the same shape. Your app asks the operating system to register for remote notifications, and the OS returns an opaque device token. Your app sends that token to your backend. When you want to notify the user, your backend sends a payload addressed to the token to APNs or FCM, which relay it to the device.
APNs (Apple) accepts HTTP/2 requests to api.push.apple.com (and a sandbox host for development builds). You authenticate with either a token-based key (a .p8 file, JWT signed with ES256, valid for up to an hour per token, one key works for all your apps) or certificates that expire yearly. Prefer the token-based approach; certificate expiry has caused many silent outages.
FCM (Google) uses the HTTP v1 API, authenticated with short-lived OAuth 2.0 access tokens generated from a service account. The legacy server-key API has been retired, so any older integration needs migration. FCM handles Android natively and can also relay to iOS by forwarding to APNs, which lets you use a single send API for both platforms at the cost of an extra hop.
A common design decision is whether to send to APNs directly for iOS or route everything through FCM. Routing everything through FCM reduces code and gives you topics and analytics in one place. Going direct to APNs gives you full control of APNs-specific headers and one fewer dependency. For most teams, FCM for both platforms is the pragmatic starting point, and direct APNs becomes attractive when you need fine control over priorities, collapse behavior and Live Activities.
Device tokens: the part everybody underestimates
Tokens are not user identifiers. They are per-install, per-app, and they change. Plan for these events:
- A user reinstalls the app, restores a backup to a new phone, or clears app data: a new token is issued.
- FCM tokens rotate periodically and when the app is restored on a new device.
- APNs tokens change in several circumstances, and Apple advises requesting the token on every launch.
- A user uninstalls the app: the token becomes invalid, but you only learn that when a send fails.
The consequence is that you need a proper token table, not a column on the user record:
| Column | Purpose |
|---|---|
id |
Primary key |
user_id |
Owner; nullable for pre-login installs |
token |
Unique index, the platform token |
platform |
ios, android, web |
app_version, os_version |
Debugging and targeting |
locale, timezone |
Localized and well-timed sends |
last_seen_at |
Updated on every app launch |
notifications_enabled |
Mirrors OS permission state |
invalidated_at |
Set when the provider reports the token dead |
Operational rules:
- Upsert on every launch. The app reports its current token each time it opens; the backend updates
last_seen_at. - One user, many tokens. Phones, tablets and old devices all receive pushes unless you prune.
- Handle invalidation responses. APNs returns
410 Unregistered, and FCM returnsUNREGISTEREDorINVALID_ARGUMENTfor dead tokens. Mark them invalid and stop sending. Continuing to send to dead tokens harms your sender reputation. - Detach on logout. When a user logs out, remove the association between that token and that user, or the next person on a shared device will receive the previous user’s private notifications. This is a real privacy bug, and it appears in many apps.
- Prune stale tokens. Tokens unseen for 60 to 90 days are rarely worth sending to. FCM itself treats tokens inactive for 270 days as expired.

Permissions and the opt-in problem
iOS requires explicit user permission; Android 13 and later does too, via the POST_NOTIFICATIONS runtime permission. A user who denies the system prompt can only be won back through Settings, so do not spend your single prompt on launch. Show a short in-app explanation first (“Get alerts when your payment is confirmed”) and trigger the system dialog after the user shows intent. Teams that defer the prompt to a moment of clear value commonly see opt-in rates substantially higher than those that ask at first launch.
Track permission state as data. Report it with the token, and store it, so your analytics can distinguish “delivered” from “sent to someone who disabled notifications”.
Message types and payloads
Distinguish two kinds of messages:
- Notification messages (alert pushes) display a visible banner. The OS renders them even if the app is not running.
- Data messages (silent or background pushes) wake the app to fetch data. iOS heavily throttles silent pushes and does not guarantee delivery; never rely on them for anything critical.
Keep payloads small. APNs allows 4 KB, and FCM allows 4 KB for most message types. Do not put sensitive data in the payload; send an identifier and let the app fetch the details after the user authenticates. A typical APNs payload:
{
"aps": {
"alert": { "title": "Payment received", "body": "US$50.00 from Maria" },
"sound": "default",
"thread-id": "payments"
},
"deeplink": "myapp://payments/pay_8f21",
"message_id": "msg_01HZX"
}
Use thread-id (iOS) or notification channels and tags (Android) to group related notifications. On Android 8 and later, channels are mandatory and the user controls them individually, so define them thoughtfully: “Transactions” and “Marketing” should be separate so users can keep one and mute the other.
Topics, segments and fan-out
For broadcast sends, FCM topics let devices subscribe to a named stream (news, market-miami) and let you send one request to reach all subscribers. They are cheap and simple, with caveats: you cannot enumerate subscribers, delivery is best effort, and fine-grained personalization is impossible.
For anything personalized, such as “your balance changed” or “your order shipped”, send per token. For large campaigns, fan out through a queue:
- A scheduler or event creates a campaign record with a target segment.
- A worker resolves the segment to a list of tokens in batches of 500 to 1,000.
- Each batch becomes a job on a queue (BullMQ, SQS, Sidekiq or similar).
- Send workers call FCM or APNs with controlled concurrency and retry rules.
- Results update a delivery table and invalidate dead tokens.
Rate limits matter. APNs allows many concurrent HTTP/2 streams on one connection, and you should reuse connections rather than reconnect per message; opening a fresh connection for each request can get you throttled. FCM enforces per-project quotas, and a sudden blast to a million tokens should be spread over minutes.
Scheduling and timing
Notifications that arrive at 3 a.m. get muted. Respect time zones by storing the user’s IANA time zone, and schedule marketing sends in local time rather than server time. Add quiet hours, and cap frequency per user: for example, no more than three non-transactional pushes per day and one per hour. Enforce caps centrally in the sending service rather than trusting each feature team to behave.
Separate transactional messages (security alerts, payment confirmations, delivery updates) from promotional ones, in code, in channels and in user preferences. Transactional messages bypass frequency caps and quiet hours; promotional ones obey them.
For time-sensitive content, set expiry. APNs apns-expiration and FCM ttl tell the service how long to hold a message for an offline device. A “your driver is arriving” push should expire in minutes, not days. Use apns-collapse-id or FCM collapse_key so a stale update is replaced by the newest one rather than all being delivered when the phone comes back online. Priority matters too: use high priority only for user-visible, time-critical messages, since misusing it drains batteries and platforms may downgrade your traffic.
Deliverability: why pushes do not arrive
Sent is not delivered, and delivered is not seen. The funnel has many leaks:
- Permission denied or notifications disabled in system settings.
- Invalid or expired tokens, which you handle through feedback.
- Battery and data saver modes, plus aggressive manufacturer task killers on some Android devices, that delay or drop messages.
- Throttling of repeated high-priority or silent messages.
- Wrong environment: a production build with a sandbox token, or the reverse, returns
BadDeviceToken. Keep environments strictly separated. - Expired credentials: APNs keys revoked, certificates lapsed, or service accounts rotated without updating the sender.
- Payload errors: oversized or malformed JSON.
Build a delivery log: message ID, token ID, provider response code, timestamp. Add client-side acknowledgements by having the app report “received” and “opened” events. Dashboards should show send, accepted-by-provider, received and opened as separate series, plus error counts by code. Alert on a rising Unregistered ratio or any spike in authentication errors; both are early warnings of broken credentials or a bad release.
Deep links that land correctly
A notification that opens the app’s home screen when it promised “your document is ready” feels broken. Handle deep links with care:
- Put a route in the payload (
myapp://payments/pay_8f21) or, better, a universal link (iOS) or app link (Android) on your own domain, so the same URL works from email, SMS and push. - Handle three app states: the app is killed (cold start), in the background, and in the foreground. Each triggers a different callback, and cold start is the one teams forget to test.
- Require authentication before showing sensitive content. If the user is logged out, store the intended route, run the login flow, then navigate.
- Validate the target. A deep link should never trigger a state-changing action on its own, such as confirming a transfer.
- When the target entity no longer exists, show a clear message and a sensible fallback screen.
Test deep links with the platform tools (xcrun simctl push for the iOS simulator, adb shell am start for Android) in your automated suite, not only manually.
Privacy, compliance and fintech considerations
Lock-screen previews can leak information. In financial or health apps, avoid exact balances and account numbers in the notification body, or use iOS notification service extensions to decrypt content on the device. Honor unsubscribe preferences at the category level, and keep consent records where regulations require them. In apps we help operate, including CityFraction, a fractional real-estate investing app, the rule is simple: the push says that something happened, and the app shows the details after authentication.
Key takeaways
- Treat device tokens as volatile, per-install data in their own table, upserted on every launch and invalidated on provider feedback.
- Prefer APNs token-based authentication and FCM HTTP v1; both avoid the silent outages caused by expired certificates and retired APIs.
- Separate transactional from promotional messages in code, channels and preferences, and enforce frequency caps and quiet hours centrally.
- Use collapse keys, TTLs and correct priorities so stale or low-value messages do not drain batteries or arrive late.
- Measure the whole funnel from sent to opened, and alert on credential errors and rising unregistered rates.
- Test deep links in cold, background and foreground states, and never put sensitive data in the payload.

