How to Design, Build and Run a Cloud App (Cloud Developer Roadshow 2014)

How to Design, Build and Run a Cloud App (Cloud Developer Roadshow 2014)

This deck is an end to end walkthrough of designing and building an application on Google Cloud Platform. It's based on the real world example of the app that we built for the Google I/O 2014 keynote and sessions, an app called Walkshare. This deck was delivered during the Google Cloud Platform Developer Roadshow events in 2014.

42ff40d0d729d86739df5ede5591d4f1?s=128

GoogleCloudPlatform

August 20, 2014
Tweet

Transcript

  1. How to Design, Build and Run a Cloud app Google

    Cloud Platform Developer Roadshow - 2014
  2. None
  3. None
  4. Demo - overview

  5. Application Tracks Comments Leaderboard Persistent Storage Temporary Storage API

  6. Agenda Architectural decisions Plan for getting big Run the app

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

    in production Coming soon 1 2 3 4
  8. - Persistent Storage Accessible from Mobile - Autoscaling, Modular, Frontend

    and API - Ease of Development and maintenance - Robust commenting - DB for Temp/Summary data
  9. Where do we store walks (GPS Tracks)?

  10. - Persistent Storage Accessible from Mobile - Autoscaling, Modular, Frontend

    and API - Ease of Development and maintenance - Robust commenting - DB for Temp/Summary data
  11. Cloud Datastore

  12. Why?

  13. 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
  14. • 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
  15. Other situations?

  16. 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.
  17. • 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
  18. Files images, videos, backups...

  19. 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
  20. Persistent Storage Accessible from Mobile - Autoscaling, Modular, Frontend and

    API - Ease of Development and maintenance - Robust commenting - DB for Temp/Summary data ✓
  21. How can we share the walks?

  22. Persistent Storage Accessible from Mobile - Autoscaling, Modular, Frontend and

    API - Ease of Development and maintenance - Robust commenting - DB for Temp/Summary data ✓
  23. App Engine • Very easy to use Datastore from web

    • We created an API and HTML5 client app
  24. Why?

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

  26. 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
  27. No need for this...

  28. Can handle changes in demand...

  29. 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
  30. App Engine Architecture Pending Request Queue Instance Scheduler datastore Requests

    Task Queue memcache Application
  31. 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
  32. Building a RESTful API from scratch

  33. 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
  34. Demo - API

  35. Simplifying API Development

  36. 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
  37. Java - App Engine @Api(name=”comment” version=”v1”) public class CommentsEndpoint @ApiMethod(httpMethod

    = "GET", path = "{userid}/{walkid}") public List<Comment> getComments( @Named("walkid") long walkId, @Named(“userid”) long userId) throws UnauthorizedException, NotFoundException { List<Comment> results = comments.query(userid, walkid); return results; } } // REST call = /comment/v1/{userid}/{walkid} public class CommentsTask extends ServiceTask<Void> { protected void executeEndpointCall() { service.commentsEndpoint().getComments(userId, walkId).execute(); } Android App
  38. Why didn’t we just start with Endpoints?

  39. Other situations?

  40. 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
  41. 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
  42. Web Requests Worker Task Queue /process_form?status=processed&form_data=... Ancillary Services External APIs

    Task Queues
  43. Build it yourself on Compute Engine?

  44. Persistent Storage Accessible from Mobile Autoscaling, Modular, Frontend and API

    Ease of Development and maintenance - Robust commenting - DB for Temp/Summary data ✓ ✓ ✓
  45. Comment SPAM

  46. Persistent Storage Accessible from Mobile Autoscaling, Modular, Frontend and API

    Ease of Development and maintenance - Robust commenting - DB for Temp/Summary data ✓ ✓ ✓
  47. Captcha

  48. None
  49. Managed VMs makes this easy

  50. Demo - captcha

  51. Persistent Storage Accessible from Mobile Autoscaling, Modular, Frontend and API

    Ease of Development and maintenance Robust commenting - DB for Temp/Summary data ✓ ✓ ✓ ✓
  52. Comments Leaderboard

  53. Persistent Storage Accessible from Mobile Autoscaling, Modular, Frontend and API

    Ease of Development and maintenance Robust commenting - DB for Temp/Summary data ✓ ✓ ✓ ✓
  54. Redis on Compute Engine • Which users are getting the

    most comments on their walks? Redis +
  55. Why Redis? Use the right tool for the job.

  56. Why Compute Engine?

  57. Google Compute Engine Images by Connie Zhou

  58. 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
  59. 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
  60. • Per GB pricing; no IO charges • Consistent Performance

    • Encryption • Live Migration • Storage redundancy • Checksums • Snapshots • 1GB - 1TB Persistent Disk SSD PD Standard PD
  61. Local SSD Persistent Disk • Per GB pricing; no IO

    charges • Consistent Performance • Encryption • Live Migration • Sub-ms latency • 1-4 x 375 GB partitions
  62. Local SSD Persistent Disk SSD PD Standard PD RO RW

  63. 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
  64. • 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
  65. us-central1-a scheduled maintenance event Live Migration

  66. GCE and Docker

  67. GCE is a great place to run Redis.

  68. Application Tracks Comments Leaderboard Persistent Storage Temporary Storage API

  69. Master Redis Cluster Application Tracks Comments Leaderboard ... Minions Temp

    DB (Redis)
  70. Persistent Storage Accessible from Mobile Autoscaling, Modular, Frontend and API

    Ease of Development and maintenance Robust commenting DB for Temp/Summary data ✓ ✓ ✓ ✓ ✓
  71. Agenda Architectural decisions Plan for getting big Run the app

    in production Coming soon 1 2 3 4
  72. Getting big - scale • Services • Development processes Source:

    iStockPhoto
  73. None
  74. None
  75. None
  76. App Engine Autoscale Pending Request Queue Instance Scheduler Requests Application

    Instance Instance
  77. 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
  78. Load Balancing: 1m requests/sec Load Balancing at Scale • Single

    load-balanced IP Address • Serving 1 million qps sustained • Total cost of test: $10
  79. master Redis Cluster Application Tracks Comments Leaderboard Replica Pool Load

    Balancer VM Load balanced Redis
  80. Demo - load balanced Redis

  81. Focus on the product • Minimize risk • Scale down

    • Deployment • Ease of management
  82. Minimize risk keep the site up

  83. Scale down keep it cheap to start, experiment quickly

  84. smoothly scaling abstractions Application Tracks Comments Leaderboard

  85. Deployment

  86. App Engine Modules Module Module Module Version Version Version Version

    VM Instance Instance Version Version VM Instance App
  87. Application Tracks Comments Leaderboard Persistent Storage Temporary Storage API

  88. Ease of management

  89. Agenda Architectural decisions Plan for getting big Run the app

    in production Coming soon 1 2 3 4
  90. Two views

  91. Monitoring the tech • log viewer • metrics • monitoring

  92. None
  93. None
  94. None
  95. 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!
  96. Application Tracks Comments Leaderboard Persistent Storage Temporary Storage API

  97. Agenda Architectural decisions Plan for getting big Run the app

    in production Coming soon 1 2 3 4
  98. Managed VMs and Beyond

  99. Compute Engine Core OS Kubernetes App Engine managed VMs NEW

    NEW Blurring the line between Iaas and Paas
  100. 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…
  101. Autoscaling Replica Pool

  102. … … 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
  103. Saving Mobile Data

  104. Your Project Your App running on Google App Engine Google

    Cloud Datastore Cloud Save for Android Google Cloud Save for Android
  105. Your app here

  106. cloud.google.com Images by Connie Zhou