Building personalized experiences using Couchbase Sync Gateway – Couchbase Connect 2016

Preview:

Citation preview

©2016 Couchbase Inc. 1

The Couchbase Connect16 mobile appTake our in-app survey!

©2016 Couchbase Inc. 2

Questions? Tweet #Couchbase #SG

©2016 Couchbase Inc. 4

Building Personalized Experiences

Using Couchbase Sync Gateway

©2016 Couchbase Inc. 6

Introduction

Sync Gateway Features/Capabilities

Alternate Use Case: Digital Signage

Application Demonstration

Application Analysis (Code)

©2016 Couchbase Inc.

Couchbase Mobile: The Complete Mobile Database Solution

Couchbase Lite Sync Gateway Couchbase Server

EMBEDDED DATABASE SYNCHRONIZATION DATABASE SERVER

SECURITY

©2016 Couchbase Inc. 8

Sync Gateway Platform Features

©2016 Couchbase Inc. 9

ReST + Stream + BatchAPI

(Swagger)

©2016 Couchbase Inc. 10

DocumentDatabase

©2016 Couchbase Inc. 11www.flickr.com/photos/xmodulo

Blobs

©2016 Couchbase Inc.

Integration

Photo courtesy of Blue Coat (www.bluecoat.com) (CC BY-SA 2.0)

©2016 Couchbase Inc. 13

©2016 Couchbase Inc. 14

©2016 Couchbase Inc. 15

RBAC placeholder

Photograph taken by Dori (dori@merr.info)

Authorization

©2016 Couchbase Inc. 16

Security

©2016 Couchbase Inc. 17

©2016 Couchbase Inc. 18

Cross ClusterSync

CBServer

SyncGateway

©2016 Couchbase Inc. 19

STATE

©2016 Couchbase Inc. 20

SmallFootprint

©2016 Couchbase Inc. 21

©2016 Couchbase Inc. 23

©2016 Couchbase Inc. 24

http://en.wikipedia.org/wiki/File:Lightning_Strike_Bolts_3.jpg

Changes Feed

©2016 Couchbase Inc.

Business

Logic

©2016 Couchbase Inc. 26

ChannelSync

Function

Sync FunctionData routing

Business Logic

©2016 Couchbase Inc. 27

Digital Signage

©2016 Couchbase Inc. 28Photo courtesy of OnSign TV (CC BY 2.0)

©2016 Couchbase Inc. 29

©2016 Couchbase Inc. 30

©2016 Couchbase Inc. 31

©2016 Couchbase Inc. 32

©2016 Couchbase Inc. 33

©2016 Couchbase Inc. 34

Personalized Preferences

Live Demo

©2016 Couchbase Inc.

Flow

©2016 Couchbase Inc.

Live Demo

©2016 Couchbase Inc. 37

CODE

©2016 Couchbase Inc. 38

#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

Load Initial Data to Cloud

©2016 Couchbase Inc. 39

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

©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();

©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)); }

©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 Functionfunction(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"}); } }

©2016 Couchbase Inc. 43

Summary

©2016 Couchbase Inc.

Q&A

©2016 Couchbase Inc. 45

©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)

©2016 Couchbase Inc. 47

The Couchbase Connect16 mobile appTake our in-app survey!

Recommended