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

Look ma, no server! Creating mobile apps on bac...

Clay Smith
November 28, 2015

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

Clay Smith

November 28, 2015
Tweet

More Decks by Clay Smith

Other Decks in Programming

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. 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
  5. LOOK MA, NO SERVER NOT SHOWN IN PREVIOUS DIAGRAM ▸

    Security ▸ Server Provisioning ▸ Deploying ▸ Monitoring and Alerting ▸ Scaling
  6. MOST OF YOU ARE FAMILIAR WITH THE VIRTUES OF A

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

    CC flickr.com/photos/veljovic/15738348069
  8. "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
  9. 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).
  10. 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)
  11. PRACTICAL BAAS FOR A SIMPLE APP LET'S SEE SOME CODE!

    CC flickr.com/photos/hackny/6890140478
  12. 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
  13. 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
  14. 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.
  15. 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
  16. LOOK MA, NO SERVER! PARSE COOLNESS: CONVERTING AN ANONYMOUS USER

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

    = new ParseUser(); user.setUsername("username"); user.setPassword("pass"); user.setEmail("[email protected]"); user.signUpInBackground(); // ref is a reference to your Firebase URL ref.createUser("[email protected]", "pass", new Firebase.ValueResultHandler<Map<String, Object>>() { // callbacks }); FIREBASE PARSE
  18. 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
  19. 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) { } });
  20. 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.
  21. 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!
  22. 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
  23. 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
  24. 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)
  25. AN EVENT IS A SIGNIFICANT CHANGE IN THE STATE OF

    THE UNIVERSE. K. Mani Chandy, "Towards a Theory of Events" LOOK MA, NO SERVER!
  26. 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
  27. 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.
  28. 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.
  29. 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!
  30. 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.
  31. 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)
  32. 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.