Duration 31:09
16+
Play
Video

Upgrade to Firebase Cloud Messaging

Todd Hansen
Software Engineer at Google
+ 2 speakers
  • Video
  • Table of contents
  • Video
2018 Google I/O
May 9, 2018, Mountain View, USA
2018 Google I/O
Request Q&A
Video
Upgrade to Firebase Cloud Messaging
Available
In cart
Free
Free
Free
Free
Free
Free
Add to favorites
4.64 K
I like 0
I dislike 0
Available
In cart
Free
Free
Free
Free
Free
Free
  • Description
  • Transcript
  • Discussion

About speakers

Todd Hansen
Software Engineer at Google
Subir Jhanb
Engineering Lead at Google
Jon Mensing
Software Engineer at Google

Todd has been working on Firebase Cloud Messaging for the past nine years focusing on performance, reliability, and scalability. Before Google, Todd helped build a county scale high performance wireless network while working for the San Diego Supercomputer Center. He earned both a masters degree in Geophysics and a bachelors in Computer Science from UCSD. He enjoys spending time with his family, hiking, woodworking, and amateur radio.

View the profile

Subir Jhanb is the engineering lead for Firebase Cloud Messaging and Firebase Predictions. With many years of experience in mobile technologies and distributed systems infrastructure, Subir has designed and built messaging APIs and backend solutions for all mobile and web platforms. Prior to Firebase, Subir was working on Android sync services and Google applications for Android.

View the profile

About the talk

Get the most out of both Firebase and Google Cloud Messaging (GCM) by moving to Firebase Cloud Messaging (FCM). This session will show the ease of switching, and all the advantages you get by migrating today. For example: by using the notifications composer, you'll get integrated analytics on how many users clicked on each notification. You'll also see how FCM optimizes message delivery reliability, without sacrificing the battery life of your user's phone.

Share

Alright. Hello everyone. Welcome to the station for 5 to start messaging. My name is to be 9 p.m. Today at 4 p.m. Go send WhatsApp. You know sgm is Google's reliable cross-platform message messaging service developers use the service to send you the notifications during messages to the applications across multiple platforms. And it's also seem to be integrated with Harvest what that means is that features like predictions a b testing analytics just works seamlessly with a 50mm and your touch base with all these today.

Talking about scale the infrastructure that powers this year is supporting more than 1 million active developer account today. And that means these developers are sending notifications to More Than 3 billion devices every week. There's a very large scale infrastructure. Well as severe mention Firebase Cloud messaging is apart of Firebase and Firebase is a set of products that helps developers like you to build better apps to improve apps ability and to grow your hair out from your first user to your million. This talk is focused on Firebase Cloud messaging specifically, but I'd

encourage you to look at the other products and features into the Firebase brand many of which will be showcased right here at IHOP. Fcm is the successor to GCM or Google Cloud messaging and for those of you who are familiar with DCM and especially for those you who rely upon it everyday have no fear fcm Builds on the exact same infrastructure is GCM many great new features in just a few minutes. We're going to talk about the new and improved client sdks the new Firebase Integrations and our new version send API which makes sending to

cross-platform targets easier than ever before. All right. So before we take a deep look into the Integrations and the features that John just mentioned I'd like to take a step back and understand some basic concepts in a cm to the most commonly used Kia send SMS to send a message to a particular a Penske what's happening behind the scenes is getting a token from the esteem cloud and it gets the token now this token get taxes and address for the device. So whenever you want to send a message to the device you need this token. Obviously be absent upload this to their

servers so that when it's time to send a message server knows how to reach this device. Server has two identical to that field and send a message on cloud figures out how to write this message to this particular instance regardless of what platform it is on. Another popular feature in a CMS topic messaging and a lot of developers use this feature when they use cases are to send the same type of notification to a large number of devices can be sending a news app notification to folks interested in certain topics a sports

app, for example notifying. Hey, there's an update on your team that you follow its that rot. In this case every device subscribes to top. I guess the one line code on The Blind Side and instead of sending one message for device. You only send one message to steam cloud and it stand out to all the devices connected really easy and scalable for developers to reach a large number of devices. Another way of sending and receiving messages from SMS to open a persistent connection from your application server to the fcm cloud. You can do this using the xmpp

and find that we have you can send messages to topics are directly to devices on this connection and you can also receive messages from your application a popular excuse for this is when developers want to notify that did a vacation has actually received a message so they cannot make other changes or 10 fall off notifications Etc. Let me talk to work a little earlier and I would like to highlight that latency is super important to us. We were will want to deliver your messages as fast as possible. As long as the devices are connected RV in network latency numbers. That means

time when the notification GS2 vfd embarking on Taylor's dispatch on the carrier Channel and impact negatively. Earlier in the presentation. We promise to give you a look at the latest and greatest Firebase Integrations. And that's exactly we're going to do now so far as deeply and seamlessly with all of the Firebase products including analytics a b testing predictions and more and these products all work together sooner just Stickley to help you produce more effective more understandable notifications for

users. So let's walk through a quick demo of those new features. So I said I'm an apple owner and my app works by encouraging team-based competition. So my users will have some sort of an army maybe a robot army and and they're going to fight against other armies like the Sparky Army and each team basically competes to get to the top of the leaderboard Fame and Fortune and Sue they can buy upgrades to their army with a premium currency that I called battle box. So one of the things that I like to do as an aponeurosis

send notifications to my users to bring that back into the game and I'm particularly interested in sending notifications to my paying users because they're the ones who actually keep the lights on in my company. So I have this idea that sending a message that appeals to team loyalty is going to be the best way to talk to these users and it's going to be better than the status quo that I have. So what I'm going to want to do is to build a Navy test to test that theory and here you see in this in this you I screen the beginnings of my 80s hats where I'm sitting up all the

parameters. This is an actual you ice cream from the Firebase console where you can set up such an AP test So I'll walk through some of these different items on the screen so you can understand what's going on. First. We have the experiment name, which is really for me. So I don't lose track of what my test is trying to do is the theme text test which I practice saying many times before I got up on stage today. And the description is to test team now. I didn't didn't practice enough text vs. Status quo. I actually set up that problem for myself. So I have no one to blame.

This is going to be targeted towards my paying users using Firebase predictions. So with Firebase predictions another Firebase product. I'm actually able to Target the subset of my users who are predicted to spend based on their history within my app to automatically in by integrating the Firebase SDK. I get access to Firebase predictions and it's just a few clicks to turn it on here. I'm going to be targeting my users who are predicted to spend real. In my app because they're the Dead 2 user they care about for this test and I'm going to

send it to 5% of those users so I can test this on a smaller population before rolling out more broadly. So one quick Boyd, I'd like to highlight their is that if you have Google analytics events for spend and you've turned on predictions, you don't have to do anything you need at STK on top of that person's are available to you and will create be spending show in buckets. All right, very true. So what you can see through the flow this just kind of sits up the variance of my ADD test for those of you who are familiar with a t testing essentially just have different

experiences a b maybe see that your users can see and you just look at the the metrics of interest for each of those groups within your audience and whichever set of metrics you like the most that's the experience that you know is having an impact you wanted to have so this is essentially the three variants that I've got set up in this test that I was describing earlier. I've got a Varian a witch is going out to 33% of of the users in the test. And that's the old status quo. It's my boring old text that says get

20% off battlbox pretty generic and I've got very Envy which is the new hot version of my texts, which says Hey Sparky get 20% off a box with his coat. So that's appealing to Team spirit and in the Affinity that they'll have for the team, I think as a product manager, maybe that's going to do better than the old way of doing things. Both of these are going to be compared against the control group, which is no message at all. And at the end of this experiment all of our Delta's in our metrix user engagement. Those will be measured relative to not receiving a message of any sort.

Alright, alright more screen stuff in just a few clicks. You set up the goal for the test. My goal is user engagement. I want my paying users to come into the app. So that's the goal. I sent. I also want to check a few other metrics like retention and purchase Revenue so I can have a more holistic view of what's going on with this experiment and I'm going to look at all of these metrics together after my test is concluded to to be sure that the winning variance is really winning on all counts.

so Sometime in the future about 7 days later after I've sent out those messages to those different groups. I'm going to have a screen that looks something like this which tells me about the actual results of the experiment and what do you know? It turns out that the theory was was right. The themed text was the clear leader for this experiment and it actually did outperform the status quo and the control group so that had an improvement over control for user engagement. I'd also be able to dive into some of the other metrics like purchase Revenue to make sure that that wasn't

strangely adversely impacted or anything like that. But once I'm satisfied that variance see is actually the winter themed text. It's very easy for me to roll that out to the remaining population of my app by clicking the big blue button up at the top of the screen that says roll out the leader and then that message will go out to the remaining people in my app went and seen the message. So ask me no SPM best rastakhan service. That means you can send notifications to Android iOS Android application.

And what is API allows us to do is to override lock from specific parameters in a single request. What it also allows you to do is a service account with a tent acacian. So if you use any other Google API, it gives you chocolate Oakland to Santa Clara. Service Etc. Also integrated with fibers. Admin SDK. So if you're using a fight with admin SDK, all these features are already available, you have the convenience methods for authentication sending messages using this API cetera Deep dive into agnostic and a talk on that later today. So

if some things with it, if you are interested, please attend. Let's take an example of this API and let's say you want to send a message to your topic for sale Watchers. Now, these are people interested in sales that you can include them in items like tight and hurting them in a notification body. And now if you want to specify what will happen if somebody kicks on this notification on Android you have a field called quick action to tell which activity to go so you can specify died in the Android message. Section and then on iOS this field is called category

same purpose but different name so you can just find out in the APN as part of it and you can specify a specific task is to the platform so that they are rendered the way you expect them to the Future. So I recommend you checking this out. All right. So we've talked a lot about Firebase Cloud messaging and it Integrations in different features. If you're already have access to all this good stuff so job well done, But if you haven't moved from this game yet. It's time to upgrade.

I said exit walkthrough quickly on the steps that are needed to move from GCM to fcm and I'll cover each of these quickly first else to have a few clicks on the 5 with console in RDR have to type. It is still for each Android application. You'll have to enable 5s for that application steps are specific to Android. Next step is to change your dependency. So instead of hinder Bill gratifying instead of using Play services GCM. You should move to fight with messaging. Another fun stuff. Let's start taking things out of our manifest. So you don't need to declare any

formations with FTM. These are automatically handled by the STK so you can just take these out. And if you go do you think you see any family had these receivers? You don't need these anymore either you can take them out the sem STK automatically merges into receivership need. Turn on the server side. When you talk to me a CM Cloud, you should have paid the entrance to the fcm and point. We highly recommend you doing this. The request response format is a thing your request would be everything look as if you just need to update their URL. I lost my son coach changes on the client

site and you need to move to the new messaging service private messaging service. It has the same method for when you receive a message call Don message received all your logic Remains the Same. Can you also need to move to the 5 attend Society service, which also has the same method as before like on token refresh? That's it. That's it. We have a migration guide at the LINQ mentioned here if you want more details and it also covers of the black pumps. Okay. Well that is not so bad. But we

have picked up a couple tips along the way that we'd like to share with you starting with the first one let fcm manage your registration retry logic to be the case that in GCM. It's possible to to not get a valid registration token back from the GCM cloud and fcm. We automatically handle all of the retry Logic for you. So you don't need to replicate the old code that you would have had in your GCM implementation. So just let him handle it. It'll do it a second tip avoid using GCM and fcm in the same app at

the same time because they'll try to do the same things and potentially conflict with each other. So when you're moving from GCM to fcm just start clean clean out your GCM implementation and put the fcm implementation and place. That's the way to do it the third tip. Store one token for app instance. They are mutually interchangeable between GCM and fcm. So you don't need to maintain separate lists of tokens between GCM and fcm. All you need is one list of tokens. They're just tokens and when you replace a GCM token for a particular app instance, make sure you replace that

token rather than a pending it to the list for doing something else those tokens do translate to the same app instance and finally make sure that your periodically refreshing your tokens. So you get a valid token at all times and severe has some more details about that last point. I do go fund stock around 40% notifications for devices and tokens which are invalid. These are tokens which have an unregistered. They have been invalidated browser platform for Tetra. You are storing these tokens even have a 58 of your devices. So, how can we fix it?

But you can do two things. First is to have The Observers in the on token refreshment. This is an example of an iOS. So when you get there, you should upload the latest open to your server in overnight estate on the server as soon as possible after you always have the most accurate way to be sure devices. Again, this is the colored on Android. Same logic when you get on token refresh. Do you get Oakland uploaded to your server? Second thing you can do is periodically refresh your tokens. And what does they got some frequency? Just keep uploading the tokens from your device to the

service. Are you at all times have our first date on the server side? And also you clean up the tokens that you had a few Stephen Hawking use any more depends on us, but we should be good enough. All right with that said let's do it before but is a fans who had fears about delivery and Battery impact. Write most of you raise your hands. That's a good sign on how we can get the best performance from SDF and for that let's have. Hanson on stage. Thank you, sweetie. Hey, John. All right. So for the rest of the session today, I'm basically going to ask Todd

all of my burning questions about fcm performance so he can tell us all how to make high-performing apps with fcm and I'll start with our very first question here Todd, please tell us what are the newest version of Android doing to improve battery life. And what are the implications for fcm? So Android versions as recent as far back as marshmallow can be doing things that impact your battery life. Let's examine those and see what those changes are. And then we also talked about how you can make sure that if Sims continues to perform while on your app

So marshmallow and nougat introduce toes and dos on the go battery saving features which disabled some activities when the screen was turned off and reduced to fcm message priorities to allow user to allow apps to decide whether the message should be able to wake the device up when it's in those or not. Then comes Oreo Oreo added background check which prevents the apps from running in the background for too long. So this means that you can run in the background for a short. Of time. And then after that you can't run the background longer. We also introduced a temp

whitelist, which allows you to to access the network for a few seconds after receiving a high priority message. Neither of these were intended to be sufficient for all applications on all Network conditions. We will talk about more in a few minutes in November existing apps in the Play Store will be required to Target. Oh so many of you are just now starting to deal with these challenges as your updating apps. We're here to help. Android P. Introduces app standby buckets of sand by buckets group apps based on their recency of use

and the frequency of use and provides restrictions. So that apps that aren't used as frequently will be less consuming a battery absent by buckets also changes. How fcm Works a little bit if it means that FTM high-priority messages should only be used for things that will generate a user interaction such as a notification or ringing the phone or something. So this is a snapshot from a co-worker's device and it shows you how different apps can be categorized based on the recency. And again the frequency, which they're used. This particular

coworker clearly has Gmail in the rear bucket and I sent him an email to find out why but he hasn't gotten back to me. So tomorrow there's a talk the talks more about app standby buckets and depth in general. That's a great place to go for now. We're going to concentrate on ftms impact or the impact FTM. So this table shows apps can buy buckets and their impact on a high-priority messages. You can see that message message priority messages have different photos for different buckets.

So clearly if you're in a rare bucket, you're only going to get five messages per day. If you exceed that amount. The messages will be delivered as normal priority, but there's more if you display a notification your application moves to the working set and that means that effectively if you only use High party messages for displaying a notification or other user actions, you won't be limited At All by the change. In addition if the app is opened. It'll move to the active bucket. And so similarly I won't be affected at all. So the situations in which you will potentially run

into challenges as when I say you display a notification to a disabled Channel or when you use a high priority message to trigger background work in those situations. You do not change your app standby buckets, and you could run into these limits. Alright next question for Todd. So just to summarize when should I use high priority? And when should I use normal priority? Okay, and the basic rules been the same since marshmallow used High party messages only for situations in which field generator use her actions such as a notification in addition. I also want to point out that you

should not you should not expect to be able to call to your server call home to your servers to get additional content before displaying a notification as the the background service mate. All right. So if I'm feeling maybe a little bit lazy what happens if I just leave everything in my app exactly how it is today? Like what's the problem with that? So let's look at an example and I'll propose a solution for you. Okay, we'll start by looking at a simple chat app. The main premise of this simple chat app is after this plane or after receiving a high party message, it goes and contacts the

servers to download additional content before display notification. Let's see. What happens when it targets. Are you? So we start to see some notifications not showing up. It's not very high and we don't maybe don't notice right away, but we start to get some complaints accumulating. So as we start to investigate we find the 5% of notifications are lost because the network access times out before we can even connect to our servers we look for then we find another 5% and notifications are lost because the background service times out before we can even complete retrieving all of the

content. So sooner or later you got an angry boss wondering why your app is broken. All right, that's a big problem. So a 10% loss rate is pretty bad. We could try and brute-force this we can solve this Maybe by letting the app run for a lot longer to get the failure rate down to under 1% We have to let the app run for seven minutes in response to each message. So clearly that's a lot of battery spend that were costing users. It could be possible that you know on a poor-quality network would have a really bad experience having their app run for seven

other device run for 7 minutes for every message and they might prefer to choose when to download that content. So let's go further. Okay, follow question since background run time can be limited. What's the right way to ensure that my notifications are actually going to be seen by all of my users. So clearly we need a better solution unless go into that now. So what we will do is we'll ramp limit the app to implement graceful degradation and graceful degradation is meaning that will always display the notification

even if we can't get the content from the servers. So the following steps of graceful degradation are here first to display a notification immediately. You can often use the payload of a of an FC a message to display the content. If if that's not sufficient. You can just play a placeholder. Then you schedule a job to go and collect the information in the background if that job completes, then you can update the notification if that's appropriate if user opens the app before the job completes, then you would display spinner and start the job immediately to collect that

data. If you do this, right, I believe the very few users why she noticed this difference in those few users will be on for Quality networks. And so that will appreciate the extra battery savings. Straight sorry, I think I understand how to handle down to messages now. Can you tell me how these background limits apply to client to server messages? Yes. So back on restrictions apply to whenever your app is running in the background. That's what you're doing. So our simple chat app sends outgoing messages using the background service. And so

we see that sometimes that background service times out before the message is sent especially if we have to retry sending the message multiple times because of say tissue or something. So one solution that you could do as you could use a foreground service to send these messages. However, a better solution would probably be to use FTM Upstream messaging which handles to work for you in a more efficient manner it handle three tries and maintaining the connection and ensuring that the message gets there. Okay, son. Well, there's more to life than Android

as this message or this drawing here somehow demonstrates. I'm not sure exactly how but do you have some more General tips about understanding and improving the performance of FTM? So let's walk through the flow of a message through fcm. So this diagram as we saw before shows how you're sending a message from your servers through fcm to the device. Will start bags. I mean when you send messages to a c and servers are already alluded to 40% of messages are targeted in active devices. Those are devices that have been connected to our servers in over a month some Engineers

think the deleting registration tokens upon receiving are not registered is sufficient to solve this. However, we only send are not registered when we are absolutely certain that that registration is no longer valid. So that means you can accumulate a large list of invalid inactive device registrations and your registration list. A better solution is to periodically refresher FTM token again something that severe talked about earlier this while often returned the same token, although it may updated in certain conditions, but most importantly this refreshes your registration targets

that you can easily start to identify an active devices by looking at which ones haven't registered recently so I clear out my old registration time. So I have just one more question for you earlier sabir said that me and latency for FTM is around 70 milliseconds. And when I test my app, I experienced late and sees over 300 milliseconds. What's up? Okay, let's look at the messages as they depart FTM servers to the device Network latency add significantly to the latency That You observe for example of the 80% tile latency for FTM servers to dispatch dispatch a message to you is 120

milliseconds. However, when we had Network latency into account, we find that latency jumps to 300 350ml seconds. I think you should should probably get a better Network. All right. my Google I was lying really about one last question. This is my real last question right here. So I don't get messages when my phone is turned off. I think most people are probably in the same boat are a lot of message deliveries affected by the same situation. Yeah. So what we see is that You know device availability varies dramatically around the

globe, but on an average, we see about 11% of messages are delivered two devices that haven't been connected in the last hour. So that means that when you're sending messages to devices some of portion of your devices could be as high as 11% could be hired if you know where you're located. Are off line at that point and they'll receive the message when they get online. And so we really do recommend that you take it those users into account and make the app work. Well, even when these aren't available they could be reasons that they're doing that like an airplane ride or something like that.

Yes. That's what I do. Okay. Thank you very much Todd for all of your great answers to our performance questions. If you'd like to learn more about fcm or if you just like to stop by and say hello will be intent be able be tomorrow morning at 8:30 a.m. Until 9:30 a.m. Will be there smiling with cup coffee. Please come and see us. and finally Oh, well, wait back. That's the one we want to hear from you. We love to hear your feedback on this session. Please go to the link

on the screen google.com schedule leave some feedback. We love to know what you thought. Thank you.

Cackle comments for the website

Buy this talk

Access to the talk “Upgrade to Firebase Cloud Messaging”
Available
In cart
Free
Free
Free
Free
Free
Free

Access to all the recordings of the event

Get access to all videos “2018 Google I/O”
Available
In cart
Free
Free
Free
Free
Free
Free
Ticket

Interested in topic “IT & Technology”?

You might be interested in videos from this event

September 28, 2018
Moscow
16
166
app store, apps, development, google play, mobile, soft

Similar talks

Naveen Agarwal
Federated Identity Team at Google
+ 3 speakers
Luke Camery
Product Manager at Google
+ 3 speakers
Treffyn Koreshoff
User experience researcher at Google
+ 3 speakers
Steven Soneff
Product Manager at Google
+ 3 speakers
Available
In cart
Free
Free
Free
Free
Free
Free
Jumana Al Hashal
Product Leader at Google
+ 1 speaker
Todd Kerpelman
Developer Advocate at Google
+ 1 speaker
Available
In cart
Free
Free
Free
Free
Free
Free
Fergus Hurley
Product Manager at Google
+ 2 speakers
Wojtek Kaliciński
Android Developer Advocate at Google
+ 2 speakers
Joel Newman
Android/Play Business Development Product Specialist at Google
+ 2 speakers
Available
In cart
Free
Free
Free
Free
Free
Free

Buy this video

Video

Access to the talk “Upgrade to Firebase Cloud Messaging”
Available
In cart
Free
Free
Free
Free
Free
Free

Conference Cast

With ConferenceCast.tv, you get access to our library of the world's best conference talks.

Conference Cast
572 conferences
22795 speakers
8497 hours of content
Todd Hansen
Subir Jhanb
Jon Mensing