Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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.

GoogleCloudPlatform

August 20, 2014
Tweet

More Decks by GoogleCloudPlatform

Other Decks in Technology

Transcript

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

    View Slide

  2. View Slide

  3. View Slide

  4. Demo - overview

    View Slide

  5. Application
    Tracks
    Comments
    Leaderboard
    Persistent Storage
    Temporary
    Storage
    API

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  9. Where do we store walks (GPS Tracks)?

    View Slide

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

    View Slide

  11. Cloud Datastore

    View Slide

  12. Why?

    View Slide

  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

    View Slide

  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

    View Slide

  15. Other situations?

    View Slide

  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.

    View Slide

  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

    View Slide

  18. Files
    images, videos, backups...

    View Slide

  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

    View Slide

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

    View Slide

  21. How can we share the walks?

    View Slide

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

    View Slide

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

    View Slide

  24. Why?

    View Slide

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

    View Slide

  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

    View Slide

  27. No need for this...

    View Slide

  28. Can handle changes in demand...

    View Slide

  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

    View Slide

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

    View Slide

  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

    View Slide

  32. Building a RESTful API from scratch

    View Slide

  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

    View Slide

  34. Demo - API

    View Slide

  35. Simplifying API Development

    View Slide

  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

    View Slide

  37. 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

    View Slide

  38. Why didn’t we just start with Endpoints?

    View Slide

  39. Other situations?

    View Slide

  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

    View Slide

  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

    View Slide

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

    View Slide

  43. Build it yourself on Compute Engine?

    View Slide

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



    View Slide

  45. Comment SPAM

    View Slide

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



    View Slide

  47. Captcha

    View Slide

  48. View Slide

  49. Managed VMs makes this easy

    View Slide

  50. Demo - captcha

    View Slide

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




    View Slide

  52. Comments Leaderboard

    View Slide

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




    View Slide

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

    View Slide

  55. Why Redis?
    Use the right tool for the job.

    View Slide

  56. Why Compute Engine?

    View Slide

  57. Google Compute Engine
    Images by Connie
    Zhou

    View Slide

  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

    View Slide

  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

    View Slide

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

    View Slide

  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

    View Slide

  62. Local SSD
    Persistent Disk
    SSD PD
    Standard PD
    RO RW

    View Slide

  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

    View Slide

  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

    View Slide

  65. us-central1-a
    scheduled maintenance event
    Live Migration

    View Slide

  66. GCE and Docker

    View Slide

  67. GCE is a great place to run Redis.

    View Slide

  68. Application
    Tracks
    Comments
    Leaderboard
    Persistent Storage
    Temporary
    Storage
    API

    View Slide

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

    View Slide

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





    View Slide

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

    View Slide

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

    View Slide

  73. View Slide

  74. View Slide

  75. View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

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

    View Slide

  80. Demo - load balanced Redis

    View Slide

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

    View Slide

  82. Minimize risk
    keep the site up

    View Slide

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

    View Slide

  84. smoothly scaling abstractions
    Application
    Tracks
    Comments
    Leaderboard

    View Slide

  85. Deployment

    View Slide

  86. App Engine Modules
    Module
    Module
    Module
    Version
    Version
    Version
    Version
    VM
    Instance
    Instance
    Version
    Version
    VM
    Instance
    App

    View Slide

  87. Application
    Tracks
    Comments
    Leaderboard
    Persistent Storage
    Temporary
    Storage
    API

    View Slide

  88. Ease of management

    View Slide

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

    View Slide

  90. Two views

    View Slide

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

    View Slide

  92. View Slide

  93. View Slide

  94. View Slide

  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!

    View Slide

  96. Application
    Tracks
    Comments
    Leaderboard
    Persistent Storage
    Temporary
    Storage
    API

    View Slide

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

    View Slide

  98. Managed VMs and Beyond

    View Slide

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

    View Slide

  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…

    View Slide

  101. Autoscaling Replica Pool

    View Slide



  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

    View Slide

  103. Saving Mobile Data

    View Slide

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

    View Slide

  105. Your app here

    View Slide

  106. cloud.google.com
    Images by Connie Zhou

    View Slide