Push notifications with Firebase: notification messages vs data messages
Compare Firebase notification and data messages, their handling responsibilities and the limits to consider when designing push behavior.
If your app uses Firebase Cloud Messaging (FCM), the first design choice is which of two message types to send. Firebase's documentation (https://firebase.google.com/docs/cloud-messaging/concept-options) explains the difference. This article covers FCM only; iOS and Android system rules for permissions and display have separate documentation.
The two message types
- Notification messages ("display messages") have a predefined set of user-visible keys, such as title and body. The FCM SDK handles displaying them automatically when the app is in the background. When the app is in the foreground, your app code decides what happens.
- Data messages carry only your own custom key-value pairs. The client app is responsible for processing them.
A notification message can also carry an optional data payload. Then FCM displays the notification and your app handles the data.
Maximum payload for both types is 4096 bytes, except messages sent from the Firebase console, which has a 1000-character limit.
Which should you use?
Firebase's guidance: use notification messages when you want the SDK to display the notification for you while the app is in the background. Use data messages when you want to handle the message in your own client code.
| Need | Starting point (our reading of the above) |
|---|---|
| Simple alert, such as "Your order has shipped" | Notification message |
| Silent update of in-app data | Data message, subject to platform background execution and delivery limits, never a guaranteed immediate job |
| Alert that also opens a specific screen | Notification message with a data payload |
| Custom display logic in the app | Data message |
Where to send from
The documentation says to use the Admin SDK or the HTTP v1 API from a trusted environment such as Cloud Functions or your app server. The Firebase console is suited to testing and to marketing or re-engagement messages, and offers analytics-based A/B testing.
Practical design rules (Omnistu advice, not from the source)
- Send notifications that are timely and useful to that person, such as an order status change. Keep marketing sends separate and optional.
- Ask for notification permission when the benefit is clear, not on first launch.
- Give users a setting to choose which kinds they receive.
- Test the three states: app in foreground, background and closed.
- Never put sensitive data in the notification text, since it may show on a lock screen.
- Keep payloads small; the limit above is 4096 bytes.
Limits
We did not read FCM's platform-specific pages for iOS and Android, so behaviours such as delivery timing and permission prompts are not covered here.
By Omnistu.