Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Building personalized experiences using Couchbase Sync Gateway – Couchbase Connect 2016

289 views

Published on

Personalizing real-world user experience presents an enormous business opportunity, along with many challenges. Recall your last plane flight. Surely your preferences extend beyond "aisle or window."

Sync Gateway, part of the Couchbase Mobile stack, integrates secure HTTP(S)-based REST, stream, and batch APIs with data replication, data routing, authentication, access control, and eventing functions. Combined with the Couchbase document-model data representation, Sync Gateway becomes a service platform enabling the rapid development of new, novel applications. In some instances, Sync Gateway can completely replace your application layer.

This talk will examine these capabilities in the context of driving personalized interactions on digital displays. We’ll review Sync Gateway. We’ll then dive into an example application. Using passenger experience for illustration, you'll leave the session with practical examples of how to flexibly build personalizable experiences in a fraction of the time you thought possible.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Building personalized experiences using Couchbase Sync Gateway – Couchbase Connect 2016

  1. 1. ©2016 Couchbase Inc. 1 The Couchbase Connect16 mobile app Take our in-app survey!
  2. 2. ©2016 Couchbase Inc. 2 Questions?Tweet #Couchbase #SG
  3. 3. ©2016 Couchbase Inc. Building Personalized Experiences Using Couchbase Sync Gateway 4
  4. 4. ©2016 Couchbase Inc. 6 Introduction Sync Gateway Features/Capabilities Alternate Use Case: Digital Signage Application Demonstration Application Analysis (Code)
  5. 5. ©2016 Couchbase Inc. Couchbase Mobile:The Complete Mobile Database Solution Couchbase Lite Sync Gateway Couchbase Server EMBEDDED DATABASE SYNCHRONIZATION DATABASE SERVER SECURITY
  6. 6. ©2016 Couchbase Inc. Sync Gateway Platform Features 8
  7. 7. ©2016 Couchbase Inc. 9 ReST + Stream + Batch API (Swagger)
  8. 8. ©2016 Couchbase Inc. 10 Document Database
  9. 9. ©2016 Couchbase Inc. 11 www.flickr.com/photos/xmodulo Blobs
  10. 10. ©2016 Couchbase Inc. I n t e g r a t i o n Photo courtesy of Blue Coat (www.bluecoat.com) (CC BY-SA 2.0)
  11. 11. ©2016 Couchbase Inc. 13
  12. 12. ©2016 Couchbase Inc. 14
  13. 13. ©2016 Couchbase Inc. 15 RBAC placeholder Photograph taken by Dori (dori@merr.info) Authorization
  14. 14. ©2016 Couchbase Inc. 16 S e c u r i t y
  15. 15. ©2016 Couchbase Inc. 17
  16. 16. ©2016 Couchbase Inc. 18 Cross Cluster Sync CB Server Sync Gateway
  17. 17. ©2016 Couchbase Inc. 19
  18. 18. ©2016 Couchbase Inc. 20 Small Footprint
  19. 19. ©2016 Couchbase Inc. 21
  20. 20. ©2016 Couchbase Inc. 23
  21. 21. ©2016 Couchbase Inc. 24
  22. 22. ©2016 Couchbase Inc. B u s i n e s s
  23. 23. ©2016 Couchbase Inc. 26 Sync Function Sync Function Data routing Business Logic
  24. 24. ©2016 Couchbase Inc. Digital Signage 27
  25. 25. ©2016 Couchbase Inc. 28 Photo courtesy of OnSignTV (CC BY 2.0)
  26. 26. ©2016 Couchbase Inc. 29
  27. 27. ©2016 Couchbase Inc. 30
  28. 28. ©2016 Couchbase Inc. 31
  29. 29. ©2016 Couchbase Inc. 32
  30. 30. ©2016 Couchbase Inc. 33
  31. 31. ©2016 Couchbase Inc. Personalized Preferences Live Demo 34
  32. 32. ©2016 Couchbase Inc. Flow
  33. 33. ©2016 Couchbase Inc. Live Demo
  34. 34. ©2016 Couchbase Inc. 37
  35. 35. ©2016 Couchbase Inc. #Load the data for fqname in ./data/*.json; do filename=`basename $fqname` response=$(curl -s -X PUT -H "Content-Type: application/json” -d "@$fqname" "$cloudurl/prefer/${filename%.*}") done #Load the data for fqname in ./data/*.json; do filename=`basename $fqname` response=$(curl -s -X PUT -H "Content-Type: application/json” -d "@$fqname" "$cloudurl/prefer/${filename%.*}") done #Load the data for fqname in ./data/*.json; do filename=`basename $fqname` response=$(curl -s -X PUT -H "Content-Type: application/json” -d "@$fqname" "$cloudurl/prefer/${filename%.*}") done 38 Load Initial Data to Cloud
  36. 36. ©2016 Couchbase Inc. body=' { "source": ”cloud", "target": "'$url'", "continuous": false }' response=$(curl -s -X POST -H "Content-Type: application/json” -d "$body" "$cloudurl/_replicate") body=' { "source": ”cloud", "target": "'$url'", "continuous": false }' response=$(curl -s -X POST -H "Content-Type: application/json” -d "$body" "$cloudurl/_replicate") body=' { "source": "cloud", "target": "'$url'", "continuous": false }' response=$(curl -s -X POST -H "Content-Type: application/json” -d "$body" "$cloudurl/_replicate") Replicate Cloud to Plane 39
  37. 37. ©2016 Couchbase Inc. 40 documentChangeListener = new CouchbaseDocumentChangeListener(config.url, config.getChannels()); documentChangeListener.addListener( function(doc) { if(doc.type == "preference_group") { … } } else if(doc.type == "passenger") { } else if(doc.type == "passenger_preferences") { self.passengerPreferences = doc; self.preferenceBeverage = self.selectedBeverage = doc.preferences[0].selectedBeverage; … } } , function(doc) { return true; } ); documentChangeListener.start(); Changes Feed documentChangeListener = new CouchbaseDocumentChangeListener(config.url, config.getChannels()); documentChangeListener.addListener( function(doc) { if(doc.type == "preference_group") { … } } else if(doc.type == "passenger") { } else if(doc.type == "passenger_preferences") { self.passengerPreferences = doc; self.preferenceBeverage = self.selectedBeverage = doc.preferences[0].selectedBeverage; … } } , function(doc) { return true; } ); documentChangeListener.start(); documentChangeListener = new CouchbaseDocumentChangeListener(config.url, config.getChannels()); documentChangeListener.addListener( function(doc) { if(doc.type == "preference_group") { … } } else if(doc.type == "passenger") { } else if(doc.type == "passenger_preferences") { self.passengerPreferences = doc; self.preferenceBeverage = self.selectedBeverage = doc.preferences[0].selectedBeverage; … } } , function(doc) { return true; } ); documentChangeListener.start(); documentChangeListener = new CouchbaseDocumentChangeListener(config.url, config.getChannels()); documentChangeListener.addListener( function(doc) { if(doc.type == "preference_group") { … } } else if(doc.type == "passenger") { } else if(doc.type == "passenger_preferences") { self.passengerPreferences = doc; self.preferenceBeverage = self.selectedBeverage = doc.preferences[0].selectedBeverage; … } } , function(doc) { return true; } ); documentChangeListener.start(); documentChangeListener = new CouchbaseDocumentChangeListener(config.url, config.getChannels()); documentChangeListener.addListener( function(doc) { if(doc.type == "preference_group") { … } } else if(doc.type == "passenger") { } else if(doc.type == "passenger_preferences") { self.passengerPreferences = doc; self.preferenceBeverage = self.selectedBeverage = doc.preferences[0].selectedBeverage; … } } , function(doc) { return true; } ); documentChangeListener.start();
  38. 38. ©2016 Couchbase Inc. 41 savepreferences: function (event) { this.passengerPreferences.preferences[0].selectedMixer = this.selectedMixer; … //Push doc to server var url = config.url; url += "/"+this.passengerPreferences._id; url += "?rev="+this.passengerPreferences._rev; var _http = new XMLHttpRequest(); _http.open("PUT", url); _http.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); _http.setRequestHeader( 'Authorization', 'Basic ' + btoa( "p4" + ':' + "p453cur1ty" ) ); _http.withCredentials = true; _http.send(JSON.stringify(this.passengerPreferences)); } Update Preferences savepreferences: function (event) { this.passengerPreferences.preferences[0].selectedMixer = this.selectedMixer; … //Push doc to server var url = config.url; url += "/"+this.passengerPreferences._id; url += "?rev="+this.passengerPreferences._rev; var _http = new XMLHttpRequest(); _http.open("PUT", url); _http.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); _http.setRequestHeader( 'Authorization', 'Basic ' + btoa( "p4" + ':' + "p453cur1ty" ) ); _http.withCredentials = true; _http.send(JSON.stringify(this.passengerPreferences)); } savepreferences: function (event) { this.passengerPreferences.preferences[0].selectedMixer = this.selectedMixer; … //Push doc to server var url = config.url; url += "/"+this.passengerPreferences._id; url += "?rev="+this.passengerPreferences._rev; var _http = new XMLHttpRequest(); _http.open("PUT", url); _http.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); _http.setRequestHeader( 'Authorization', 'Basic ' + btoa( "p4" + ':' + "p453cur1ty" ) ); _http.withCredentials = true; _http.send(JSON.stringify(this.passengerPreferences)); } savepreferences: function (event) { this.passengerPreferences.preferences[0].selectedMixer = this.selectedMixer; … //Push doc to server var url = config.url; url += "/"+this.passengerPreferences._id; url += "?rev="+this.passengerPreferences._rev; var _http = new XMLHttpRequest(); _http.open("PUT", url); _http.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); _http.setRequestHeader( 'Authorization', 'Basic ' + btoa( "p4" + ':' + "p453cur1ty" ) ); _http.withCredentials = true; _http.send(JSON.stringify(this.passengerPreferences)); } savepreferences: function (event) { this.passengerPreferences.preferences[0].selectedMixer = this.selectedMixer; … //Push doc to server var url = config.url; url += "/"+this.passengerPreferences._id; url += "?rev="+this.passengerPreferences._rev; var _http = new XMLHttpRequest(); _http.open("PUT", url); _http.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); _http.setRequestHeader( 'Authorization', 'Basic ' + btoa( "p4" + ':' + "p453cur1ty" ) ); _http.withCredentials = true; _http.send(JSON.stringify(this.passengerPreferences)); }
  39. 39. ©2016 Couchbase Inc. 42 function(doc, oldDoc) { if (doc.type == "flight") { //Add flight details to the public channel visible to all entertainment systems channel("!"); } else if ( doc.type == "preference_group") { //Add preference group docs to the public channel visible to all units channel("!"); } else if (doc.type == "passenger") { //Create a channel for the passenger record channel("passenger-"+doc.passengerid); access(doc.seatnumber,"passenger-"+doc.passengerid); } else if (doc.type == "passenger_preferences") { requireUser(doc.seatnumber); channel("passenger-"+doc.passengerid); } else { //Reject all other document types, they aren’t part of this application throw({forbidden : "Unknown document type"}); } } Plane Sync Function function(doc, oldDoc) { if (doc.type == "flight") { //Add flight details to the public channel visible to all entertainment systems channel("!"); } else if ( doc.type == "preference_group") { //Add preference group docs to the public channel visible to all units channel("!"); } else if (doc.type == "passenger") { //Create a channel for the passenger record channel("passenger-"+doc.passengerid); access(doc.seatnumber,"passenger-"+doc.passengerid); } else if (doc.type == "passenger_preferences") { requireUser(doc.seatnumber); channel("passenger-"+doc.passengerid); } else { //Reject all other document types, they aren’t part of this application throw({forbidden : "Unknown document type"}); } } function(doc, oldDoc) { if (doc.type == "flight") { //Add flight details to the public channel visible to all entertainment systems channel("!"); } else if ( doc.type == "preference_group") { //Add preference group docs to the public channel visible to all units channel("!"); } else if (doc.type == "passenger") { //Create a channel for the passenger record channel("passenger-"+doc.passengerid); access(doc.seatnumber,"passenger-"+doc.passengerid); } else if (doc.type == "passenger_preferences") { requireUser(doc.seatnumber); channel("passenger-"+doc.passengerid); } else { //Reject all other document types, they aren’t part of this application throw({forbidden : "Unknown document type"}); } } function(doc, oldDoc) { if (doc.type == "flight") { //Add flight details to the public channel visible to all entertainment systems channel("!"); } else if ( doc.type == "preference_group") { //Add preference group docs to the public channel visible to all units channel("!"); } else if (doc.type == "passenger") { //Create a channel for the passenger record channel("passenger-"+doc.passengerid); access(doc.seatnumber,"passenger-"+doc.passengerid); } else if (doc.type == "passenger_preferences") { requireUser(doc.seatnumber); channel("passenger-"+doc.passengerid); } else { //Reject all other document types, they aren’t part of this application throw({forbidden : "Unknown document type"}); } } function(doc, oldDoc) { if (doc.type == "flight") { //Add flight details to the public channel visible to all entertainment systems channel("!"); } else if ( doc.type == "preference_group") { //Add preference group docs to the public channel visible to all units channel("!"); } else if (doc.type == "passenger") { //Create a channel for the passenger record channel("passenger-"+doc.passengerid); access(doc.seatnumber,"passenger-"+doc.passengerid); } else if (doc.type == "passenger_preferences") { requireUser(doc.seatnumber); channel("passenger-"+doc.passengerid); } else { //Reject all other document types, they aren’t part of this application throw({forbidden : "Unknown document type"}); } } function(doc, oldDoc) { if (doc.type == "flight") { //Add flight details to the public channel visible to all entertainment systems channel("!"); } else if ( doc.type == "preference_group") { //Add preference group docs to the public channel visible to all units channel("!"); } else if (doc.type == "passenger") { //Create a channel for the passenger record channel("passenger-"+doc.passengerid); access(doc.seatnumber,"passenger-"+doc.passengerid); } else if (doc.type == "passenger_preferences") { requireUser(doc.seatnumber); channel("passenger-"+doc.passengerid); } else { //Reject all other document types, they aren’t part of this application throw({forbidden : "Unknown document type"}); } } function(doc, oldDoc) { if (doc.type == "flight") { //Add flight details to the public channel visible to all entertainment systems channel("!"); } else if ( doc.type == "preference_group") { //Add preference group docs to the public channel visible to all units channel("!"); } else if (doc.type == "passenger") { //Create a channel for the passenger record channel("passenger-"+doc.passengerid); access(doc.seatnumber,"passenger-"+doc.passengerid); } else if (doc.type == "passenger_preferences") { requireUser(doc.seatnumber); channel("passenger-"+doc.passengerid); } else { //Reject all other document types, they aren’t part of this application throw({forbidden : "Unknown document type"}); } }
  40. 40. ©2016 Couchbase Inc. Summary 43
  41. 41. ©2016 Couchbase Inc. Q&A
  42. 42. ©2016 Couchbase Inc. 45
  43. 43. ©2016 Couchbase Inc. 46 Share your opinion on Couchbase 1. Go here: http://gtnr.it/2eRxYWn 2. Create a profile 3. Provide feedback (~15 minutes)
  44. 44. ©2016 Couchbase Inc. 47 The Couchbase Connect16 mobile app Take our in-app survey!

×