Push Notifications: Mobile and Web
What you'll learn: How mobile apps and web browsers receive push notifications through platform-specific services like APNs, FCM, and browser push APIs.
The Core Mechanism
Push notifications allow your server to send messages to users' devices even when your app isn't running. Instead of directly connecting to millions of devices, you use platform-specific notification services as intermediaries—Apple Push Notification service (APNs) for iOS, Firebase Cloud Messaging (FCM) for Android, and browser vendors' push services for web.
Think of it like this: You're a postal service (your backend). Instead of delivering mail directly to every house, you give packages to regional postal hubs (APNs/FCM/browser services) that handle the final delivery. You just need to know each house's address (device token).
Device Token Registration Flow
- User installs your app → App requests notification permission
- Platform service issues unique device token → A long string identifying this device + app combination
- App sends token to your backend → You store it in your database linked to the user
- When you want to notify the user → You send the message + device token to the platform service
- Platform service delivers to device → User sees notification
Platform-Specific Details
iOS (APNs): Requires certificates or token-based authentication. Tokens can become invalid if users uninstall your app or revoke permissions.
Android (FCM): Uses API keys for authentication. FCM also handles message queuing and retry logic automatically.
Web Push: Uses VAPID keys and service workers. The browser vendor runs the push service (not a single provider like APNs/FCM).
Critical Considerations
Token management is ongoing—devices change tokens, users uninstall apps, or revoke permissions. Your system must handle invalid token removal to avoid wasting resources on dead endpoints.
Key Takeaway: Push notifications route through platform services (APNs, FCM, browser push) using device tokens for addressing. Your backend registers tokens per user-device and sends notifications through the appropriate platform gateway.