Mobile Push Notification Integration
What you'll learn: How to coordinate in-app real-time updates with push notifications so offline or background mobile users stay informed without wasting resources.
The Coordination Challenge
When users are actively viewing your social feed, WebSockets or SSE deliver instant updates. But what happens when they close the app or their phone locks? They need push notifications to bring them back. The key challenge is avoiding duplicate alerts (push + in-app), detecting user state, and routing updates appropriately.
Core Architecture
Your real-time update system needs a presence service that tracks:
- Active users (WebSocket connected): deliver via real-time channel only
- Background users (app open but not viewing): trigger in-app badge updates
- Offline users: send push notifications via APNs (iOS) or FCM (Firebase Cloud Messaging for Android)
When your fanout service generates a new post for a user's timeline, it queries the presence service:
if user.isActiveInFeed():
send_via_websocket(update)
elif user.isAppBackground():
increment_badge_count()
else:
send_push_notification(user.deviceToken, update)
Integration Points
- Device token registration: Store tokens when users log in on mobile
- Notification payload: Include deep-link data so tapping opens the specific post
- Deduplication window: If a user comes online within seconds of a push being sent, suppress the in-app alert
- Batch notifications: Don't send 50 pushes for 50 new posts; aggregate: "15 new posts in your feed"
Cost and Rate Management
Push notifications cost money per send and have platform rate limits. Apply notification throttling for low-priority updates and respect user preferences (mute hours, frequency caps).
Key Takeaway: Mobile push notification integration requires presence-aware routing that sends real-time updates to active users and push notifications to offline users, with careful deduplication and aggregation to avoid alert fatigue.