Slide 1

Slide 1 text

How to Design, Build and Run a Cloud app Google Cloud Platform Developer Roadshow - 2014

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Demo - overview

Slide 5

Slide 5 text

Application Tracks Comments Leaderboard Persistent Storage Temporary Storage API

Slide 6

Slide 6 text

Agenda Architectural decisions Plan for getting big Run the app in production Coming soon 1 2 3 4

Slide 7

Slide 7 text

Agenda Architectural decisions Plan for getting big Run the app in production Coming soon 1 2 3 4

Slide 8

Slide 8 text

- Persistent Storage Accessible from Mobile - Autoscaling, Modular, Frontend and API - Ease of Development and maintenance - Robust commenting - DB for Temp/Summary data

Slide 9

Slide 9 text

Where do we store walks (GPS Tracks)?

Slide 10

Slide 10 text

- Persistent Storage Accessible from Mobile - Autoscaling, Modular, Frontend and API - Ease of Development and maintenance - Robust commenting - DB for Temp/Summary data

Slide 11

Slide 11 text

Cloud Datastore

Slide 12

Slide 12 text

Why?

Slide 13

Slide 13 text

NoSQL Store Autoscale and management Automatically scales as your needs do and is fully managed. sharding and replication is taken care of for you Schemaless access, no need to think about underlying data structure. Robust query engine and abstraction libraries Schemaless access Cloud Datastore ACID Transactions with Strong consistency on reads and ancestor queries

Slide 14

Slide 14 text

• Same High Replication Datastore Used By App Engine Apps Today • Accessible Anywhere via RESTful API • Equally Fast Queries For Any Sized Dataset • Data Replicated Across Multiple Data Centers • Use From Any Application or Language • Serving 4.5+ Trillion Requests Per Month Cloud Datastore

Slide 15

Slide 15 text

Other situations?

Slide 16

Slide 16 text

MySQL in the Cloud Easy Migration; No Lock-in Standard connections and tools such as mysqldump, MySQL Wire Protocol, and JDBC, easy to migrate and avoids lock-in. Data replicated in many geographic locations as standard, failover handled automatically. Fully managed backups Security, Availability, Durability Cloud SQL Cloud SQL offers managed MySQL instances, up to 16GB RAM, 100GB storage.

Slide 17

Slide 17 text

● Flexible Charging ○ Pay per use ○ Package options ● EU, US and Asia Data Centers ○ Colocate Cloud SQL and App Engine Apps in EU or US Cloud SQL

Slide 18

Slide 18 text

Files images, videos, backups...

Slide 19

Slide 19 text

Object Store Encryption and Access Control Store any amount of data, up to 5TB/Object. With full versioning, change notifications and resumable uploads and downloads Data encrypted at rest. Fine grained access control 99.95% SLA through highly available, geo-redundant data-replication system. Strong read-after-write consistency for each object Reliable and Consistent Cloud Storage

Slide 20

Slide 20 text

Persistent Storage Accessible from Mobile - Autoscaling, Modular, Frontend and API - Ease of Development and maintenance - Robust commenting - DB for Temp/Summary data ✓

Slide 21

Slide 21 text

How can we share the walks?

Slide 22

Slide 22 text

Persistent Storage Accessible from Mobile - Autoscaling, Modular, Frontend and API - Ease of Development and maintenance - Robust commenting - DB for Temp/Summary data ✓

Slide 23

Slide 23 text

App Engine • Very easy to use Datastore from web • We created an API and HTML5 client app

Slide 24

Slide 24 text

Why?

Slide 25

Slide 25 text

Google App Engine Python, Java, PHP, Go, ...

Slide 26

Slide 26 text

Simple to Scale - Autoscale Easy to develop - Free to start - Build and test locally - Focus on App Code Trivial to manage - Fully managed - No patches/updates - 24x7 operation by Google SREs Google App Engine

Slide 27

Slide 27 text

No need for this...

Slide 28

Slide 28 text

Can handle changes in demand...

Slide 29

Slide 29 text

Local Dev Environment... $ gcloud app run . INFO: Module instance default is running at http: //localhost:8080/ com.google.appengine.tools.development.AbstractModule startup INFO: The admin console is running at http://localhost: 8080/_ah/admin com.google.appengine.tools.development.DevAppServerImpl doStart INFO: Dev App Server is now running

Slide 30

Slide 30 text

App Engine Architecture Pending Request Queue Instance Scheduler datastore Requests Task Queue memcache Application

Slide 31

Slide 31 text

Factor large Apps into logical components Modules: - Can access and share stateful Services - Communicate Securely - Have Performance settings and Versions - Have URI, e.g. my-module. myapp.appspot.com - Can be backed by Compute Engine VMs (Managed VMs) App Engine Modules Module Module Module Version Version Version Version VM Instance Instance Version Version VM Instance App

Slide 32

Slide 32 text

Building a RESTful API from scratch

Slide 33

Slide 33 text

GET http://walkshare-staging.appspot.com/comment/userbob/walk1 {"type":"LIST_COMMENTS","status":"OK","count":3,"comments":[{"userID":"userbob","walkID":" walk1","commenterName":"Alphonse","date":"Jul 24, 2014 1:07:16 AM","content":"Nice walk! ☺ (Though not as great as my walk)"]} Walkshare API

Slide 34

Slide 34 text

Demo - API

Slide 35

Slide 35 text

Simplifying API Development

Slide 36

Slide 36 text

Backend running on Google App Engine iOS Cloud Endpoints ● Create APIs for Mobile and Gaming Backends ● Decorate client interface application code or generate Endpoint classes from Models ● Discoverable, Restful APIs implemented on top of Google’s API Infrastructure ● Tools for generating mobile optimized Client Libraries for Android, iOS and Web ● out-of-the-box DoS protection, OAuth 2.0 support and client key management Google Cloud Endpoints

Slide 37

Slide 37 text

Java - App Engine @Api(name=”comment” version=”v1”) public class CommentsEndpoint @ApiMethod(httpMethod = "GET", path = "{userid}/{walkid}") public List getComments( @Named("walkid") long walkId, @Named(“userid”) long userId) throws UnauthorizedException, NotFoundException { List results = comments.query(userid, walkid); return results; } } // REST call = /comment/v1/{userid}/{walkid} public class CommentsTask extends ServiceTask { protected void executeEndpointCall() { service.commentsEndpoint().getComments(userId, walkId).execute(); } Android App

Slide 38

Slide 38 text

Why didn’t we just start with Endpoints?

Slide 39

Slide 39 text

Other situations?

Slide 40

Slide 40 text

App Engine shared memcache Application (walkshare) prod Instance 1 Instance N DataAnalysis Backend 1 Backend 2 Queues Application (snipchut) one Instance 1 Instance N DataAnalysis Backend 1 Backend 2 Queues Application (someapp) prod Backend 1 Backend 2 test Backend 1 Backend 2 Queues Datastore Memcache

Slide 41

Slide 41 text

memcache App Engine shared memcache Application (walkshare) prod Instance 1 Instance N DataAnalysis Backend 1 Backend 2 Queues Application (snipchut) one Instance 1 Instance N DataAnalysis Backend 1 Backend 2 Queues Application (someapp) prod Backend 1 Backend 2 test Backend 1 Backend 2 Queues Datastore Dedicated Memcache Dedicated Memcache Per GB reservation No service-level evictions

Slide 42

Slide 42 text

Web Requests Worker Task Queue /process_form?status=processed&form_data=... Ancillary Services External APIs Task Queues

Slide 43

Slide 43 text

Build it yourself on Compute Engine?

Slide 44

Slide 44 text

Persistent Storage Accessible from Mobile Autoscaling, Modular, Frontend and API Ease of Development and maintenance - Robust commenting - DB for Temp/Summary data ✓ ✓ ✓

Slide 45

Slide 45 text

Comment SPAM

Slide 46

Slide 46 text

Persistent Storage Accessible from Mobile Autoscaling, Modular, Frontend and API Ease of Development and maintenance - Robust commenting - DB for Temp/Summary data ✓ ✓ ✓

Slide 47

Slide 47 text

Captcha

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

Managed VMs makes this easy

Slide 50

Slide 50 text

Demo - captcha

Slide 51

Slide 51 text

Persistent Storage Accessible from Mobile Autoscaling, Modular, Frontend and API Ease of Development and maintenance Robust commenting - DB for Temp/Summary data ✓ ✓ ✓ ✓

Slide 52

Slide 52 text

Comments Leaderboard

Slide 53

Slide 53 text

Persistent Storage Accessible from Mobile Autoscaling, Modular, Frontend and API Ease of Development and maintenance Robust commenting - DB for Temp/Summary data ✓ ✓ ✓ ✓

Slide 54

Slide 54 text

Redis on Compute Engine • Which users are getting the most comments on their walks? Redis +

Slide 55

Slide 55 text

Why Redis? Use the right tool for the job.

Slide 56

Slide 56 text

Why Compute Engine?

Slide 57

Slide 57 text

Google Compute Engine Images by Connie Zhou

Slide 58

Slide 58 text

Compute Resources - US, Europe and Asia zones - Fast SDN-Based virtual networking Consistently Fast - Fast VM Provisioning - Consistent Performance - Cloud Native Load Balancing Cost Effective - Sub-Hour Billing - No IOPS charges for Block Storage - VMs not required for Load balancing Compute Engine

Slide 59

Slide 59 text

Cores CPU to Memory ratio More memory 1 2 4 8 More CPU (Shared) 16 High CPU Standard High Memory Standard High Memory High CPU Compute Engine VMs: ● Debian, CentOS, SUSE, RHEL ● shared core or 1 - 16 cores ● Up to 60GB of RAM Instances to suit diverse workloads

Slide 60

Slide 60 text

● Per GB pricing; no IO charges ● Consistent Performance ● Encryption ● Live Migration ● Storage redundancy ● Checksums ● Snapshots ● 1GB - 1TB Persistent Disk SSD PD Standard PD

Slide 61

Slide 61 text

Local SSD Persistent Disk ● Per GB pricing; no IO charges ● Consistent Performance ● Encryption ● Live Migration ● Sub-ms latency ● 1-4 x 375 GB partitions

Slide 62

Slide 62 text

Local SSD Persistent Disk SSD PD Standard PD RO RW

Slide 63

Slide 63 text

Local SSD Persistent Disk 200 30 80 Local SSD IOPS/GB (log scale) 0 Standard PD 15 6 SSD PD 2 SSD PD Standard PD

Slide 64

Slide 64 text

● TCP and UDP (plus VPN protocols) ● IP addresses ● public: static and ephemeral ● internal: ephemeral with automatic DNS ● Network groups & firewall rules ● rules applied to instances via tags ● Gateways, routing and VPNs ● Load Balancing ● Client Affinity Networking Internet

Slide 65

Slide 65 text

us-central1-a scheduled maintenance event Live Migration

Slide 66

Slide 66 text

GCE and Docker

Slide 67

Slide 67 text

GCE is a great place to run Redis.

Slide 68

Slide 68 text

Application Tracks Comments Leaderboard Persistent Storage Temporary Storage API

Slide 69

Slide 69 text

Master Redis Cluster Application Tracks Comments Leaderboard ... Minions Temp DB (Redis)

Slide 70

Slide 70 text

Persistent Storage Accessible from Mobile Autoscaling, Modular, Frontend and API Ease of Development and maintenance Robust commenting DB for Temp/Summary data ✓ ✓ ✓ ✓ ✓

Slide 71

Slide 71 text

Agenda Architectural decisions Plan for getting big Run the app in production Coming soon 1 2 3 4

Slide 72

Slide 72 text

Getting big - scale • Services • Development processes Source: iStockPhoto

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

App Engine Autoscale Pending Request Queue Instance Scheduler Requests Application Instance Instance

Slide 77

Slide 77 text

Replica Pool name: io-demo modules: replica_pool: type: REPLICA_POOL replicaPoolModule: numReplicas: 1 replicaPoolParams: v1beta1: machineType: n1-standard-2 zone: us-central1-a baseInstanceName: io-demo disksToCreate: - boot: true autodelete: true mode: READ_WRITE … load_balancer: type: LOAD_BALANCING … firewall: type: … autoscaler: type: AUTOSCALING autoscalingModule: targetModule: "replica_pool" targetUtilization: 0.5 maxNumReplicas: 10 minNumReplicas: 2 coolDownPeriodSec: 45 Resource View create/ destroy Load Balancer Agent Agent VM Monitoring Agent Compute Engine Replica Pool

Slide 78

Slide 78 text

Load Balancing: 1m requests/sec Load Balancing at Scale • Single load-balanced IP Address • Serving 1 million qps sustained • Total cost of test: $10

Slide 79

Slide 79 text

master Redis Cluster Application Tracks Comments Leaderboard Replica Pool Load Balancer VM Load balanced Redis

Slide 80

Slide 80 text

Demo - load balanced Redis

Slide 81

Slide 81 text

Focus on the product • Minimize risk • Scale down • Deployment • Ease of management

Slide 82

Slide 82 text

Minimize risk keep the site up

Slide 83

Slide 83 text

Scale down keep it cheap to start, experiment quickly

Slide 84

Slide 84 text

smoothly scaling abstractions Application Tracks Comments Leaderboard

Slide 85

Slide 85 text

Deployment

Slide 86

Slide 86 text

App Engine Modules Module Module Module Version Version Version Version VM Instance Instance Version Version VM Instance App

Slide 87

Slide 87 text

Application Tracks Comments Leaderboard Persistent Storage Temporary Storage API

Slide 88

Slide 88 text

Ease of management

Slide 89

Slide 89 text

Agenda Architectural decisions Plan for getting big Run the app in production Coming soon 1 2 3 4

Slide 90

Slide 90 text

Two views

Slide 91

Slide 91 text

Monitoring the tech • log viewer • metrics • monitoring

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

No content

Slide 95

Slide 95 text

Monitoring the product • data from monitoring the tech • great source of usage data, etc. • custom? • we set up Redis on GCE for leaderboards • you can do anything your app needs • leaderboard stats over time? ad hoc, exploratory queries? • BigQuery!

Slide 96

Slide 96 text

Application Tracks Comments Leaderboard Persistent Storage Temporary Storage API

Slide 97

Slide 97 text

Agenda Architectural decisions Plan for getting big Run the app in production Coming soon 1 2 3 4

Slide 98

Slide 98 text

Managed VMs and Beyond

Slide 99

Slide 99 text

Compute Engine Core OS Kubernetes App Engine managed VMs NEW NEW Blurring the line between Iaas and Paas

Slide 100

Slide 100 text

Dockerfile app.yaml All you need Your app Cloud SDK gcloud app run or gcloud app deploy Docker registry VM* container dockerd *A VM running Docker…

Slide 101

Slide 101 text

Autoscaling Replica Pool

Slide 102

Slide 102 text

… … machineType: n1-standard-1 zone: us-central1-a baseInstanceName: io-demo disksToCreate: - boot: true autodelete: true mode: READ_WRITE … load_balancer: type: LOAD_BALANCING … firewall: type: … autoscaler: type: AUTOSCALING autoscalingModule: targetModule: "replica_pool" targetUtilization: 0.5 maxNumReplicas: 10 minNumReplicas: 2 coolDownPeriodSec: 45 Replica Pool Resource View create/ destroy Load Balancer Agent Agent VM Monitoring Agent Actuator Compute Engine Autoscaler

Slide 103

Slide 103 text

Saving Mobile Data

Slide 104

Slide 104 text

Your Project Your App running on Google App Engine Google Cloud Datastore Cloud Save for Android Google Cloud Save for Android

Slide 105

Slide 105 text

Your app here

Slide 106

Slide 106 text

cloud.google.com Images by Connie Zhou