How Do Push Notification Works

Push Notifications are the clickable mesaage that are sent from a website or mobile app on your device to alert you something. You can subscribe and receive notifications on your desktop or phone.

There are two kinds of push notifications :

Both Web / Browser Push Notification and Mobile Push Notification are similar except the fact that Web / Browser Push Notification work on websites and can be accessed on all devices (desktop, mobile, tablet, etc) and Mobile Push Notification work on apps and can be accessed on mobile only.

How do Mobile Push notification Works :

Mobile Push Notification are actionable messages that are sent from a mobile app to its users on their mobile device. If the user is not active on the app or even the mobile device, these messages get delivered in real-time and appear on the lock screen and notification slider of the user’s mobile phone. These messages are supported by all major mobile platforms like iOS, Android and Windows.

In Android Device :

Google developed a mobile push notification service commonly reffered as GCM (Google Cloud Messaging). It enables third-party mobile application developers to send push notifications from server to applications on Google’s Android Operating System. It was launched in 2012.

The steps below explain how push notifications work on Android devices.

  1. When an app is installed, the Android device sends a sender ID and application ID to the Google Cloud Messaging server for registration.
  2. Upon successful registration, Google Cloud Messaging server issues a registration ID to the Android device.
  3. After receiving the registration ID from Google Cloud Messaging server, the android device will send the registration ID to your server.
  4. Your server will store the registration ID in the database for later use.
    1. Now whenever a push notification is requested, your server sends a message to the Google Cloud Messaging server along with the device registration ID which was stored in its database.
    2. The GCM server will then deliver your push notification message to the respective mobile device according to the device registration ID.



In IOS Device :

Apple Push Notification Service is a platform for mobile push notification service created by Apple Inc. which enables third party application developers to send actionable mobile push notifications to applications installed on Apple devices.  It was first launched with Apple iOS 3.0 in 2009.

The steps below explains how mobile push notification works in ios :

  1. Apple iOS application requests a device token ID for each unique device from Apple Push Notifications Service.
  2. The app receives the device token ID from APNS, which works as an address to trigger iOS mobile push notifications to.
  3. The mobile app the sends the device token ID to your server.
  4. Whenever a push notification request is prompted, the server will send a push notification with a device token ID to APNS and APNS will then deliver the mobile push notification to the the device with the token ID.



How do Web / Browser Push Notification Works :

There are two main requirements for Browser Push Notifications to work:

A. HTTPS – Web push notifications can only be implemented on HTTPS enabled domains to prevent man-in-the-middle attacks. But with a little workaround HTTP websites too can implement web push functionality.

B. Service Workers, push and notifications APIs should be supported by the browser else the service won’t work.

The steps below explains how Web / Browser Push Notification works :

  1. Website should be registered on the notification server like Google Cloud Messaging (GCM) service which will return you the API key. Consider this as a permission to receive user id data on your server when a user subscribes to your web notifications.
  2. Have a table in your database where you store user ids or tokens along with other data like subscription and unsubscribe date.
  3. When the user clicks on the ‘Subscribe’ or ‘Allow’ button for granting notification permission, his/her service worker (a script which runs in the background and allows notifications even when browser is closed) is registered and his subscription id is sent and stored on the push notification server and application server as well.
  4. The subscription id identifies a particular device so that the notifications are sent to the correct device.
  5. Now whenever you need to send a notification, the user ids are fetched from the application server and sent to the notification server which checks user-agent (device) for permission. If the permission is granted, the service worker sends a fetch request to the application server for message data to be displayed.
  6. If the user wishes to unsubscribe, a request is sent to the push notification server which clears the user’s id from its tables.



The process working of browser push notification is same in both Chrome and Firefox except the fact that the Push service is maintained by Mozilla for Firefox on the desktop. On Android, Firefox uses Google’s Cloud Messaging platform instead.