About problems and solving the task of delivering push notifications to millions of devices on various platforms

Original author: Elio Damaggio
  • Transfer
  • Tutorial
Push notifications are critical for mobile applications connected to the Internet. They allow the services backend to send frequent and timely updates to specific users and devices, which can then be presented in the form of live tile updates, pop-up toast notifications, badge updates, and so on (refer to this series of articles to learn more). Posing as such, push notifications are perhaps the most powerful client engagement mechanism available to application developers on phones, tablets, and PCs.

push fig1

There are many tools available to help you make push notifications easier ( Windows Azure Mobile Services, for example, already includes such functionality). Using these tools, sending separate notifications to one individual user is a relatively simple task. Nevertheless, the constant sending of notifications with low latencies to millions of mobile users, taking into account the real requirements for localization, support for different mobile platforms, personalization for the user, is becoming a much more difficult task.

The main reason for all the difficulties is that push notifications are sent to devices using platform-specific services. For example, you will need to use the Windows Notification Service (WNS) to send push notifications to applications from the Windows Store, the Microsoft Push Notification Service (MPNS) for Windows Phone, the Apple Push Notification service (APNs) for iOS, and Google Cloud Messaging (GCM) for Android.

All these platform services work using the ChannelURI channel requested in advance, specific for each user, device, application, which is stored somewhere on the backend. Then, while sending a notification, the application backend sends data via the ChannelURI channel in order to reach the necessary device. One complication is added to this - ChannelURI channels may expire over time (and therefore they must be constantly updated on the backend). In addition, a single device may have several simultaneous active ChannelURI channels. During the development of applications for several platforms, these problems immediately increase, since each platform processes push notifications in its own way.

push fig1
Push Notification Life Cycle

Imagine a scenario in which you want to send notifications of hot news, and each user can subscribe to different categories. In this scenario, we get approximately the following table of data that will be stored in the database:
Device idPlatformChanneluriCategoriesLanguageClientVersion
1Windowschannel.uri / 1{“World”, “Business”}EnglishV1.1
2WindowsPhonechannel.uri / 2{“Technology”, “Sports”}FrenchV2.0
Obviously, you will want to allow the user to have several devices, and if you need to handle localization of notifications and user preferences, then this approach to data will soon become problematic.

In addition, even if you consider that you wrote all the necessary code to manage the table above and the code needed to send notifications through each separate service, you can still encounter problems if your application (fortunately!) Succeeds. If you have thousands of devices that need to be notified, then the process of simply sorting through the devices in a loop to send notifications will not give your users the desired positive experience. This means, for example, that delays in delivering notifications very quickly become unacceptably high, and you will not be able to restore the process if something happens in the middle of the notification cycle. Obviously, even if you solve these problems by storing device information in several databases (sharding), creating many virtual machines,

To summarize: we just saw how the implementation of a practical solution with push notifications in your application can quickly become a big and difficult task. The main difficulty lies in processing device information (especially when developing multi-platform and localized applications) and scaling up the notification sending infrastructure for millions of devices. Now let's take a look at how Windows Azure Notifications Hubs simplify the process for you.

Why Notification Hubs?


Service Windows Azure Notification Hubs offers an extremely scalable infrastructure to send push notifications to help you effectively direct cross-platform, personalized push notifications to millions of users:

identity management device . Notification Hubs allow you to eliminate the need to store and manage device identifiers or URI channels that are used by the notification services of each platform (WNS, MPNS, Apple PNS, or Google Cloud Messaging Service). We, especially for you, ourselves safely process service responses, expiration of the device identifier, and so on for each of the PNS (Platform Notification Service).

Effective multicast and routing system based on tags and subscriptions. Devices can specify one or more tags during their registration in the Notification Hub. These tags show the user's interest in notifications about a set of topics (favorite sport / team, geo-location, stock index, logical user identifier, and so on). These tags do not need to be reprocessed or care about their relevance. They provide applications with a very easy way to send targeted notifications to millions of devices with just one API call, without the need for you to create your own notification routing infrastructure for each device.

High personalization. Notification Hubs offer a built-in template engine that allows you to set the form, format, and localization of notifications for your customers, leaving your own backend code clean and independent of the mobile platform.

Extreme scaling . Notification Hubs are optimized to send push notifications to millions of devices with very low latency. Each instance of the Notification Hub can handle up to 5 million devices out of the box. And your own backend should send only one message to the Notification Hub and notifications will automatically be distributed to millions of your users without the need to remake your application.

Cross-platform. With just one call to the Notification Hubs API, your mobile backend can send simultaneous push notifications to users on Windows Store, Windows Phone 8, iOS, or Android devices.

Use from any backend . Notification Hubs can be easily integrated into any existing server backend. be it .NET or Node.js, Java or PHP, Python or Ruby using the existing SDK or the open REST API. The service simply integrates with Windows Azure Mobile Services. It can also be used from server applications hosted in virtual machines both on Windows and Linux, in cloud services or websites.

Bing News: Using Windows Azure Notification Hubs to Deliver Hot News to Millions of Devices


One of the first applications that started using Windows Azure Notification Hubs from the very start of the public preview version (launched in January 2013) was the Bing News application, which is included in every PC with Windows 8.x and is available on devices with Windows Phone 8. Bing News needed the ability to instantly notify users of hot news. This could become a difficult task for several reasons:

Extreme scaling . Each Windows 8.x device contains the installed Bing News application, which means that from the very moment of birth, the application had to send hundreds of millions of hot news notifications to users every month.

Preferred Newsletter. Broadcasting push notifications to different markets, taking into account the interests of each user, requires an effective routing mechanism, subscriptions, and preference-based distribution logic.

Cross-platform delivery . Notification formats and semantics differ on different mobile platforms, tracking channels / device identifiers for all platforms can be a difficult process.

Windows Azure Notification Hubs have become the perfect solution for Bing News. Along with recent application updates, they began using Notification Hubs to deliver push notifications daily to millions of users on Windows and Windows Phone.



The Bing News application on the client receives the corresponding ChannelURI from the Windows Notification Service (WNS) and Microsoft Push Notification Service (MPNS) for Windows and Windows Phone, respectively. Then, the application registers these channels in the Windows Azure Notification Hub. When you want to deliver notification of hot news in one of the markets, the application uses Notification Hubs to deliver relevant messages to all devices. With just one call to the Notification Hub API, a service can automatically filter clients by interests (for example, a sports message) and deliver messages to millions of customers without delay: Overview of the Bing News push notification architecture

push fig2


Windows Azure takes all the logic for filtering and selecting users and devices and efficiently delivers messages with low latency.

Getting started with Notification Hubs


You can try Notification Hubs in Windows Azure by creating a new Notification Hub through the Windows Azure Management Portal. Select the Service Bus Notification Hub element in the New -> App Services dialog :



Creating a new Notification Hub will take less than a minute, after creating it, you can open the control panel and start monitoring the service. Among other things, you can monitor the number of devices that are currently registered, the number of messages that were sent, the number of successfully delivered messages, the number of delivery errors:



Just configure your credentials received from the Windows Store in the Configure tab:



And that’s all what you need to run the Notification Hub.

In a Windows Store application that uses the Windows Store device SDK , you can register in your Notification Hub with a simple call:

await hub.RegisterNativeAsync (channel.Uri, new string [] {"myTag", "myOtherTag"});

Notification Hubs do not yet offer an official SDK for WinJS, but you can see an example of how to use the open REST API for such solutions to make a call with the following code:

hub.registerApplicationAsync (channelUri, ["myTag", "myOtherTag"]);

Finally, when you need to broadcast a message to all clients, simply call:

var toast = @ "Hello everybody!";

await hub.SendWindowsNativeNotificationAsync (toast);

Notification Hubs support any XML format that is available for WNS (even newer templates for Windows 8.1). To send a notification, simply create the correct XML-code following the recommendations of Windows and use the same method as in the previous code example (for example, you can add another binding for tiles with a size of 310x310 pixels):

var tile = @ "";
tile + = @"";
tile + = @"";
tile + = @" ";
tile + = @"Hello World! My very own tile notification";
tile + = @"
";
tile + = @"";
tile + = @"Hello World! My very own tile notification";
tile + = @"
";
tile + = @"
";
tile + = @"
";

hub.SendWindowsNativeNotificationAsync (tile);

Additionally, we offer ready-made SDKs for Windows Phone 8 , Android and iOS . Also, do not forget that you can use Notification Hubs from .NET, backend, Windows Azure Mobile Service and generally from anywhere using the Node.js SDK and open REST API.

After you create your application, scale it to millions of users directly from the Windows Azure management portal:



And get diagnostic information about your notifications from dozens of metrics:



Conclusion


With Notification Hubs, you can add push notifications to your application without writing code to manage devices or provide cross-platform support. Quickly set up interest groups and send notifications to millions of devices without any extra work. Start learning the Notification Hubs right now on the Notification Hubs service page or go straight to the Getting Started with Notification Hubs tutorials or tutorial video . If you still do not have a Windows Azure account, you can sign up for a free trial and start using the service today.

useful links


Below you will find links to resources that will help you use the Microsoft cloud platform:


And if you are already developing on Windows Azure or want to find developers of your service, visit the appprofessionals.ru service .

We will be happy to answer your questions at azurerus@microsoft.com . And look forward to seeing you in the Windows Azure Community on Facebook . Here you will find experts (do not forget to ask them questions), photos and a lot of news.

Also popular now: