online training - couchbase mobile 101
TRANSCRIPT
Couchbase*M101:**Mobile*Architecture
Jasdeep*Jaitla*Technical)Evangelist
twi8er:)@scalabl3email:)[email protected]
Architecture*of*Couchbase*Mobile
JSON*Anywhere
On Mobile Device In Data Center/CloudIn Data Center/Cloud
JSON*Anywhere
On Mobile Device In Data Center/CloudIn Data Center/Cloud
JSON*Anywhere
On Mobile Device In Data Center/CloudIn Data Center/Cloud
JSON*Anywhere
On Mobile Device In Data Center/CloudIn Data Center/Cloud
TradiAonal*Mobile
ApplicaAon*ServerREST*Services
TradiAonal*Mobile
ApplicaAon*ServerREST*Services
TradiAonal*Mobile
ApplicaAon*ServerREST*Services
Construction/Deconstruction of
JSON
RDBMS Style Local Storage
TradiAonal*Mobile
ApplicaAon*ServerREST*Services
Complex Sync Code
Complex Sync Code While Offline or Cannot Use App
While Offline
Construction/Deconstruction of
JSON
RDBMS Style Local Storage
TradiAonal*Mobile
ApplicaAon*ServerREST*Services
Complex Sync Code
Complex Sync Code While Offline or Cannot Use App
While Offline
Construction/Deconstruction of
JSON
RDBMS Style Local Storage
Mobile*DBaaS
DBaaSREST*Services
Mobile*DBaaS
DBaaSREST*Services
Simple Storage Only
Mobile*DBaaS
DBaaSREST*Services
Scaling Expensive/Slow
Simple Storage Only
Mobile*DBaaS
DBaaSREST*Services
Scaling Expensive/Slow
Simple Storage Only
Mobile*DBaaS
DBaaSREST*Services
RDBMS Style Local Storage
Scaling Expensive/Slow
Simple Storage Only
Mobile*DBaaS
DBaaSREST*Services
RDBMS Style Local Storage
Complex Sync Code
Scaling Expensive/Slow
Simple Storage Only
JSON*Anywhere*G*Automated*Sync
JSON*Anywhere*G*Automated*Sync
JSON*Anywhere*G*Automated*Sync
Synchronization Automated when Connectivity Present
Couchbase*Lite
Couchbase*Lite*
The*only*Na3ve*NoSQL*Database*for*
Mobile*
Couchbase*LiteThe)only)NoSQL)Database)for)Mobile)Devices
Couchbase*Lite**iOS*
Couchbase*Lite**
Android*
Lite
Features*UltraDlightweight,)secure)JSON)database))NaIve)support)for)iOS,)Android)and)REST/HTML5)
Powerful)conflict)resoluIon)Automated)Sync)
Couchbase*Lite*Features
• Use*JSON*in*your*Mobile*App*Data*Tier*
• Always*Work*with*Local*Data*on*Device*
• Modify*schema*dynamically,*super*flexible*
• When*Connected:**Create*New*Data*and*Change*Documents,*they*Sync*AutomaAcally*
• When*Not*Connected:*Work*with*solid*local*NoSQL*database*
• Powerful*conflict*resoluAon*features
Partner*IntegraAons
Adobe*PhoneGap*
!
Appcelerator*Titanium*
!
Xamarin
PhoneGap)Integra.on)Couchbase*Lite*Plug1in*for*PhoneGap*
• Support*for*HTML5*developers*• Develop*once*in*JavaScript*and*deploy*
on*iOS*&*Android*• Available*on*GitHub,*Cordova*Plugin*
Registry,*and*coming*soon*to*build.phonegap.com*
*
hHps://github.com/couchbaselabs/Couchbase1Lite1PhoneGap1Plugin*
hHp://plugins.cordova.io/#/com.couchbase.lite.phonegap*
Xamarin'Integra,on'Couchbase*Lite*for*Xamarin*
• Partnered*to*support*C#*community*• Available*on*Developer*Center*• Includes*sample*applica=on*to*help*
developers*get*started*today*
h?p://components.xamarin.com/view/couchbaseElite/*
Appcelerator*Integra.on*Couchbase*Lite*Titanium*
• Build*rich*na5ve*apps*for*iOS*&*
Android*using*JavaScript*SDK*
• Now*available*on*the*Appcelerator*
Marketplace*
hEps://github.com/couchbaselabs/couchbaseIliteI5tanium/*
hEps://marketplace.appcelerator.com/apps/6706?1396013098*
Couchbase*Sync*Gateway
What*is*the*Sync*Gateway?
• Sync Operations/Management • User Authentication• User channel configuration• User roles and info (name, email, password)• User enable/disable
Couchbase Sync Gateway is a server side program that sits in front of Couchbase Server to manage sync and sync administration
Sync*Gateway*Overview
Sync Gateway
Subcomponents Couchbase Smart ClientSync REST API
Subcomponents*of*Sync*Gateway
Sync Gateway
Authentication
Sync FunctionConflict
Management/Revisions
Couchbase Smart ClientSync REST API
Channel Change Tracking
The*Sync*FuncAon
function(doc,+oldDoc)+{+!
}
Sync Function
The*Sync*FuncAon
function(doc,+oldDoc)+{+!
}
json doc
Sync Function
The*Sync*FuncAon
function(doc,+oldDoc)+{+!
}
json doc previous revision, if any
Sync Function
The*Sync*FuncAon• Defined*in*the*Sync*Gateway*Launch*ConfiguraAon*
• Processes*Documents*and*Sync*FuncAons*Calls*
• Creates*associaAons*between*Documents,*Channels,*Users*and*Roles*
!
• Sync*FuncAons*Calls:*• channel*(channels)**
• access*(usersGroles,*channels)*
• role*(users,*roles)*
• throw({*type:*“message”})
Sync Function
channel()Associate)JSON)Document)with)a)Channel
function(doc,+oldDoc)+{+channel+(doc.channel_name)+
}
• Channel*Names*are*strings*(i.e.*“food”,*“chatG12939”)*
• Associate*this*Document*to*Channel*or*Array*of*Channels*
• Overwrites*previous*associaAons,*can*change*channels
Sync Function
channel()Associate)JSON)Document)with)a)Channel
function(doc,+oldDoc)+{+channel+(doc.channel_name)+
}associates this doc
with channel
• Channel*Names*are*strings*(i.e.*“food”,*“chatG12939”)*
• Associate*this*Document*to*Channel*or*Array*of*Channels*
• Overwrites*previous*associaAons,*can*change*channels
channel()
• Channels*organize*what*JSON*Documents*are*synchronized*down*to*which*Users*
• Users*are*associated*with*Channels*
• Users*are*associated*with*Roles**
• Roles*are*associated*with*Channels*
• Channels*are*defined*as*JSON*strings*or*array*of*strings*within*the*JSON*Document
channel()
Channels*organize*what*JSON*Documents*are*synchronized*down*to*which*Users
User*A
User*B
User*C
JSONdoc.channels*:*“food”
JSONdoc.channels*:*[*“food”,*“sports”*]
JSONdoc.channels*:*[*“sports”,*“travel”*]
channels:*food
channels:*sports
channels:*food,*travel
User*D*creates*Content*
with*Channel*associaAonThese*Users*Subscribed**
to*Content*Channels
channel()
Channels*organize*what*JSON*Documents*are*synchronized*down*to*which*Users
User*A
User*B
User*C
JSONdoc.channels*:*“food”
JSONdoc.channels*:*[*“food”,*“sports”*]
JSONdoc.channels*:*[*“sports”,*“travel”*]
channels:*food
channels:*sports
channels:*food,*travel
User*D*creates*Content*
with*Channel*associaAonThese*Users*Subscribed**
to*Content*Channels
channel()
Channels*organize*what*JSON*Documents*are*synchronized*down*to*which*Users
User*A
User*B
User*C
JSONdoc.channels*:*“food”
JSONdoc.channels*:*[*“food”,*“sports”*]
JSONdoc.channels*:*[*“sports”,*“travel”*]
channels:*food
channels:*sports
channels:*food,*travel
User*D*creates*Content*
with*Channel*associaAonThese*Users*Subscribed**
to*Content*Channels
channel()
Channels*organize*what*JSON*Documents*are*synchronized*down*to*which*Users
User*A
User*B
User*C
JSONdoc.channels*:*“food”
JSONdoc.channels*:*[*“food”,*“sports”*]
JSONdoc.channels*:*[*“sports”,*“travel”*]
channels:*food
channels:*sports
channels:*food,*travel
User*D*creates*Content*
with*Channel*associaAonThese*Users*Subscribed**
to*Content*Channels
channel()
Channels*organize*what*JSON*Documents*are*synchronized*down*to*which*Users
User*A
User*B
User*C
JSONdoc.channels*:*“food”
JSONdoc.channels*:*[*“food”,*“sports”*]
JSONdoc.channels*:*[*“sports”,*“travel”*]
channels:*food
channels:*sports
channels:*food,*travel
User*D*creates*Content*
with*Channel*associaAonThese*Users*Subscribed**
to*Content*Channels
channel()
Channels*organize*what*JSON*Documents*are*synchronized*down*to*which*Users
User*A
User*B
User*C
JSONdoc.channels*:*“food”
JSONdoc.channels*:*[*“food”,*“sports”*]
JSONdoc.channels*:*[*“sports”,*“travel”*]
channels:*food
channels:*sports
channels:*food,*travel
User*D*creates*Content*
with*Channel*associaAonThese*Users*Subscribed**
to*Content*Channels
channel()
Channels*organize*what*JSON*Documents*are*synchronized*down*to*which*Users
User*A
User*B
User*C
JSONdoc.channels*:*“food”
JSONdoc.channels*:*[*“food”,*“sports”*]
JSONdoc.channels*:*[*“sports”,*“travel”*]
channels:*food
channels:*sports
channels:*food,*travel
User*D*creates*Content*
with*Channel*associaAonThese*Users*Subscribed**
to*Content*Channels
access()Grants)access)to)channels)
• Associate*a*User,*or*Array*of*Users*to*one*or*more*Channels*
• Associate*a*Role*(group*of*Users)*to*one*or*more*Channels
Sync Function
function(doc,+oldDoc)+{+access+(doc.friends,+doc.channels)+
}
access()Grants)access)to)channels)
• Associate*a*User,*or*Array*of*Users*to*one*or*more*Channels*
• Associate*a*Role*(group*of*Users)*to*one*or*more*Channels
Sync Function
function(doc,+oldDoc)+{+access+(doc.friends,+doc.channels)+
}associates users/roles
with channel(s)
role()grants)users)a)role
• Associate*a*User,*or*Array*of*Users*to*one*or*more*Roles*
• Roles*can*give*enAre*groups*of*Users*access*to*Channels
Sync Function
function(doc,+oldDoc)+{+role+(doc.friends,+roles)+
}
role()grants)users)a)role
• Associate*a*User,*or*Array*of*Users*to*one*or*more*Roles*
• Roles*can*give*enAre*groups*of*Users*access*to*Channels
Sync Function
function(doc,+oldDoc)+{+role+(doc.friends,+roles)+
}associates user(s)
with role(s)
throw()validate)documents,)prevent)syncing/modificaIons
• ValidaAon*of*document*data*and*associaAons*
• ValidaAon*of*authenAcaAon
Sync Function
function(doc,+oldDoc)+{+throw+({+type:+“message”})+
}
throw()validate)documents,)prevent)syncing/modificaIons
• ValidaAon*of*document*data*and*associaAons*
• ValidaAon*of*authenAcaAon
Sync Function
function(doc,+oldDoc)+{+throw+({+type:+“message”})+
}invalidates this
document
Collaborate*with*Channels
• For*each*document,*you*specify*a*set*of*channels*it*belongs*to*
• For*each*user*or*device,*you*control*which*channels*they*can*access*
• Replicate*only*a*subset*of*documents*down*to*the*device*
• UserDdefined)filter)funcIons))• Simply)lets)you)know)whether)a)document)should)be)replicated)• And*you*can*authenAcate*users*with*Facebook*
and*Persona
DEMO
Q*&*A