الانتقال إلى المحتوى
تطبيقات الموبايلApp Architecture· 7 دقائق للقراءة

Push Notifications Aren't a Delivery Guarantee: Designing Around FCM and APNs

FCM and APNs accept your message, then deliver it when, and if, the device allows. Treat a push as a hint and let the app sync the truth.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
محتويات المقال

A clinic booking app moves an appointment from 4 pm to 2 pm. The server sends a data message with the new time, the app writes it into its local list of appointments, and the server marks the patient as notified. The next day support gets a complaint: the patient came at 4 pm, and the app still says 4 pm. The server logs show that FCM returned a message ID. Nobody can say what happened after that, because nothing in the design ever checked.

The common misconception

The belief: once FCM or APNs accepts a push, the phone receives it, the app runs, and the local data is updated. So the server can push the new state and move on, with no polling and no sync.

It's an easy belief to hold. In development the phone sits on your desk, plugged in, with the app open a minute ago, and every push arrives within a second. The send API returns a message ID that looks like a receipt. The word "push" itself suggests the server is in control. And most of the time, messages do arrive quickly. That's the half-truth: delivery is usually fast, but it isn't promised, and the failures land on the devices you rarely test: idle, offline, saving battery, or with the app swiped away.

What actually happens

A message ID means "accepted", not "delivered"

Firebase's docs are direct about this: when your server "receives a message ID back, it doesn't mean that the message was already delivered to the device. Instead, it means that it was accepted for delivery." If the device isn't connected, FCM stores the message until it is. By default a message lives for four weeks, and you can set its ttl anywhere from 0 to 2,419,200 seconds (28 days). A ttl of 0 means a message that can't be delivered immediately is discarded. And on Android, if a device hasn't connected to FCM for more than a month, FCM "still accepts the message but immediately discards it."

Apple calls APNs "a best-effort service". If it can't deliver right away, it may store the notification for up to 30 days, depending on the apns-expiration you set, and it warns that notifications "may also get throttled, saved in storage, and in some cases, not delivered."

The OS decides when your app hears about it

On Android, normal priority is the default for both data and notification messages. Normal messages arrive right away when the device is awake, but in "delivery may be delayed to conserve battery until the device exits doze." High priority can wake a sleeping device, but it's reserved for messages that show the user something: if FCM "detects a pattern in which messages don't result in user-facing notifications, your messages may be deprioritized to normal priority". FCM's newer AndroidConfigV2 API, still in preview, makes the split explicit: RemoteNotification for urgent, visible notifications and BackgroundSync for updates whose delivery "can be batched or delayed".

On iOS, a background notification (content-available with apns-priority 5) is the tool for silent updates, and Apple's docs say the system "doesn't guarantee their delivery". They advise sending no more than two or three per hour. The system may hold one back; when a newer one arrives, it keeps only the newest, and "if something force quits or kills the app, the system discards the held notification." And when a push does wake the app, the work must be quick: iOS gives it 30 seconds, and FCM's Android docs say the time in onMessageReceived is "only expected to be long enough to immediately render a notification". A backgrounded app can be stopped at any moment, as the article on the app lifecycle and process death explains.

Messages get collapsed, capped and reordered

A replaces an older one with the same collapse key that's still waiting. That's what you want for "sync now", but it means the device never sees the older payload. APNs goes further: when it can't deliver right away, it stores "only one notification per bundle ID".

Non-collapsible messages are capped. On Android, FCM stores at most 100 of them for a device; past that, "all stored messages are discarded," and the app later gets a special message (onDeletedMessages in the Android SDK) that is its cue to do a full sync.

Order isn't promised either. FCM "doesn't guarantee the order of delivery", and APNs "may reorder notifications you send to the same device token." If each push carries a new state, an old state can arrive last and win.

Push as a hint, sync as the truth

The fix is to stop treating the payload as the update. The push says "something changed"; the app asks the server what changed, using a token that remembers where its last sync ended.

Dart push_handler.dart
// Registered with FirebaseMessaging.onMessage and onBackgroundMessageFuture<void> onPush(RemoteMessage message) async {  final id = message.data['appointmentId'] as String;  final time = DateTime.parse(message.data['time'] as String);  // The push IS the update: miss it and the app stays wrong  await db.saveAppointmentTime(id, time);}

Now a lost push costs a delay, not a wrong screen: the next resume or the next push pulls the same change. Duplicates, collapsed pings and out-of-order arrivals all trigger the same pull, and since applying the same changes twice leaves the same result, the extra pulls are harmless. That's doing the work. A visible notification still carries its own text, "Your appointment moved to 2 pm", which the system can show without running your app.

MythReality
A message ID means the phone got itIt means FCM accepted it for delivery
Every push is stored until deliveredMessages expire, collapse, and on Android are capped at 100 pending
Pushes arrive in the order you send themNeither FCM nor APNs guarantees order
A data push always wakes the appDoze delays normal priority; iOS treats background pushes as low priority
High priority fixes everythingWithout visible notifications, FCM may deprioritize it

How to apply it in your project

  1. Find pushes that carry stateSearch your push handlers for payload fields written to storage or app state. Each one is a place where a missed push leaves the app wrong.
  2. Give the app a pull pathAdd an endpoint that returns changes since a token, and call it on app start, on resume, on every push and when the app learns that stored messages were deleted.
  3. Pick the message by its jobVisible, urgent messages get a notification payload and high priority (apns-priority 10 on iOS). Background refreshes get normal priority or a background notification, a collapse key, and a ttl that matches how long they're useful.
  4. Stop treating "sent" as "seen"Don't mark a user as informed when the send succeeds. If something must reach them, show it in the app on the next sync as well, or use a channel you can confirm.
  5. Test the bad daysPut an Android device into Doze, swipe the app away on iOS, disable notifications, and check that the app still ends up showing the right data.

Key takeaways

  • A message ID from FCM means the message was accepted, not delivered.
  • Doze, priority rules, TTL, collapsing and reordering all sit between your server and your app.
  • On iOS, background pushes are low priority, rate-limited and dropped when the app is force quit.
  • Use the push as a hint and keep the truth on the server, synced on start, resume and push.
  • Make syncing idempotent, so duplicate, late or out-of-order pushes are harmless.

📚 المصادر

  1. Set the lifespan of a message — Firebase Cloud Messaging
  2. Set and manage Android message priority — Firebase Cloud Messaging
  3. Non-collapsible and collapsible messages — Firebase Cloud Messaging
  4. Pushing background updates to your App — Apple Developer Documentation
  5. Sending notification requests to APNs — Apple Developer Documentation

التعليقات (0)