61
최명근 - [email protected] Cloud Sales Engineer Google Cloud Platform Workshop

Mobile game architecture on GCP

  • Upload
    -

  • View
    170

  • Download
    2

Embed Size (px)

Citation preview

최명근 - [email protected] 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 DatastoreBigtable

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 TypesAverage 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 & loggingTracing, Error Reporting, Debugging

Intelligent defaults

AppsKubernetes

Builds on our 10 years of container managementDesigned for multi-cloudBroad 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

BackgroundImage processingMedia serving

API endpoints

Push to phone

Game logic

Datastore

Memcache

Mobile Backend running on Google

App Engine Instances

iOS

Cloud EndPoint Clients

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

CloudEndpoints

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 APISubmit 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 readAppEngineWebXmlINFO: Successfully processed ./war/WEB-INF/appengine-web.xmlAPI configuration written to ./gameinviteendpoint-v1.apiAPI Discovery Document written to ./gameinviteendpoint-v1-rpc.discoveryAPI Discovery Document written to ./gameinviteendpoint-v1-rest.discoveryAPI client library written to ./gameinviteendpoint-v1-java.zip

Eclipse

Cloud Endpoints DevelopmentGenerate 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

GeoLoad 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

PDSSD

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 DatabaseNoSQL 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/docsCloud docs : cloud.google.com/docs

Join the discussion

bit.ly/gcp-slack bit.ly/gcp-githubbit.ly/gcp-twitter gcpug.kr

Thank You