Jump to Content
Application Development

Building a serverless online game: Cloud Hero on Google Cloud Platform

January 29, 2019
https://storage.googleapis.com/gweb-cloudblog-publish/images/cloud_hero.max-2000x2000.jpg
Preston Holmes

Solution Architect, Google Cloud

Nick Curia

Technical Lead, Launch Consulting

If you’ve ever been to one of our live events, you may have played Cloud Hero, a game we built with Launch Consulting to help you test your knowledge of Google Cloud through the use of timed challenges. Cloud Hero gets a room full of people competing head-to-head, with a live play-by-play leaderboard and lots of prizes. To date, over 1,000 players have played Cloud Hero at 12 public events like Google Cloud Next and Google Cloud Summits—with more venues on the way!

When we set out to build Cloud Hero, we knew we wanted interactive and snappy game play, and an extensible and flexible game platform so that we could easily create new challenges and content. We also wanted to build the game quickly—and try out early versions with real players, without writing a lot of custom backend code. And with our event schedule, we also needed an architecture that would easily scale up and down on gameday, without having to run servers when it wasn’t in play.

It goes without saying that Cloud Hero would run on Google Cloud. Beyond that though, we chose to architect the game play system as an entirely serverless system, using Angular, Cloud Firestore, and Cloud Functions. Participants complete challenges directly in the Cloud Console, while BigQuery aggregates data for analytics. There’s not a single stateful server to be found in this game engine.

https://storage.googleapis.com/gweb-cloudblog-publish/images/cloud_hero_architecture_diagram.max-800x800.png

If you’re looking to test your Google Cloud skills, be sure to sign up for a round of Cloud Hero at one of our upcoming events. If you’re thinking about creating your next scalable, online, interactive game, read on to learn how we built Cloud Hero—we think it’s a winning architecture.

Game setup

When users play Cloud Hero, they are provided a game-specific project that is provisioned by script in a specific folder of a Resource Manager organization. Provisioning these projects enables certain APIs in advance which lets players focus on using the products, and less on setting up the project. Finally, the game system's service account is given access to the project. This is key to the game design, which will become clear shortly.

When a player registers and begins a game, documents are created in Firestore that represent the player and that player's specific instance of the game. The player is added to one of the pre-provisioned projects, and it is also associated with the game. And then the timed game challenges begin.

Game time

When a player starts a challenge, the game takes note of their start time. The challenge includes instructions to complete a variety of tasks in GCP. The more the player knows about GCP, the faster they are likely to complete the task, and the more points they will accrue. But players can also do well if they are good at finding the answers in docs and on the web—nobody knows everything, so navigating to the right information is a critical skill in cloud development.

https://storage.googleapis.com/gweb-cloudblog-publish/images/cloud_hero_map.max-1600x1600.png

While the game's front end keeps the gameplay feeling active with a running clock and animations, the serverless backend is idle—that is, until the user submits the challenge for verification, no compute is running. When a player completes a challenge, this changes the state of the challenge document in Firestore to ‘submitted’. The document change triggers a cloud function that runs using the game system's authorized service account that was added earlier to the player’s game project. With this access, and the information from the submitted challenge, the function introspects the state of the player's cloud resources to verify if the task was completed. Updating the result of this check in the Firestore document is immediately reflected to the player through Firestore's real-time watch system and Angular’s reactive subscription model.

Not only is the player notified of their update immediately, but so is the live projected leaderboard, which uses Firestore's ability to update queries in real time as the documents change to match the query's condition.

Finally, data is pushed from Firestore into BigQuery, whose enhanced analytics feed a real-time game analytics console that lets event coordinators see where players may be getting stuck, and which challenges are taking the most time.

Timed challenges FTW

From the outset, we expected that a live game and real-time feedback would be well received by players. Further, we hoped that the immersive game experience and direct access to the player’s project Cloud Console would help players learn more about GCP products. What we didn’t expect is that even novice GCP users would enjoy the experience as much as GCP pros. In fact, the top spot in our first event was won by someone who had never signed into the Cloud Console before! We’ve even got great feedback from people who didn’t advance past the first stage of challenges—they might be the group who took the most away. Not everyone finishes the game, but they have fun learning and challenging themselves.

In 2019 we are taking Cloud Hero in an exciting new direction: online! Early registrations for the new online version are now open. And if you’re interested in learning more about building serverless games, check out these guides and how-tos for Cloud Firestore and Cloud Functions.

Posted in