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

Mobility in the cloud

Mobility in the cloud

Building an AppEngine backend for your mobile app without much coding.

Video of the screencast mentioned in the talk: http://www.youtube.com/watch?v=5lGcr4dblgE

Avatar for Roman Kirillov

Roman Kirillov

November 01, 2013
Tweet

More Decks by Roman Kirillov

Other Decks in Technology

Transcript

  1. Mobility in the Cloud Building an AppEngine backend for your

    mobile app without much coding. Roman Kirillov google.com/+RomanKirillov
  2. Why Cloud for Mobile? Scale on Demand Analytics for User

    Engagement and Retention Global Availability Focus on developing your App - reduced time to market Apps powered by a backend are more engaging
  3. Google Infrastructure Performance Redundancy Disaster Recovery Audits & Certifications Security

    Energy Efficient Global Data Centers 99.95% Uptime SLA Compute Storage Services Compute Engine (IaaS) App Engine (PaaS) Cloud Storage (Object) Cloud SQL (Relational) Cloud Datastore (NoSQL) BigQuery Cloud EndPoints Caching Queues and more... Cloud Platform Google Services
  4. • Platform-as-a-service • Popular Programming Language Support • Auto-scaling •

    Versioning and Traffic Splitting • Static Content Serving and Caching • Local Developer Tools • European Zones for Locality and Compliance • Google FrontEnds protect against DOS attacks • Integrated Auth for Google Accounts App Engine Features
  5. “ With Google App Engine, we don't need a system

    administrator or anyone dedicated to deploying our app, so 99% of our time is working on our application.. ” Ben Kamens, Lead Engineer Khan Academy
  6. Compute Engine Need to go outside App Engine? On-demand VMs

    (RHEL/CentOS, Debian) • 1-8 virtual cores • 1.8-6.5GB RAM/core • Shared Core VMs 3 storage types • Local/scratch: 420GB • Persistent disk: 10TB • Cloud Storage: unlimited 3 interfaces • Command-line interface • Web-based interface • Your code via REST API
  7. Chrome World-Wide Maze • HTML5 game, mostly running in browser

    • Requires low-latency communication between phone (controller) and desktop (display) Why Compute Engine? • Websocket server - needs low-latency, consistent network I/O & long-running connections Source: http://www.html5rocks.com/en/tutorials/casestudies/world_wide_maze/
  8. Products Google BigQuery Analyze your app's data and build custom

    dashboards of your core metrics using the same technology used at Google.
  9. Data Analysis Power Tool SELECT kick_ass_product_plan AS strategy, AVG(kicking_factor) AS

    awesomeness FROM lots_of_data GROUP BY strategy +-------------+----------------+ | strategy | awesomeness | +-------------+----------------+ | "Forty-two" | 1000000.01 | +-------------+----------------+ 1 row in result set (10.2 s) Scanned 100GB A brief history of BigQuery
  10. • 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 Cloud Endpoints: APIs made easy • Tools available for generating Client Libraries for Android, iOS and JavaScript • Built-In Authentication Support
  11. Java - App Engine Cloud Endpoints - Custom API Send

    Game Invitation @ApiMethod(httpMethod = "PUT", path ="game/{gameId}/invitation/{playerId}") public InvitationResult sendInvitation( @Named("gameId") Long gameId, @Named("playerId") Long playerId, User user) throws ServiceException { } Java - Android App InvitationResult invitation = gameBackend.sendInvitation( gameId, playerId)).execute();
  12. • App Engine supports mobile device messaging ◦ Apple Push

    Notifications (using Sockets API)* ◦ Google Cloud Messaging (using GCM Server) • GCM Messages ◦ Send-to-sync (collapsible) ◦ Send with Payload (Non-Collapsible) • Examples ◦ Notification of new emails on Server ◦ Send game invites from friends ◦ Display ‘toasts’ with important messages Push Notifications Apple Push Notifications Service *See Orchestrating iOS Push Notifications on Google Cloud Platform (http://goo.gl/GpmyMz)
  13. • Inverse of traditional search engines ◦ Which Queries would

    retrieve this document? • Queries registered in advance of documents (hence prospective) • Documents ◦ Python dictionary ◦ datastore.Entity ◦ db.Model derived class • Query Rules ◦ Simple Queries: ‘rose’ ◦ Field Queries: ‘author:rose’ • Search Operators ◦ AND, OR, NOT Prospective Search Mobile Backend Running On Google App Engine Instances
  14. Prospective Search Code Flow Java - App Engine CloudQuery cq

    = new CloudQuery("Contact"); cq.setFilter(F.eq("group", "friends")); cq.setScope(Scope.FUTURE_AND_PAST); List<CloudEntity> results = cloudBackendAsync.list(cq, handler);
  15. Ready to deploy, general purpose Cloud Backend + General Purpose

    Client side Framework What is the Mobile Backend Starter?
  16. 1. Next, download the Android client project 2. Open the

    project in your Android IDE. Locate the Consts.java file and set the PROJECT_ID to the Project ID of the project in which you created the Mobile Backend Starter Android Client project Build and run the project. You have a cloud enabled Android application!
  17. Google Cloud Messaging 1 2 3 4 1. Application server

    sends message to GCM 2. Google enqueues the message and stores it if device is offline 3. Once device is online, Google sends message(s) to the device 4. Android processes message via Intent Broadcast, waking up the app to process it.
  18. Google Cloud Messaging Application Server 65541212161L (Sender ID) Application ID

    (package name from manifest) Registration ID (issued by GCM to each device) [email protected] AIzzSmq78hIOlwUU4nq8dD (Server API key) Registration ID (issued by GCM to each device) Listen to whom? Who wants to listen? Who’s talking? Identifies an instance of app on the server Speaking to whom? cool-beanbag-383.appspot.com (Application URL) “cool-beanbag-383” (Project ID)
  19. Enable Google Cloud Messaging Consts.java Enable Cloud Messaging for Android

    in “APIs & auth” section and replace project number in Consts.java. Now application “knows” whom it should listen to.
  20. [kirillov@kirillov:/home/kirillov]$ keytool -exportcert \ -alias androiddebugkey \ -keystore .android/debug.keystore -list

    -v Alias name: androiddebugkey ... ... Certificate fingerprints: MD5: 21:52:24:BA:62:42:64:DA:AA:8D:AF:DD:90:FE:EC:CC SHA1: 0E:73:4C:8B:3B:EE:F3:5B:1B:35:2A:C7:8C:FC:35:0B:FA:71:34:80 ... Enable Google Cloud Messaging 1 2 3
  21. Application Server 624491884055- fpeqjdnf78pjqu13pdp1219vbuf.apps. googleusercontent.com (Android Client ID) 624491884055- 102e3nt459n26fv9mc4vsd7p2l.apps.

    googleusercontent.com (Web Client ID) com.google.cloud.backend.android (Android package) 10:94:27:04:4d:9f:f6:6e:bc:15:61: d9:ee:3d:7f:9f:73:b1:71:05 (SHA1 fingerprint) 624491884055- 102e3nt459n26fv9mc4vsd7p2l.apps. googleusercontent.com (Web Client ID) Same developer, no need for consent screen Produced by combining package and SHA1 fingerprint Google Cloud Endpoints Application Signature Google Authentication for Android
  22. [kirillov@kirillov:/home/kirillov]$ keytool -exportcert \ -alias androiddebugkey \ -keystore .android/debug.keystore -list

    -v Alias name: androiddebugkey ... ... Certificate fingerprints: MD5: 21:52:24:BA:62:42:64:DA:AA:8D:AF:DD:90:FE:EC:CC SHA1: 0E:73:4C:8B:3B:EE:F3:5B:1B:35:2A:C7:8C:FC:35:0B:FA:71:34:80 ... Re-using existing key 1 2 3
  23. Define Handler CloudCallbackHandler<List<CloudEntity>> cloudCallBackHandler = new CloudCallbackHandler<List<CloudEntity>>() { @Override public

    void onComplete(List<CloudEntity> messages) { /* message processing logic, e.g. show a Toast */ } }; Pub/Sub Messaging Subscribe CloudBackendMessaging cloudBackendMessaging = new CloudBackendMessaging(activity); cloudBackendMessaging.subscribeToCloudMessage("DevFest", cloudCallBackHandler);
  24. Send Message CloudBackendMessaging cloudBackendMessaging = new CloudBackendMessaging(activity); CloudEntity ce =

    cloudBackendMessaging.createCloudMessage(“DevFest”); ce.put(“chatMessage”, <chat message about how great GDG DevFest is>); cloudBackendMessaging.sendCloudMessage(ce); Send Message
  25. Register Query CloudBackendAsync cloudBackendAsync = new CloudBackendAsync(activity); CloudQuery cq =

    new CloudQuery(“MyEvents”); cq.setFilter(F.eq(“hashtag”, “#DevFestUK”)); cq.setScope(Scope.FUTURE_AND_PAST); List<CloudEntity> results = cloudBackendAsync.list(cq, cloudCallBackHandler); Continuous Queries
  26. • Solution Papers https://cloud.google.com/resources/tutorials-articles • Sample Applications https://github.com/googlecloudplatform • Mobile

    Backend Starter https://developers.google.com/cloud/samples/mbs (http://goo.gl/VIbmV) • Google I/O Sessions https://developers.google.com/events/io/ Resources
  27. Geek Serendipity Google I/O Session on Mobile Backend Starter* Blog

    and Walkthrough: http://goo.gl/Evgucq *A little out of date due to Cloud Console changes, watch the docs for updates at http://goo.gl/VIbmV