A push notification is a message that travels from a server to a device via a push service, arrives even when the app isn’t open, and is displayed in the notification shade or banner.
Background
Push notifications have become a staple of mobile and web user experience. Unlike SMS or email, they are delivered through a specialized channel that requires a device to be registered with a cloud service. The term “push” refers to the server pushing data to the client rather than the client pulling it. The technology is built on a foundation of message brokers, secure sockets, and device tokens that uniquely identify each app installation.
How It Works
The delivery process can be broken into three main stages: registration, message construction, and delivery.
- Device Registration
- The app requests permission from the user to receive notifications.
- If granted, the operating system generates a unique device token and sends it to the app.
- The app forwards this token to its backend server.
- The backend stores the token along with any user‑level preferences.
- Message Construction
- When an event occurs (e.g., a new message, a sale, or a weather alert), the server builds a payload.
- The payload contains a title, body text, optional icon, sound, and a custom data dictionary.
- For iOS, the payload must be JSON and is signed with the app’s APNs certificate. For Android, it is sent to Firebase Cloud Messaging (FCM) and can be plain JSON or a binary format.
- Delivery
- The server sends the payload to the platform‑specific push service (APNs for iOS, FCM for Android, or Web Push for browsers).
- The push service receives the device token and routes the message through a secure channel (TLS) to the device.
- When the device is online, the OS displays the notification immediately. If the device is offline, the push service queues the message until the device reconnects, respecting a maximum age (usually 7 days).
- Upon user interaction, the OS launches the app and passes the payload data for in‑app handling.
Choosing a Push Service
Developers often select a push service based on platform, scalability, and feature set. The two dominant services are Apple Push Notification service (APNs) for iOS and Firebase Cloud Messaging (FCM) for Android. Web applications use the Web Push protocol, which relies on service workers and the Push API.
- APNs: Requires an Apple Developer account, supports rich media, and enforces a 2 KB payload limit.
- FCM: Free, supports high‑volume traffic, and offers advanced features like topic messaging and device groups.
- Web Push: Works across browsers, uses VAPID keys for authentication, and allows offline delivery via the browser’s push manager.
Key considerations include:
- Platform coverage and the user base you target.
- Reliability of delivery and message size limits.
- Analytics and reporting capabilities.
- Cost structure (most services are free up to a large volume).
Common Problems
Even with a robust infrastructure, push notifications can fail. Understanding typical pitfalls helps mitigate them.
- Token Expiration
- Device tokens can change when the app is reinstalled or updated. The server must handle token refresh callbacks and update its database.
- Payload Size Exceeded
- APNs limits payload to 2 KB. Exceeding this truncates the message or causes delivery failure. FCM allows larger payloads but still recommends staying under 4 KB.
- Network Conditions
- Push services queue messages but drop them after a timeout. Devices on cellular networks may miss notifications if the connection is intermittent.
- User Permissions
- If the user revokes notification permission, the app will no longer receive messages. The app should detect this state and prompt the user to re‑enable notifications.
Cost Considerations
Most push services are free up to a very high volume. However, indirect costs can accumulate:
- Backend infrastructure for sending messages (compute, database, message queues).
- Developer time for handling token lifecycle, analytics, and user segmentation.
- Third‑party libraries or SDKs that may charge per message or per user.
- Data transfer costs on cloud providers, especially if you host your own push gateway.
For most applications, the direct cost of using APNs or FCM is negligible, but scaling to millions of users can push infrastructure expenses into the thousands of dollars per month.
Safety & Privacy
Push notifications can carry sensitive data. Protecting user privacy is essential.
- Never embed personal identifiers or passwords in the payload. Use opaque IDs and resolve them server‑side.
- Encrypt the payload if it contains confidential information; both APNs and FCM support optional encryption.
- Respect opt‑in status and provide a clear way to unsubscribe or silence notifications.
- Follow platform guidelines: iOS requires explicit user permission, Android requires a notification channel with a user‑visible name.
Alternatives
While push notifications are the most common channel, other methods can complement or replace them depending on context.
- Email: Reliable for long‑form content but slower and less attention‑grabbing.
- In‑app messages: Delivered when the user is active; useful for contextual prompts.
- SMS: High open rates but limited by carrier costs and regulatory compliance.
- Webhooks: For server‑to‑server communication, not user‑facing.
Frequently Asked Questions
1. Do push notifications work offline?
Push services queue messages until the device reconnects. However, the OS may discard messages after a set period (often 7 days). Therefore, messages are not guaranteed to arrive if the device remains offline for an extended time.
2. Can I send a push notification to all users at once?
Both APNs and FCM support topic or group messaging. You can publish to a topic that all subscribed devices receive, or use a device group for iOS. This is efficient for broadcast events like app updates.
3. How do I test push notifications locally?
Use the platform’s developer tools: APNs provides a sandbox environment, FCM offers a test key, and browsers support service workers that can be run in a local server. Tools like Postman can send test payloads to the push service.
4. What happens if the user deletes the app?
When an app is uninstalled, the operating system invalidates the device token. The next time the app is installed, a new token is generated, and the server must update its records. Sending to an old token will result in a “BadDeviceToken” error.
5. Is there a limit to how many notifications I can send?
APNs and FCM do not impose hard limits on the number of messages, but they enforce rate limits to protect infrastructure. Exceeding these limits can temporarily block your app’s ability to send new messages.