Did you play the interactive Google Doodle for the Mexican card game “Lotería” last December? If not, you can still check it out here. Lotería is a multiplayer bingo-style game that supports up to five players per room. In the digitized Doodle version, you can play with random people around the world or create a private game with your friends.
The Lotería game was developed in JavaScript primarily by one engineer over a few months, and the game's usage jumped from no players to millions literally overnight. The multiplayer component that supported it all was built entirely with the Firebase Realtime Database, which meant we could spend more time developing a great user experience, and less time worrying about infrastructure. Let's look into how we did it!
/games/{gameId}/deal = {card, time, countDown}
To detect the winner, all players listen to another database location at /games/{gameId}/winner. When a player clicks “Lotería!” and has a valid winning pattern on their board, we write their ID to that location.
/games/{gameId}/winner.
Often, there’s a close tie, so we use Reference.transaction to ensure that only the first player to call, “Lotería!” is declared the winner. We do this by making sure that /games/{gameId}/winner doesn’t already have an existing value before we write anything to that location.
Reference.transaction
/games/{gameId}/winner
To create random public games, we utilized Cloud Functions for Firebase in conjunction with the Realtime Database.
When a player selects “Random Match,” their player ID is written to the location /queue/. A Cloud Function is set up to trigger when a new entry is created, and it checks whether we have enough players to start a game. If so, it creates the game at /games/{gameId}, and writes the gameId to each player's entry, like so: /players/{playerId}/gameId = {gameId}
/queue/
/games/{gameId}
/players/{playerId}/gameId = {gameId}
Players listen to gameId on their own database entries, so they know when to transition to the gameplay screen.
gameId
Since there are a lot of players connecting simultaneously, and the Cloud Function is asynchronous, we once again used a transaction to ensure that players are removed from the queue and placed into games atomically. Making one game at a time atomically could create a bottleneck, so instead we create as many games as possible in one transaction.
Interactive Google Doodles get millions of players, so we needed to make sure that the database could handle the load. To do this, we sharded the database into multiple instances. Each instance can handle a limited amount of traffic, so we estimated how much traffic we expected to have. To do this, we wrote a load testing bot that could be run repeatedly and measured how much load this generated on a single instance. Then, we extrapolated that number to how many players we expected, which then gave us the number of instances we might need.
However, there is a downside to having too many instances: if players are spread too thinly, it might take longer for enough to connect to one instance to start a game. To solve this problem, we created an entry in the default database instance called “shards.” This was a number that could be adjusted from 1 to the maximum number of shards we created. Clients read this value and only used shards in that range. Since the Doodle was only live on the Google homepage for a short time, we updated the shards value manually through the Firebase Console, setting it lower when there was less traffic, and higher when there were spikes. Naturally, this process could be automated for a longer-running application.
Update: On Friday, February 28th, GDC 2020 organizers made the difficult decision to postpone the conference. We understand and support this decision, as we have to prioritize the health and safety of our community. Although we won’t be connecting in-person this year, we’re still excited to share the latest announcements from Firebase with you in a digital experience. Check back soon at g.co/gdc2020 for more details.
Cross-posting from the Google Developer Blog. Firebase will once again be at the Game Developers Conference to meet with you and share how we're making Firebase even more powerful for game developers!
We’re excited to see you at the upcoming Game Developers Conference (GDC) in San Francisco. Join us March 16th-20th, 2020 to learn about new products and solutions from Google that will help developers for all platforms take their game to the next level. If you can’t make it in person, sign up to keep up to date with our announcements and view the livestream.
Everything kicks off with the Google for Games Developer Summit Keynote on Monday, March 16th where product leaders from across Google will share the newest announcements for game developers. After the keynote, join in on two days of developer sessions and learn how to use Google solutions to create great games, connect with more players, and scale your business. Check out the agenda today.
Starting Wednesday, March 18th, visit our booth in the GDC Expo to experience demos and meet one-on-one with Google product experts.
If you can’t attend GDC in-person, watch the Keynote and other Developer Summit sessions via the live stream at g.co/gdc2020.
We’ll be sharing more details about what we have planned at GDC in the coming weeks — be sure to sign up to be among the first to hear the latest updates. On-site events are part of the official Game Developers Conference and require a pass to attend.
See you there!
See the full agenda
It's been over a year since we first announced Firebase In-App Messaging to help you guide app users who are actively using your app by sending them targeted and contextual messages. In-App Messaging allows you to communicate with your most valuable users and deepen their engagement by surfacing relevant offers, information, and tips as they use your app.
We have been actively working on adding more features and expanding on the capabilities of Firebase In-App messaging (such as new message layouts), and we’re excited to highlight another new feature today - the ability to auto-translate your message into multiple languages using Google Translate.
As your app user base expands into more countries and languages, it's important to make sure messages are localized for each recipient to improve engagement, and for that we have added an easy way to translate your message to many languages. To get started is simple.
1. First choose your message style and content.
2. Set your target criteria
Then in the targeting section, when you select your app, Firebase will look at your audience and determine if localizing message content would help, and provide you a helpful nudge to provide localized content:
3. Click on Localize, and you will see the following dialog.
The first section of the dialog contains the default language and strings to be localized. And if you would like to provide alternative translated messages, click on Localize next to the language you would like.
When you click on Localize, you can either enter the localized message yourself, or click on the Translate button and let Google Translate automatically do the translation for you.
4. Save your translations
Once you are done with all the translations, click on Save and continue completing the rest of the steps for your messaging campaign.
Unless you provide localized messages, all your users - irregardless of their locale - will receive the message in the default language. If you provide translations, users who’s locale matches available translations will get the localized message, and everyone else will get the default message.
We have a lot more product updates in the works for this year, and look forward to sharing them with you. If you are not already using Firebase In-App Messaging, then 2020 is the year to start. Get started today by checking out the documentation:
Getting started with Firebase In-App Messaging
Real estate investing is a fantastic way to build a stream of passive income and grow your wealth. Numerous studies have pointed out that real estate investing has created more millionaires throughout history than any other form of investing (like this one and this one). So why don’t more people do it?
I asked myself this very question a few years ago after talking to a group of friends about the success I’ve had with real estate, and listening to their reasons why they think it’s out of their reach.
A common theme among them was that they viewed it as something too difficult to learn and master. There were too many steps, the learning curve was steep and there was a lot of room for mistakes for somebody just starting out, especially when analyzing the financial performance of potential investment properties.
Traditionally, most investors used spreadsheets to do the math - which works only if you know what and how you’re calculating something. But if you don’t know that, it’s very easy to make mistakes and overlook things. And no one wants to make mathematical errors before a huge purchase like an investment property.
Where do I even begin?!
And that’s when I had the idea to build DealCheck – a cloud-based, easy-to-use property analysis tool for real estate investors and agents. I wanted to create a platform that would help new investors learn the ropes and avoid costly mistakes, but at the same time provide the flexibility to perform more advanced analysis with a click of a button.
Making real estate investing easier and more accessible.
I was working as a front-end engineer at the time, so I knew I could build the UI myself, but what about the back-end, data storage, authentication, and a bunch of other things you need for a full-functioning cloud app?
I didn’t know anybody I could bring on as a co-founder, so I set out to research what technologies and platforms I could leverage to help me with the back-end and server infrastructure.
Firebase kept popping up again and again and I began to look at it in more detail. It was then recently acquired by Google and its collection of BaaS (backend-as-a-service) modules seemed to offer the exact solution I needed to build DealCheck.
I was especially impressed with the documentation for each feature and how well all of the different technologies could be tied together to create one unified platform.
It wasn’t long before I signed up and started building the first MVP of the app.
As the only developer on the project, I had limited time and resources to spend on building the back-end, so I set out to use every Firebase feature that was available at the time to my advantage.
My goal was actually to write as little server-side code as possible and instead focus on leveraging the different Firebase modules to solve three specific challenges:
The first one was authentication and user management. DealCheck’s users needed the ability to create their accounts so they can view and analyze properties on any device (more on that later). I wanted to have the ability to sign in with email, Facebook or a Google account.
Firebase Authentication was designed specifically for this purpose and I used it to handle pretty much the entire authentication flow. Out-of-the-box, it has support for all the major social networks, cross-network credential linking and the basic account management operations like email changes, password resets and account deletions.
There was no server-side code required at all – I just needed to build the UI on the front-end.
Email, Facebook and Google sign in powered by Firebase.
And as an added benefit, Firebase Authentication ties directly into the Realtime Database product to create a declarative permissions and access control framework that’s easy to implement and maintain. This helped me make sure user data was protected from unauthorized access, but also facilitate data sharing among users.
Next up was data storage. I knew that I wanted DealCheck’s users to be able to use the app and analyze properties online, on iOS and Android. So I needed a real-time, cloud-based database solution that could sync data across any device.
Syncing data across web and mobile is not easy!
Firebase Realtime Database is a NoSQL, JSON-based database solution that was designed exactly for this purpose, and I was actually surprised how great it worked. I used the official AngularJS bindings for Firebase on the front-end to read and write to it directly from the client.
I had to do some extra work on mobile to implement an offline mode with syncing after reconnections, but all-together the code required to make everything work was minimal.
As I mentioned, Firebase Authentication tied directly to the database to facilitate access control, so I really didn’t need to do anything extra there. And I was able to set up automatic daily backups of all the data with a click of a button.
Up to now, I had written exactly 0 lines of server-side code and everything was handled by the client directly. As DealCheck’s development progressed, however, I knew that I would need a server to handle some operations that could not be done in the client.
I wasn’t very experienced with server maintenance and DevOps, but fortunately the Firebase Cloud Functions product was able to solve all of my needs. Cloud Functions are essentially single-purpose functions that can be triggered (or executed) based on a specific HTTP request or events coming from the Authentication, Realtime Database or other Firebase products.
Each function can be run once based on a specific event trigger to perform its prescribed task. You don’t have to worry about provisioning a server instance or managing load – everything is done automatically for you by Firebase.
What’s even cooler, is that Cloud Functions can access the Realtime Database and Cloud Storage buckets of the same project, performing operations on them server-side, as needed.
This is how DealCheck processes subscription payments through Stripe, validates Apple and Google Play mobile subscription receipts, integrates with third-party APIs and updates database records without user interaction.
Bringing in sales comparable data from third-party providers into DealCheck.
Cloud Functions became the “glue” that tied the entire back-end infrastructure together.
The first version of the DealCheck app was built and launched in less than 5 months with just me on the development team. I definitely don’t think that would have been possible without Firebase powering the back-end infrastructure. Maybe the project wouldn’t have ever launched at all.
While Firebase is awesome for quick MVP development, it’s definitely designed to power production applications at scale as well. As DealCheck grew from a small side-project to one of the most popular real estate apps with over 100k users, all of the Firebase products that we use scaled to support the increasing load.
Moreover, the fantastic interoperability of all Firebase modules allows us to develop and release new features much faster because of the reduced coding requirements and ease of configuration.
So next time you’re looking to build an ambitious project with a small team – take a look at how Firebase can help you reduce development time and provide a suite of powerful tools that scale as your business grows.
This is exactly how DealCheck grew from a simple idea to make property analysis easier and faster, to an app that is helping tens of thousands of people grow their wealth and passive income through real estate investing. It’s a truly awesome and fulfilling experience to see your work positively impact so many people and it wouldn’t have been possible without Firebase.
We know that the web is one of the largest platforms developed on across the globe. We want to meet developers where they are, no matter what platform that may be using.
At I/O earlier this year, we announced Firebase Performance Monitoring for web. It was our next big step in bringing the complete suite of Firebase products to the web. And just a few weeks ago, at the Firebase Summit, we announced support for web apps in Google Analytics, Cloud Messaging and Remote Config! These new features give you insight into your web users, what they are doing inside your app, and help you create personalized experiences for them - just like you already do on native. Let’s take a closer look at all that is new for web developers in Firebase.
At the heart of a successful app and business strategy lies data. Analytics helps you understand how your user base is growing, who these users are, and what actions they are taking in your app. You can then use these insights to build tailored experiences that will delight, engage and retain your users.
If you're already comfortable using Google Analytics for your native apps, the web version of Analytics should look very familiar to you. But if you are new to Firebase, there are a few key components in Analytics we want to highlight:
Analytics also has a feature called audiences, which provides a way to segment users along attributes that are meaningful to you. For example, you can create an audience comprising all the users who performed a specific sequence of events in your app. These audiences now also work for users on the web, and membership can even be evaluated across multiple platforms by setting the user_id in the Analytics SDK.
Let’s take the example of an e-commerce app and a product review feature. One important thing to track in such an app is users who started writing a product review, and then left without completing it. Using audiences, we can create a user segment that represents exactly this group of users.
Example sequence of events “Started session” > “Started review” > “Canceled review”
We can create an audience representing that sequence in the Audience builder shown in the screenshot below:
In the next two sections we will show you how to combine audiences with Remote Config & Cloud Messaging to create personalized experiences for your users.
Remote Config (now works on web) gives you the power to alter your app for any segment of users without requiring you to release a new build. For example, you can segment users by geo and date (like Christmas) and infuse a holiday color palette into your app.
Going back to the product review example, say you want to show a custom message when any user who’s part of the “Abandoned reviewers” audience opens the app. You can now use that audience as the targeting condition for your Remote Config parameters across both your web and native apps. You could even strategically roll out new features to target audiences across web and native, so you can monitor regression and roll it back if you run into any issues.
Cloud Messaging has already been available for web for quite some time. What's new is that FCM for web is now integrated with Google Analytics, which allows you to send targeted notifications to your users based on their behavior in your app. You can do this by leveraging both new web specific signals (like browser type) and Google Analytics’ custom audiences and user properties. It’s another great way for you to personalize your users’ app experiences.
What’s also new is that campaigns can be easily configured in the Firebase console. Additionally, the funnel report that tracks campaign success also now works for web campaigns. All you need to do is specify an Analytics conversion event when setting up your campaign and the report will track success automatically.
Let’s go back to our favorite product review example. Now that we have a way to identify the audience who haven’t completed their reviews, we can re-engage them with tailored notifications for users on the native app as well as users on the web app. Since the audience is already being populated by Google Analytics with these user segments, you now simply have to go to Firebase Cloud Messaging in the Firebase console and create a campaign which sends a message to these audiences on their respective platforms.
Once we’ve started our messaging re-engagement campaign, we can use Google Analytics to create closed funnels to view the performance of the engagement workflow on any specific platform.
To use any of what we just described you, take a look at the instructions for implementing and integrating the web analytics SDK here. One important note is that if you are already using analytics for your native apps, you will first need to upgrade to the full Google Analytics experience in order to access web analytics. The Remote Config SDK for web is currently in Beta and you can access it here. To get started with FCM for web, simply follow the instructions here.
We hope you’re as excited about these new web features as we are. The above example illustrates one way you can use the new web analytics features to improve your web app experience and engage users, but there are many more ways these features can be used together. We can’t wait to hear what use cases you’ve implemented in your own web apps. As always, you can reach out to us on StackOverflow and through our official support page to let us know and give us feedback. Happy Developing!