📜 ⬆️ ⬇️

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

Push notifications are critical for mobile applications connected to the Internet. They allow the backend of services to send frequent and timely updates to specific users and devices, which can then be presented as live tile updates, pop-up toast notifications, badge updates, and so on (refer to this series of articles to find out more). Introducing in this form, push notifications are perhaps the most powerful customer engagement mechanism available to application developers on phones, tablets and PCs.

push-fig1

There are many tools that can help you simplify the work with push notifications ( Windows Azure Mobile Services , for example, already includes this functionality). Using these tools, sending separate notifications to a single individual user is a relatively simple task. Nevertheless, the constant sending of notifications with low latency to millions of mobile users, taking into account the actual requirements for localization, support for different mobile platforms, personalization for the user becomes 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 have to use the Windows Notification Service (WNS) to send push notifications to applications from the Windows Store, Microsoft Push Notification Service (MPNS) for Windows Phone, Apple Push Notification service (APNs) for iOS, and Google Cloud Messaging (GCM) for Android.
')
All these platform services work using the pre-requested specific to each user device, application channelURI, which is stored somewhere on the backend. Then, while the notification is being sent, the application backend sends data via the ChannelURI channel in order to reach the required device. One complication is added to this - the relevance of ChannelURI channels may expire with time (and therefore they need to be constantly updated on the backend). In addition, one device can have several simultaneous active ChannelURI channels. During the development of applications for several platforms, these problems increase at once, as each platform handles push notifications in its own way.

push-fig1
Life cycle push notifications

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 will get approximately the following data table, which will be stored in the database:
Device IDPlatformChannelURICategoriesLanguageClientVersion
oneWindowschannel.uri / 1{“World”, “Business”}EnglishV1.1
2Windowsphonechannel.uri / 2{“Technology”, “Sports”}FrenchV2.0
Obviously, you will want to allow the user to have multiple devices, and if you need to handle the localization of notifications and user preferences, this approach to data will soon become problematic.

In addition, even if you consider that you have written all the necessary code to manage the table above and the code you need to send notifications through each individual service, you can still run into problems if your application (fortunately!) Becomes successful. If you have thousands of devices that need to be notified, the process of simply going through devices in a cycle to send notifications will not give your users the desired positive experience. This means, for example, that delays in the delivery of notifications will 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 information about devices in several databases (sharding), creating many virtual machines that will send notifications at the same time, periodically saving the progress of sending to disk storage, it will still be too difficult to implement as just a part of your backend.

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

Why Notification Hubs?


The Windows Azure Notification Hubs service offers you an extremely scalable infrastructure for sending push notifications that will help you effectively send cross-platform, personalized push notifications to millions of users:

Manage device IDs . 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 of the platforms (WNS, MPNS, Apple PNS, or Google Cloud Messaging Service). We, especially for you, safely handle service responses, expiration of the device identifier, and so on for each of the PNS (Platform Notification Service).

Efficient multicast and routing system based on tags and subscriptions . Devices can specify one or more tags when they are registered in Notification Hub. These tags show the user's interest in the topic set notifications (favorite sport / team, geo-location, stock index, logical user ID, and so on). These tags do not need to be re-processed or taken care of their relevance. They provide applications with a very simple way to send targeted notifications to millions of devices with just one API call, without you needing to create your own notification routing infrastructure for each device.

Highly personalized . Notification Hubs offer a built-in template engine that allows you to specify 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 for sending push notifications to millions of devices with very low latency. Each Notification Hub instance can handle up to 5 million devices out of the box. And your own backend should send just one message to Notification Hub and notifications will automatically be distributed to millions of your users without having to redo your application.

Cross platform With just one call to the API Notification Hubs, 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 available SDKs 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 on both Windows and Linux, in cloud services or web sites.

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 on every Windows 8.x PC and is available on Windows Phone 8 devices. Bing News needed the ability to instantly notify users of hot news. This could be 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 needed to send hundreds of millions of hot news notifications to users every month.

Mailing based on preferences . Broadcast push-notifications to different markets, taking into account the interests of each user, requires an efficient routing mechanism, subscriptions, and distribution logic based on preferences.

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

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



The client’s Bing News application receives the appropriate ChannelURI from Windows Notification Service (WNS) and Microsoft Push Notification Service (MPNS) for Windows and Windows Phone, respectively. The application then registers these channels with the Windows Azure Notification Hub. When you want to deliver a 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 API Notification Hub, the service can automatically filter customers by interest (for example, a sport message) and deliver a message to millions of customers without delay:

push-fig2
Overview of the architecture of processing push notifications Bing News

Windows Azure takes over all the filtering logic and user and device selection and efficiently delivers low latency messages.

Start using Notification Hubs


You can try the Notification Hubs feature 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 its creation you can open the control panel and start tracking the service. Among other things, you can monitor the number of devices that are registered at the current time, the number of messages that have been sent, the number of successfully delivered messages, the number of delivery errors:



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



And that's all it takes to get Notification Hub up and running.

In the Windows Store app that uses the Windows Store device SDK , you can sign up for your Notification Hub by simply calling:

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

Notification Hubs does 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 = @ "<toast> <visual> <binding template =" "ToastText01" "> <text id =" "1" "> Hello everybody! </ text> </ binding> </ visual> </ toast> " ;

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 Windows guidelines and use the same method as in the previous code example (for example, you can add another binding for tiles of 310x310 pixels):

var tile = @ "<tile>" ;
tile + = @ "<visual lang =" "en-us" ">" ;
tile + = @ "<binding template =" "TileWide310x150ImageAndText01" ">" ;
tile + = @ "<image id =" "1" "src =" "ms-appx: ///images/redWide.png" "/>" ;
tile + = @ "<text id =" "1" "> Hello World! My very own tile notification </ text>" ;
tile + = @ "</ binding>" ;
tile + = @ "<binding template =" "TileSquare150x150Text04" ">> ;
tile + = @ "<text id =" "1" "> Hello World! My very own tile notification </ text>" ;
tile + = @ "</ binding>" ;
tile + = @ "</ visual>" ;
tile + = @ "</ tile>" ;

hub . SendWindowsNativeNotificationAsync ( tile ) ;

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

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



And get diagnostic data 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 functionality. Quickly set up interest groups and send notifications to millions of devices without additional work. Start learning the Notification Hubs right now on the Notification Hubs service page or go straight to the Getting Started with Notification Hubs guidelines or tutorial videos . 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 in using the Microsoft cloud platform:


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

We will be happy to answer your questions at azurerus@microsoft.com . And we are waiting for you in the Windows Azure Community on Facebook . Here you will find experts (don't forget to ask them questions), photos, and lots and lots of news.

Source: https://habr.com/ru/post/200216/


All Articles