최명근 - mgchoi@google.com
Cloud Sales Engineer
Google Cloud Platform Workshop
01 Google Cloud Platform
3
BigQuery
Big Data
Pub/Sub Dataflow Dataproc Datalab
Compute
Compute
Engine
App Engine Container
Engine
App Services
Cloud EndpointsPrediction API Translate API
Storage
Cloud
Storage
Cloud SQL Cloud
Datastore
Bigtable
Google Cloud Platform
Building what’s next 4
70 edge locations
33 countries
The broadest reaching network
of any Cloud Provider
Google-Grade Networking
Live Migration = No Downtime
GCE Custom Machine Types
Average Savings: 19%
Unique GCE Capabilities
Industry-leading IO performance
Per-minute billing & Sustained Use Discounts
Super-fast startup times: 1000 VMs in < 5 minutes
High throughput to storage at no extra cost
NEW: Resize disks with no downtime
Multi-Cloud Reality
Public Cloud Private Cloud Open Source
& APIs
Multi-cloud monitoring & logging
Tracing, Error Reporting, Debugging
Intelligent defaults
Apps
Kubernetes
Builds on our 10 years of container management
Designed for multi-cloud
Broad industry support
02 Mobile Game Pattern on GCP
12
Typical requirements for a compelling mobile game include:
1. Game features :
● Dynamic game content
● Game data stored outside of devices
● Leaderboard
● Multiplayer mode
● Player matching
● Board generation
● Server site bots
2. Platform features :
● Support for Android and iOS devices through native client applications
● Push notifications to Android and IOS devices
● User authentication
● High scalability
3. Business features :
● In-game purchases
● Game analytics
13
Many popular mobile games use mobile backends to:
● Deliver dynamic game content
● Facilitate multiplayer games, including matching players
● Store data outside of the mobile device, e.g., the last completed level, or the scores
achieved in the previous plays
● Manage the leaderboard
● Orchestrate push notifications
● Facilitate in-game purchases
● Provide game analytics
14
Your Mobile Game Backend in the Cloud
● Automatic scalability
● Automatic load balancing across instances of your mobile backend
● Static content serving and caching
● Reliability, performance, and security features
● Monitoring and management
● Configurable DoS protection
● Integration with Google Accounts for OAuth2 authentication (for both Android
and iOS clients)
15
Easy scalability
Task queue
Background
Image processingMedia serving
API endpoints
Push to phone
Game logic
Datastore
Memcache
Mobile Backend
running on Google
App Engine Instances
iOS
CloudEndPointClients
Cloud Endpoints
● Create APIs for Mobile Apps to
communicate with Mobile Backends
● Add annotations to client interface
application code or generate Endpoint
classes from Models.
● Discoverable, Restful APIs
implemented on top of Google’s API
Infrastructure
● Tools available for generating Client
Libraries for Android, iOS and
JavaScript
● Built-In Authentication Support
APIs for Mobile Backends Made Easy
Storage Services
Web APIs
Cloud
Endpoints
Java - App Engine
@ApiMethod(httpMethod = "PUT", path = "game/{id}/answers")
public void submitAnswers(
@Named("id") long gameId, GamePlayStatus answers,
User player)
throws UnauthorizedException, NotFoundException {
if (user == null) {
throw new UnauthorizedException("The user is not authorized.");
gameService.submitAnswers(gameId, player, answers);
}
Java - Android Apppublic class SubmitAnswersTask extends ServiceTask<Void> {
protected void executeEndpointCall() {
service.gameEndpoint().submitAnswers(gameId, answers).execute();
}
Cloud Endpoints - Custom API
Submit Answers
Cloud Endpoints - Custom API
Java - App Engine
Mobile Game-AppEngine $ endpoints.sh get-client-lib org.arw.examples.appengine.mobilegame.GameInviteEndpoint
Jul 17, 2013 3:05:32 PM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml
INFO: Successfully processed ./war/WEB-INF/appengine-web.xml
API configuration written to ./gameinviteendpoint-v1.api
API Discovery Document written to ./gameinviteendpoint-v1-rpc.discovery
API Discovery Document written to ./gameinviteendpoint-v1-rest.discovery
API client library written to ./gameinviteendpoint-v1-java.zip
Eclipse
Cloud Endpoints Development
Generate Client Library
Cloud Endpoints Development
19
A Globally Distributed Player Base
US users
EU users
Australia users
Communication
MySQL
Redis
API
US
EU
AUS
Websocket
Geo
Load Balancer
20
Matchmaking
MySQL
Game servers
Matchmaker
module
Find server
Register server
I want to play
Assign players
21
Profile and Session Management
MySQL
Signed URL
Profile pictures
Bucket
Edge
Cache
Public pictures
Bucket
Session
information
Redis
User registration
and login
User frontend
PD
SSD
Image metadata
22
Smart client Smart backend
Push to Phone
Web sockets
In-game real time
notifications Push notifications
OR
23
03 How to build mobile games using
App Engine and Cloud Endpoints ?
25
Griddler - multiplayer riddle mobile game
26
27
Responsibilities of the mobile game backend include :
● Serving board definitions to the clients
● Managing the list of players and their statistics (for example, how many games a player
played across different devices, how many multiplayer games she won)
● Managing the list of devices used by players in order to be able to send push notifications
to these devices
● Sending game invitations for multiplayer games
● Relaying invitation acceptance, declines and cancellations
28
Key components of mobile gaming solutions
● The mobile game client applications
● The mobile game backend
○ Griddler API includes methods for:
■ Game Management, for example startNewSinglePlayerGame and gameFinished
■ Player Invitations, for example sendInvitation, acceptInvitation etc.
■ Notifications, for example registerDeviceForPushNotification
29
Communication between clients apps and your mobile game backend
@Api annotation
API call from the client
30
Storing data
31
Optimizing data access with Memcache
A backend running on Google App Engine can
use a distributed in-memory, data cache service
called Memcache to store and retrieve
frequently accessed data
32
● Make a game more engaging and social
● Task Queues
○ Push Queue : Sending the enqueued tasks (push model) to your code running on
Google App Engine as HTTP requests to a chosen URL
○ Pull Queue : Mobile backend code can pull the tasks from the queue / Process the
tasks outside of App Engine
Asynchronous processing with Task Queues
33
Push notifications
34
Serving and processing images
35
Scheduled jobs
36
37
Firebase is a powerful platform for
mobile and web applications.
Static HostingRealtime Database User Authentication
Web Framework Integrations
Server Side Access
Client SDKs
Realtime Database
NoSQL JSON database
Three Tier Architecture
device application
server
database
Two Tier Architecture
Firebasedevice
● Fast Development
● Offload Scaling
● Unified Security
Two Tier Architecture
Firebasedevice
server
api
Database
Realtime Data Synchronization
// Create a Firebase database reference
var ref = new Firebase("https://googleformobile.firebaseio.com");
// Write data from Firebase
ref.set("Hi GCP WorkShop!");
// Read data from Firebase
ref.on("value", function(snapshot) {
var data = snapshot.val();
console.log(snapshot.val());
});
"rules": {
"foo": {
// /foo/ is readable by the world
".read": true,
// /foo/ is writable by the world
".write": true,
// data written to /foo/ must be a string less than 100 characters
".validate": "newData.isString() && newData.val().length < 100"
}
}
Database: Offline Native
Database: Offline Native
Database: Offline Native
Authentication
Authentication
Email & Password
Third Party Providers
(Google, Facebook, Twitter, GitHub)
// Facebook Authentication
var ref = new Firebase("https://googleformobile.firebaseio.com");
ref.authWithOAuthPopup("facebook”, function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload: ", authData);
}
});
"users": {
"$uid": {
// /users/$uid is globally readable
".read": "true",
// but only personally writable
".write": "auth.uid == $uid"
}
}
Hosting
Hosting
SSL by default
Backed by a global CDN
Custom domain support
> firebase init
Initializing app…
Successfully initialized
> firebase deploy
Progress: 100%
Successfully deployed
Let’s write some code!
58
Firebase and Google App Engine
59
Firebase and Managed VMs
60
Resources
Firebase docs: firebase.com/docs
Cloud docs : cloud.google.com/docs
Join the discussion
bit.ly/gcp-slack bit.ly/gcp-githubbit.ly/gcp-twitter gcpug.kr
Thank You

Mobile game architecture on GCP

  • 1.
    최명근 - mgchoi@google.com CloudSales Engineer Google Cloud Platform Workshop
  • 2.
  • 3.
    3 BigQuery Big Data Pub/Sub DataflowDataproc Datalab Compute Compute Engine App Engine Container Engine App Services Cloud EndpointsPrediction API Translate API Storage Cloud Storage Cloud SQL Cloud Datastore Bigtable Google Cloud Platform
  • 4.
    Building what’s next4 70 edge locations 33 countries The broadest reaching network of any Cloud Provider Google-Grade Networking
  • 5.
    Live Migration =No Downtime
  • 6.
    GCE Custom MachineTypes Average Savings: 19%
  • 7.
    Unique GCE Capabilities Industry-leadingIO performance Per-minute billing & Sustained Use Discounts Super-fast startup times: 1000 VMs in < 5 minutes High throughput to storage at no extra cost NEW: Resize disks with no downtime
  • 8.
    Multi-Cloud Reality Public CloudPrivate Cloud Open Source & APIs
  • 9.
    Multi-cloud monitoring &logging Tracing, Error Reporting, Debugging Intelligent defaults
  • 10.
    Apps Kubernetes Builds on our10 years of container management Designed for multi-cloud Broad industry support
  • 11.
    02 Mobile GamePattern on GCP
  • 12.
    12 Typical requirements fora compelling mobile game include: 1. Game features : ● Dynamic game content ● Game data stored outside of devices ● Leaderboard ● Multiplayer mode ● Player matching ● Board generation ● Server site bots 2. Platform features : ● Support for Android and iOS devices through native client applications ● Push notifications to Android and IOS devices ● User authentication ● High scalability 3. Business features : ● In-game purchases ● Game analytics
  • 13.
    13 Many popular mobilegames use mobile backends to: ● Deliver dynamic game content ● Facilitate multiplayer games, including matching players ● Store data outside of the mobile device, e.g., the last completed level, or the scores achieved in the previous plays ● Manage the leaderboard ● Orchestrate push notifications ● Facilitate in-game purchases ● Provide game analytics
  • 14.
    14 Your Mobile GameBackend in the Cloud ● Automatic scalability ● Automatic load balancing across instances of your mobile backend ● Static content serving and caching ● Reliability, performance, and security features ● Monitoring and management ● Configurable DoS protection ● Integration with Google Accounts for OAuth2 authentication (for both Android and iOS clients)
  • 15.
    15 Easy scalability Task queue Background ImageprocessingMedia serving API endpoints Push to phone Game logic Datastore Memcache
  • 16.
    Mobile Backend running onGoogle App Engine Instances iOS CloudEndPointClients Cloud Endpoints ● Create APIs for Mobile Apps to communicate with Mobile Backends ● Add annotations to client interface application code or generate Endpoint classes from Models. ● Discoverable, Restful APIs implemented on top of Google’s API Infrastructure ● Tools available for generating Client Libraries for Android, iOS and JavaScript ● Built-In Authentication Support APIs for Mobile Backends Made Easy Storage Services Web APIs Cloud Endpoints
  • 17.
    Java - AppEngine @ApiMethod(httpMethod = "PUT", path = "game/{id}/answers") public void submitAnswers( @Named("id") long gameId, GamePlayStatus answers, User player) throws UnauthorizedException, NotFoundException { if (user == null) { throw new UnauthorizedException("The user is not authorized."); gameService.submitAnswers(gameId, player, answers); } Java - Android Apppublic class SubmitAnswersTask extends ServiceTask<Void> { protected void executeEndpointCall() { service.gameEndpoint().submitAnswers(gameId, answers).execute(); } Cloud Endpoints - Custom API Submit Answers Cloud Endpoints - Custom API
  • 18.
    Java - AppEngine Mobile Game-AppEngine $ endpoints.sh get-client-lib org.arw.examples.appengine.mobilegame.GameInviteEndpoint Jul 17, 2013 3:05:32 PM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml INFO: Successfully processed ./war/WEB-INF/appengine-web.xml API configuration written to ./gameinviteendpoint-v1.api API Discovery Document written to ./gameinviteendpoint-v1-rpc.discovery API Discovery Document written to ./gameinviteendpoint-v1-rest.discovery API client library written to ./gameinviteendpoint-v1-java.zip Eclipse Cloud Endpoints Development Generate Client Library Cloud Endpoints Development
  • 19.
    19 A Globally DistributedPlayer Base US users EU users Australia users Communication MySQL Redis API US EU AUS Websocket Geo Load Balancer
  • 20.
  • 21.
    21 Profile and SessionManagement MySQL Signed URL Profile pictures Bucket Edge Cache Public pictures Bucket Session information Redis User registration and login User frontend PD SSD Image metadata
  • 22.
    22 Smart client Smartbackend Push to Phone Web sockets In-game real time notifications Push notifications OR
  • 23.
  • 24.
    03 How tobuild mobile games using App Engine and Cloud Endpoints ?
  • 25.
    25 Griddler - multiplayerriddle mobile game
  • 26.
  • 27.
    27 Responsibilities of themobile game backend include : ● Serving board definitions to the clients ● Managing the list of players and their statistics (for example, how many games a player played across different devices, how many multiplayer games she won) ● Managing the list of devices used by players in order to be able to send push notifications to these devices ● Sending game invitations for multiplayer games ● Relaying invitation acceptance, declines and cancellations
  • 28.
    28 Key components ofmobile gaming solutions ● The mobile game client applications ● The mobile game backend ○ Griddler API includes methods for: ■ Game Management, for example startNewSinglePlayerGame and gameFinished ■ Player Invitations, for example sendInvitation, acceptInvitation etc. ■ Notifications, for example registerDeviceForPushNotification
  • 29.
    29 Communication between clientsapps and your mobile game backend @Api annotation API call from the client
  • 30.
  • 31.
    31 Optimizing data accesswith Memcache A backend running on Google App Engine can use a distributed in-memory, data cache service called Memcache to store and retrieve frequently accessed data
  • 32.
    32 ● Make agame more engaging and social ● Task Queues ○ Push Queue : Sending the enqueued tasks (push model) to your code running on Google App Engine as HTTP requests to a chosen URL ○ Pull Queue : Mobile backend code can pull the tasks from the queue / Process the tasks outside of App Engine Asynchronous processing with Task Queues
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
    37 Firebase is apowerful platform for mobile and web applications.
  • 38.
  • 39.
    Web Framework Integrations ServerSide Access Client SDKs
  • 40.
  • 41.
    Three Tier Architecture deviceapplication server database
  • 42.
    Two Tier Architecture Firebasedevice ●Fast Development ● Offload Scaling ● Unified Security
  • 43.
  • 44.
  • 45.
    // Create aFirebase database reference var ref = new Firebase("https://googleformobile.firebaseio.com"); // Write data from Firebase ref.set("Hi GCP WorkShop!"); // Read data from Firebase ref.on("value", function(snapshot) { var data = snapshot.val(); console.log(snapshot.val()); });
  • 46.
    "rules": { "foo": { ///foo/ is readable by the world ".read": true, // /foo/ is writable by the world ".write": true, // data written to /foo/ must be a string less than 100 characters ".validate": "newData.isString() && newData.val().length < 100" } }
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
    Authentication Email & Password ThirdParty Providers (Google, Facebook, Twitter, GitHub)
  • 52.
    // Facebook Authentication varref = new Firebase("https://googleformobile.firebaseio.com"); ref.authWithOAuthPopup("facebook”, function(error, authData) { if (error) { console.log("Login Failed!", error); } else { console.log("Authenticated successfully with payload: ", authData); } });
  • 53.
    "users": { "$uid": { ///users/$uid is globally readable ".read": "true", // but only personally writable ".write": "auth.uid == $uid" } }
  • 54.
  • 55.
    Hosting SSL by default Backedby a global CDN Custom domain support
  • 56.
    > firebase init Initializingapp… Successfully initialized > firebase deploy Progress: 100% Successfully deployed
  • 57.
  • 58.
  • 59.
  • 60.
    60 Resources Firebase docs: firebase.com/docs Clouddocs : cloud.google.com/docs Join the discussion bit.ly/gcp-slack bit.ly/gcp-githubbit.ly/gcp-twitter gcpug.kr
  • 61.