![Page 1: Delivering push notifications to millions of mobile devices](https://reader033.vdocument.in/reader033/viewer/2022051118/568163f7550346895dd58c5c/html5/thumbnails/1.jpg)
Delivering push notifications to millions of mobile devicesTamara PanovaDeveloperDataArt
![Page 2: Delivering push notifications to millions of mobile devices](https://reader033.vdocument.in/reader033/viewer/2022051118/568163f7550346895dd58c5c/html5/thumbnails/2.jpg)
Why Notification Hubs?Push is essential to the user experience of many apps.Increase user engagement.• Update tiles/widgets with current financial/weather information.• Display badges with the number of current sales leads in a CRM app.
Real world apps have complex needs.Multi-platform push.Localization.User preferences.Different client app versions.Scale.
Windows News app uses Notification Hubs
![Page 3: Delivering push notifications to millions of mobile devices](https://reader033.vdocument.in/reader033/viewer/2022051118/568163f7550346895dd58c5c/html5/thumbnails/3.jpg)
Push notificationsPush notifications require a platform specific service.Each platform (Windows Store, iOS, Android, …) has a different push notification service.Different capabilities and protocols.An e2e solution requires lots of back-end code.Store and keep up to date the device information.Implement platform-specific protocols.
![Page 4: Delivering push notifications to millions of mobile devices](https://reader033.vdocument.in/reader033/viewer/2022051118/568163f7550346895dd58c5c/html5/thumbnails/4.jpg)
Push notification lifecycleRegistration at app launch.1. Client app contacts Platform Notification Service,
to retrieve current channel (e.g., ChannelURIs, device tokens, registrationIds).
2. App updates handle in back-end.Sending Notification.3. App back-end send notification to PNS.4. PNS pushes the notification to the app
on the device.Maintenance.5. Delete expired handles when PNS rejects them.
PlatformNotification
Service
App back-end
Client app
![Page 5: Delivering push notifications to millions of mobile devices](https://reader033.vdocument.in/reader033/viewer/2022051118/568163f7550346895dd58c5c/html5/thumbnails/5.jpg)
Challenges of push notificationsPlatform dependencyDifferent communication protocols to PNS’ (e.g., HTTP vs. TCP, xml payload vs. JSON payload).Different presentation formats and capabilities (tiles vs. toasts vs. badges).RoutingPNS’ provide a way to send a message to a device/channel.Usually notifications are targeted at users or interest groups(e.g., employees assigned to a customer account).App back-end has to maintain a registry associating device handles to interest groups/users.ScaleApp back-end has to store current handles for each device high storage and VM costs.Broadcast to millions of devices with low latency requires parallelization (DB ad VM).
![Page 6: Delivering push notifications to millions of mobile devices](https://reader033.vdocument.in/reader033/viewer/2022051118/568163f7550346895dd58c5c/html5/thumbnails/6.jpg)
Using Notification HubsOne-time set upCreate a Notification Hub in Service Bus.RegisterThe client app retrieves its current handle from the PNS.Client app creates (or updates) a registration on the Notification Hub with the current handle.Send NotificationThe app back-end sends a message to the Notification Hub.Notification Hub pushes it to the PNS’.
APNs WNS
Notification Hub
App back-end
iOS app Windows Storeapp
![Page 7: Delivering push notifications to millions of mobile devices](https://reader033.vdocument.in/reader033/viewer/2022051118/568163f7550346895dd58c5c/html5/thumbnails/7.jpg)
Advantages of using Notification HubsNo platform-specific protocols.App back-end just communicates with the Notification Hub.Avoid storing device information in the app back-end.Notification Hub maintains the registry of devices and the associations to users/interest groups.BroadcastPush notifications to millions of devices (across platforms) with a single call.
![Page 8: Delivering push notifications to millions of mobile devices](https://reader033.vdocument.in/reader033/viewer/2022051118/568163f7550346895dd58c5c/html5/thumbnails/8.jpg)
Demo
Getting started with Notification Hubs
![Page 9: Delivering push notifications to millions of mobile devices](https://reader033.vdocument.in/reader033/viewer/2022051118/568163f7550346895dd58c5c/html5/thumbnails/9.jpg)
Register a Windows Store appvar hub = new NotificationHub(“<hub name>", "<connection string>");
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
await hub.RegisterNativeAsync(channel.Uri);
![Page 10: Delivering push notifications to millions of mobile devices](https://reader033.vdocument.in/reader033/viewer/2022051118/568163f7550346895dd58c5c/html5/thumbnails/10.jpg)
Broadcast a Windows notificationvar hubClient = NotificationHubClient.CreateClientFromConnectionString("<connection string>", “<hub name>");
var toast = @“<notification payload>";
hubClient.SendWindowsNativeNotificationAsync(toast);
![Page 11: Delivering push notifications to millions of mobile devices](https://reader033.vdocument.in/reader033/viewer/2022051118/568163f7550346895dd58c5c/html5/thumbnails/11.jpg)
Take-awaysNo need to store and maintain ChannelURIs.In your device local storage, in the cloud.Device registrations expire.No need to clean-up when app is uninstalled.Call RegisterAsync regularly.
![Page 12: Delivering push notifications to millions of mobile devices](https://reader033.vdocument.in/reader033/viewer/2022051118/568163f7550346895dd58c5c/html5/thumbnails/12.jpg)
Sending notifications to specific devicesTags as interest groups.1. Client app can register with a set of tags.2. Tags are simple strings (no pre-provisioning is required).3. App back-end can target all clients with the same tag.You can use tags also for:Multiple type of interest groups, e.g.,:• Follow bands: tag “followband:Beatles”.• Follow users: tag “followuser:Alice”.
Tag devices with a user ID.
Notification Hub
App back-end
Tag:”Beatles”Tag:”Wailers”
Tag:”Beatles”
![Page 13: Delivering push notifications to millions of mobile devices](https://reader033.vdocument.in/reader033/viewer/2022051118/568163f7550346895dd58c5c/html5/thumbnails/13.jpg)
Take-awaysStore the categories/tags.In your device local storage, in the cloud.Make sure to register regularly.Rule of thumb: “every app start, up to once per day.”
![Page 14: Delivering push notifications to millions of mobile devices](https://reader033.vdocument.in/reader033/viewer/2022051118/568163f7550346895dd58c5c/html5/thumbnails/14.jpg)
Tags as user IDsRegistering from device is not secure.Every device can register for any tag.Embedding credentials in the device works for “public” notifications (e.g., News apps).Register from back-end.1. Device does *not* contain the notification hub credentials.2. Devices authenticate with the app back-end to register.3. App back-end registers the device for the correct tags.Same registration patterns apply.Devices have to register regularly (registrations still expire).Store the required tags in your back-end.
Notification HubApp back-
end
![Page 15: Delivering push notifications to millions of mobile devices](https://reader033.vdocument.in/reader033/viewer/2022051118/568163f7550346895dd58c5c/html5/thumbnails/15.jpg)
Take-awaysWhen security is needed register from the back-endNo Notification Hub SDK required on the devices
![Page 16: Delivering push notifications to millions of mobile devices](https://reader033.vdocument.in/reader033/viewer/2022051118/568163f7550346895dd58c5c/html5/thumbnails/16.jpg)
Using templates for multi-platform pushRegistration.Client apps can register with a platform specific template, e.g.,• Alice’s Surface registers with
Windows Store ToastText01 template.• Bob’s iPhone with the Apple JSON template:
{ aps: {alert: “$(message)”}}.Send notification.App back-end sends a platform independent message: {message: “Hello!”}.Version independence.Templates can be used to abstract different client app versions.
Service Bus Notification HubApp back-
end
<toast><visual><binding
template=\"ToastText01\"><text
id=\"1\">$(message)</text></binding>
</visual></toast>
{aps: {
alert: “$(message)”
}}
{ message: “Hello!” }
Hello!
Hello!
![Page 17: Delivering push notifications to millions of mobile devices](https://reader033.vdocument.in/reader033/viewer/2022051118/568163f7550346895dd58c5c/html5/thumbnails/17.jpg)
Using templates for personalizationRegistration.Client apps can register with personalized templates, e.g., • Alice’s Surface wants to receive weather information in F degrees.• Bob’s iPhone wants weather information in C degrees.
Send notification.App back-end sends a message including both temperatures: {tempC: “23”, tempF: “73”}.Template Expressions.Template support a simple expression language:E.g., {‘Elio, ’+$(friend)+’ added you to ’+$(groupName)+‘ group’}.
Service Bus Notification HubApp back-
end
<toast><visual><binding
template=\"ToastText01\"><text id=\"1\">$(tempF)</text>
</binding></visual>
</toast>
{aps: {
alert: “$(tempC)”
}}
{tempC: “23”, tempF: “73”}
73
23