Look ma, no server! Creating mobile apps on backend-as-a-service platforms

2ad55a66b8325eb097612c069ab76231?s=47 Clay Smith
November 28, 2015

Look ma, no server! Creating mobile apps on backend-as-a-service platforms

2ad55a66b8325eb097612c069ab76231?s=128

Clay Smith

November 28, 2015
Tweet

Transcript

  1. CREATING MOBILE APPS IN A BACKEND-AS-A-SERVICE WORLD LOOK, MA: NO

    SERVER! CLAY SMITH, NEW RELIC - DEVFEST VIENNA 2015 @SMITHCLAY
  2. LOOK MA, NO SERVER! ABOUT ME Web App Dev Mobile

    Dev burritos Dev Advocate @ New Relic
  3. LOOK MA, NO SERVER! AGENDA THE 2015 APP MODERN BACKENDS

    INTRO TO BAAS EVENT-DRIVEN BAAS PERFORMANCE
  4. THE 2015 APP

  5. MULTIPLATFORM

  6. INTERNATIONAL

  7. COOLSENSORS

  8. SUPERRESPONSIVE

  9. CONNECTED CC flickr.com/photos/hernanpc/18954719651

  10. YEAR EXABYTES MOBILE DATA* *Google "mobile data growth" for a

    real graph.
  11. LOOK MA, NO SERVER! COMMON APP NETWORK REQUESTS ▸ API

    Requests (3rd-party or internal) ▸ Analytics ▸ Static Content ▸ Images ▸ Video ▸ Audio CC0 stock.tookapic.com/photos/20932
  12. PUSHNOTIFICATIONS

  13. APP BACKENDS MAKING YOUR MOBILE DREAMS A REALITY

  14. REMEMBER THESE? CC flickr.com/photos/dominichargreaves/2345869796

  15. IAAS, AT YOUR SERVICE CC flickr.com/photos/doctorow/14574108306 IT'S ALL IN THE

    CLOUD
  16. LOOK MA, NO SERVER NOT SHOWN IN PREVIOUS DIAGRAM ▸

    Security ▸ Server Provisioning ▸ Deploying ▸ Monitoring and Alerting ▸ Scaling
  17. PAAS, PLEASE DON'T WANT TO WORRY ABOUT INFRASTRUCTURE?

  18. git push PaaS master MAGIC!

  19. MOST OF YOU ARE FAMILIAR WITH THE VIRTUES OF A

    PROGRAMMER... LAZINESS, IMPATIENCE, AND HUBRIS Larry Wall, creator of Perl LOOK MA, NO SERVER!
  20. WE ARE MOVING TO VERY HIGH-LEVEL ABSTRACTIONS FOR APP BACKENDS

    CC flickr.com/photos/veljovic/15738348069
  21. VERY HIGH-LEVEL ABSTRACTIONS != EASIER

  22. BACKEND AS A SERVICE A THING SINCE ~2011

  23. YE OLDE BACKEND

  24. TRADITIONAL VERY SIMPLIFIED WEB APP ARCHITECTURE

  25. NEW STUFF BACKEND AS A SERVICE

  26. "A MODEL FOR PROVIDING... DEVELOPERS WITH A WAY TO LINK

    THEIR APP TO BACKEND CLOUD STORAGE AND APIS." Mobile BaaS: Wikipedia Definition CC flickr.com/photos/hrathmann/19646314070
  27. STORAGE

  28. SINGLESIGNON

  29. FANCYCONSOLES

  30. MULTIPLATFORM

  31. CLIENTLIBRARIES

  32. PUSHNOTIFICATIONS

  33. REALTIMESTUFF

  34. SECURITY?

  35. THE BAAS BIG 3*

  36. PARSE (FACEBOOK) FOUNDED IN 2011, ACQUIRED IN 2013.

  37. FIREBASE (GOOGLE) FOUNDED 2011, ACQUIRED 2014. REALTIME FOCUS.

  38. CLOUDKIT (APPLE) "ICLOUD FOR DEVELOPERS" - DONE THE APPLE WAY

  39. LOOK MA, NO SERVER! ALSO WORTH MENTIONING ▸ Apache Usergrid

    (OSS) ▸ Amazon Mobile Hub (now in beta) ▸ Azure Mobile Web Services (Microsoft) ▸ Kivney, Synaco, Apigee, Appcelerator (and many more).
  40. LOOK MA, NO SERVER! HOW BAAS PROVIDERS MATURE (TYPICALLY) DATABASE

    AUTHENTICATION EVERYTHING ELSE
  41. LOOK MA, NO SERVER! IMPORTANT BAAS METRICS ($) ▸ Number

    of requests per minute ▸ Data transfer (network I/O) ▸ Storage cost (persistence) ▸ Database ▸ Assets (Images, Audio, Video, etc)
  42. PRACTICAL BAAS FOR A SIMPLE APP LET'S SEE SOME CODE!

    CC flickr.com/photos/hackny/6890140478
  43. LOOK MA, NO SERVER! SOME ASSEMBLY REQUIRED - ANDROID dependencies

    { compile 'com.parse.bolts:bolts-android:1.+' compile 'com.parse:parse-android:1.+' } dependencies { compile 'com.firebase:firebase-client-android:2.4.0+' } FIREBASE PARSE firebase.com/docs/android/quickstart.html parse.com/apps/quickstart
  44. LOOK MA, NO SERVER! SOME INITIALIZATION REQUIRED - INITIALIZATION (ANDROID)

    Parse.initialize(this, "api-key", "client-key"); // Activity#onCreate Firebase.setAndroidContext(this); // Activity#onCreate Firebase myFirebaseRef = new Firebase("https://my-app.firebaseio.com/"); FIREBASE PARSE firebase.com/docs/android/quickstart.html parse.com/apps/quickstart
  45. AUTH MORE THAN USER + PASS CC flickr.com/photos/111692634@N04/11406965045

  46. LOOK MA, NO SERVER! SINGLE-SIGN ON SUPPORT Type Parse Firebase

    CloudKit Facebook Y Y N Google N Y N Username/Pass Y Y N Anonymous Y Y Y* Twitter Y Y N Github N Y N iCloud N N Y OAuth Y Y N * Based on publicly available documentation as of 11/6/2015.
  47. LOOK MA, NO SERVER! ANONYMOUS AUTH - ANDROID ParseUser.enableAutomaticUser(); ParseUser.getCurrentUser();

    // Exists! // ref is a reference to your Firebase URL ref.authAnonymously(new Firebase.AuthResultHandler() { // ... } ); FIREBASE PARSE firebase.com/docs/android/quickstart.html parse.com/apps/quickstart
  48. LOOK MA, NO SERVER! PARSE COOLNESS: CONVERTING AN ANONYMOUS USER

    TO REAL USER ParseAnonymousUtils.isLinked(ParseUser.getCurrentUser())
  49. LOOK MA, NO SERVER! USERNAME/PASSWORD AUTH - ANDROID ParseUser user

    = new ParseUser(); user.setUsername("username"); user.setPassword("pass"); user.setEmail("email@example.com"); user.signUpInBackground(); // ref is a reference to your Firebase URL ref.createUser("email@example.com", "pass", new Firebase.ValueResultHandler<Map<String, Object>>() { // callbacks }); FIREBASE PARSE
  50. DATA PERSIST ALL THE THINGS CC flickr.com/photos/rh2ox/9990024683

  51. LOOK MA, NO SERVER! YESTERSPRINT: AN EXAMPLE SPRINT RETROSPECTIVE APP

  52. LOOK MA, NO SERVER! PARSE - CREATING AND FETCHING ParseObject

    newRetro = new ParseObject("Retro");
 newRetro.put("createdBy", ParseUser.getCurrentUser()); // Creates a retrospective to many users relationship.
 newRetro.getRelation("members").add(ParseUser.getCurrentUser());
 newRetro.saveInBackground(); ParseQuery<ParseObject> query = ParseQuery.getQuery("Retro");
 query.whereEqualTo("members", ParseUser.getCurrentUser());
 // Execute query in background thread
 query.findInBackground(new FindCallback<ParseObject>() { // ... } ); FETCHING CREATING
  53. LOOK MA, NO SERVER! FIREBASE - CREATING AND FETCHING Firebase

    retroRef = ref.child("retros"); Map<String, String> newRetro = new HashMap<String, String>(); newRetro.put("createdBy", "clay"); retroRef.push().setValue(newRetro); FETCHING CREATING ref.child("user/clay/retros").addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snap) { } @Override public void onCancelled(FirebaseError error) { } });
  54. LOOK MA, NO SERVER! REALTIME EVENTS SIDEBAR - HOW DO

    THEY DO IT? ▸ CloudKit: Uses Apple Push Notifications ▸ Firebase: Uses websockets ▸ Parse: good old fashioned HTTP.
  55. ALL FIREBASE DATABASE DATA IS STORED AS JSON OBJECTS. THERE

    ARE NO TABLES OR RECORDS. firebase.com/docs/android/guide/understanding-data.html LOOK MA, NO SERVER!
  56. LOOK MA, NO SERVER! OFFLINE READY Parse.enableLocalDatastore(this); // must be

    called before Parse.initialize()! retrospective.saveEventually(); // when the network is available, it will save. FIREBASE PARSE // Automagic... mostly. Firebase.getDefaultConfig().setPersistenceEnabled(true); // between app restarts
  57. LOOK MA, NO SERVER! UI HELPERS TO MAKE IT SUPER

    EASY ▸ ParseQueryAdapter - Connects a list of parse data to an Android ListView (ParseUI-Android) ▸ FirebaseListAdapter - Same for Firebase (FirebaseUI- Android) CC flickr.com/photos/groovenite
  58. LOOK MA, NO SERVER! NOT DISCUSSED (FURTHER READING SUGGESTED) ▸

    Authorization - who gets what ▸ Geo data (both Parse and Firebase) ▸ Push Notifications (Parse only) ▸ Analytics (Parse only)
  59. EVENT-DRIVEN BAAS

  60. WEBHOOKS ARE "USER-DEFINED HTTP CALLBACKS" en.wikipedia.org/wiki/Webhook CC https://www.flickr.com/photos/versageek

  61. AN EVENT IS A SIGNIFICANT CHANGE IN THE STATE OF

    THE UNIVERSE. K. Mani Chandy, "Towards a Theory of Events" LOOK MA, NO SERVER!
  62. LOOK MA, NO SERVER! WEBHOOKS: EVERYTHING BECOMES EVENT-DRIVEN

  63. LOOK MA, NO SERVER! PARSE: WEBHOOKS AND CLOUD CODE ▸

    webhooks: a URL gets hit when beforeSave and afterSave gets called on a ParseObject ▸ Cloud Code: custom endpoints, triggers. ▸ Static hosting and Heroku support, too. CC flickr.com/photos/infomastern/14719723237
  64. LOOK MA, NO SERVER! FIREBASE EVENT-DRIVEN APPROACH USING THEIR NODE.JS

    CLIENT ▸ Node.js server listens for events using the firebase node library, then *does other stuff* ▸ More code, but still really useful. ▸ https://github.com/firebase/flashlight (Firebase Elastic Search) ▸ New: Google Cloud modules.
  65. LOOK MA, NO SERVER! AMAZON WEB SERVICES: "CLOUD LOGIC" IN

    MOBILE HUB (IN BETA) ▸ Exposes AWS Lambda Functions easily to mobile apps. ▸ Lambda: event driven, integrates with other major AWS services. ▸ Write once, run on multiple platforms. ▸ Current (late 2015) languages: node.js, python, java.
  66. LOOK MA, NO SERVER! PARSE - RUNNING A CLOUD CODE

    FUNCTION (JAVA/ANDROID) ParseCloud.callFunctionInBackground("myAwesomeFn", params, new FunctionCallback() { public void done(Object object, ParseException e) { // TODO: Handle response } } LOOK MA, NO BACKEND!
  67. PERFORMANCE HOW BAAS DOES IN REAL LIFE... CC flickr.com/photos/monthouphoto

  68. LAZY BENCHMARKING

  69. LOOK MA, NO SERVER! TEST: SET {"FOO":"BAR"} IN PARSE OR

    FIREBASE'S DATABASE ▸ Track how long it takes to get a success response for the server. ▸ Run the operation in JavaScript, track with a simple timer. ▸ Run the code in Singapore, Sydney, Sao Paulo, Dublin, Frankfurt, Washington DC and San Francisco.
  70. LOOK MA, NO SERVER1 NEW RELIC SYNTHETICS SCRIPT (I.E. SELENIUM)

    WEB PAGE (USING BAAS JAVASCRIPT SDKS) CREATE OBJ PARSE API FIREBASE API PUSH INSIGHTS (NRDB = METRICS DATABASE) CREATE OBJ SYNTHETICS (RUNS A WEB PAGE IN DIFFERENT PLACES)
  71. MILLISECONDS

  72. MILLISECONDS

  73. TL;DR: BE AWARE OF GEOGRAPHY

  74. LOOK MA, NO SERVER! FREE PLAN COMPARISON (IT'S DIFFICULT TO

    UNDERSTAND) Type Parse Firebase* CloudKit* File Transfer 2 TB 100 GB 2 GB File Storage 20 GB 1 GB 10 GB Database Storage 20 GB 1 GB 100 MB Requests per sec 30 100 40 * Based on publicly available documentation as of 11/6/2015. CloudKit limits grow with active user count.
  75. TO BAAS OR NOT TO BAAS?

  76. QUESTIONS? CLAY SMITH, NEW RELIC @SMITHCLAY