Overview of Push Notifications

In this article, I am going to design the architecture for implementing push notifications for you mobile application. This part only has design and architecture information, code will be covered in Part 2.

If you are new to push notifications, please read wiki article about the technology and also about GCM and APN services.

Below diagram depicts a high level overview of device registration process.

DeviceReg

  1. Device sends sender ID, application ID to GCM server for registration.
  2. Upon registration Cloud Service (GCM/APNs) sends a unique registration ID to the device.
  3. After receiving the registration ID from the cloud service the device will forward the registration ID to the Push Notification Web Service.
  4. The Push Notification web service will store the registration ID in a local database for later use.

a. Whenever Push Notification service needs to send the notification, it has to call GCM/APN service with registration ID of the device which is stored in the database.

b. GCM/APN service will deliver the notification to respective mobile device based on the registration ID.

Push Notification service would require an outbound internet connection to send messages to cloud services. Make sure to open two outbound ports on your push notification server.

Push Notification Components

You would need to implement two components:

  1. Push Notification Web Service

Push notification web service could be a rest service. Bare minimum the web service should have two functionalities. One, to register new device and Second, to unregister a device.

  1. Push Notification Windows Service.

You need to implement a windows service which could spawn multiple threads to listen to a messaging queue at a specified address. This service should be capable to pick up messages as and when it arrives to the messaging queue. The service will then query the local database and get a list of eligible devices which should receive the notification message and communicate with the cloud messaging services to get the notifications delivered.

Push Notification Windows service is a Microsoft Windows® terminology. On non-windows platform this windows service will be a process which will be initiated with a start-up batch file which could be hooked up with tomcat initialization process.

Push Notification Architecture

Diagram below depicts the push notification architecture at high level.

HLD

  1. As depicted in the diagram above, the first step is get the unique device ID from the cloud messaging service. The mobile application should make a call to the cloud messaging service every time it is launched. It is important to make this call every time as it may so happen that the unique device ID assigned earlier has now expired.
  2. Second step is to call the Push Notification web service from the mobile application and include the unique device ID (received from cloud messaging service) in the payload. You may want to pass some additional information like the device type, device operating system etc in the payload. A sample payload JSON is shown below:
    [sourcecode language="javascript"] DevicePayload:{ deviceId:'APA9sdsdA', deviceType:'mobile/tablet', deviceOS:'android/apple', userID:'xyz@gmail.com', } [/sourcecode]
  3. Push notification web service will persist the payload in a local database.
  4. Core product which is responsible for generating events per user will create notification messages and publish it to the Messaging Queue.
  5. Push notification windows service’s functionality is to constantly poll the Messaging Queue and pull any new message that arrives to the queue. The service should then query the local database to get the device id associated with the user id for which the notification was generated.
  6. With the fetched device id, the windows service will then communicate with cloud messaging services (GCM/APN).

This is the architecture at high level to design push notification service for your mobile application. In the next article (Part-2), I will cover the code required to communicate with the cloud messaging services.