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 full-size slide

  2. Demo - overview

    View full-size slide

  3. Application
    Tracks
    Comments
    Leaderboard
    Persistent Storage
    Temporary
    Storage
    API

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size 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 full-size slide

  9. Cloud Datastore

    View full-size slide

  10. 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 full-size slide

  11. • 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 full-size slide

  12. Other situations?

    View full-size slide

  13. 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 full-size slide

  14. ● 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 full-size slide

  15. Files
    images, videos, backups...

    View full-size slide

  16. 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 full-size slide

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

    View full-size slide

  18. How can we share the walks?

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  22. 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 full-size slide

  23. No need for this...

    View full-size slide

  24. Can handle changes in demand...

    View full-size slide

  25. 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 full-size slide

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

    View full-size slide

  27. 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 full-size slide

  28. Building a RESTful API from scratch

    View full-size slide

  29. 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 full-size slide

  30. Simplifying API Development

    View full-size slide

  31. 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 full-size slide

  32. 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 full-size slide

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

    View full-size slide

  34. Other situations?

    View full-size slide

  35. 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 full-size slide

  36. 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 full-size slide

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

    View full-size slide

  38. Build it yourself on Compute Engine?

    View full-size slide

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



    View full-size slide

  40. Comment SPAM

    View full-size slide

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



    View full-size slide

  42. Managed VMs makes this easy

    View full-size slide

  43. Demo - captcha

    View full-size 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 full-size slide

  45. Comments Leaderboard

    View full-size 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 full-size slide

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

    View full-size slide

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

    View full-size slide

  49. Why Compute Engine?

    View full-size slide

  50. Google Compute Engine
    Images by Connie
    Zhou

    View full-size slide

  51. 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 full-size slide

  52. 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 full-size slide

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

    View full-size slide

  54. 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 full-size slide

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

    View full-size slide

  56. 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 full-size slide

  57. ● 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 full-size slide

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

    View full-size slide

  59. GCE and Docker

    View full-size slide

  60. GCE is a great place to run Redis.

    View full-size slide

  61. Application
    Tracks
    Comments
    Leaderboard
    Persistent Storage
    Temporary
    Storage
    API

    View full-size slide

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

    View full-size slide

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





    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  67. 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 full-size slide

  68. 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 full-size slide

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

    View full-size slide

  70. Demo - load balanced Redis

    View full-size slide

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

    View full-size slide

  72. Minimize risk
    keep the site up

    View full-size slide

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

    View full-size slide

  74. smoothly scaling abstractions
    Application
    Tracks
    Comments
    Leaderboard

    View full-size slide

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

    View full-size slide

  76. Application
    Tracks
    Comments
    Leaderboard
    Persistent Storage
    Temporary
    Storage
    API

    View full-size slide

  77. Ease of management

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  80. 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 full-size slide

  81. Application
    Tracks
    Comments
    Leaderboard
    Persistent Storage
    Temporary
    Storage
    API

    View full-size slide

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

    View full-size slide

  83. Managed VMs and Beyond

    View full-size slide

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

    View full-size slide

  85. 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 full-size slide

  86. Autoscaling Replica Pool

    View full-size slide



  87. 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 full-size slide

  88. Saving Mobile Data

    View full-size slide

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

    View full-size slide

  90. Your app here

    View full-size slide

  91. cloud.google.com
    Images by Connie Zhou

    View full-size slide