Couchbase for Mobile
Jessica Liu – Product Manager
J. Chris Anderson – Mobile Architect
Couchbase Lite
The only Native NoSQL Database for
Mobile
MainframeGreen Terminal
Millions of users
Thousands of Apps
PC Client/ServerLAN/Internet
Hundreds of Millions of users
Tens of Thousands
of Apps
CloudMobile Devices & Apps
Trillions of Things
Billions of users
Millions of Apps
Mobile – The Next Generation Platform
1980 1990 2020+2000 2010
Mobile – The Next Generation of Apps
Couchbase Server
Single User Interaction - Voice, Text - Personal Apps
Multi-User Interactions - Group and Social (Facebook, Games, Video)
Local Sensor Applications e.g., Medical
Interactingwith Enterprises
JSON Anywhere
Couchbase Server
• JSON on the device Developers
increasingly prefer NoSQL database
• JSON on the wire No need for data
transformation
• JSON in the cloud Flexible data model High performance Easy scalability
JS N
JS N
JS N
The Complete Mobile Solution
Architecture
Server 3Server 1 Server 2
Couchbase Server
Channel
Sync Gateway
Channel Channel
Sync Gateway
Channel
Couchbase Lite for iOS and Android
On Premise In the cloud
Before Couchbase Lite…
•Locally, could use SQLite or Core Data This works well for apps using relational algebra, and/or not data-intensive However this does not suit the needs for mobile developers interested in an
intuitive and flexible data store
•For sync and storage, could use a file-sharing service like Dropbox or iCloud Not an actual database; ownership, insight, and analytics unavailable
•Or alternatively, could use MBaaS like Parse or Kinvey But, it missed out on the offline experience, and we are still very much in an
occasionally connected world; to write a good app, you need to think offline
Couchbase LiteThe only NoSQL Database for Mobile Devices
•Features Ultra-lightweight, secure JSON
database Native support for iOS, Android
and REST/HTML5 Full document, index and
querying and sync capabilities Powerful conflict resolution
Couchbase Lite
Android
Couchbase Lite iOS
Couchbase LiteFull Feature List
Features Benefits
Native APIs Manage your mobile database using APIs optimized specifically for iOS and Android
REST APIs REST APIs provide an alternative access method based on your development needs
JSON support Use a flexible data model designed for mobile object-oriented apps. Adapt to your application needs with immediacy and little impact
Easy sync with Couchbase Sync Gateway Get sync-ready in less than a few lines of code. Focus on application development, not syncing
Peer to peer support via REST APIs
Communicate with nearby devices, even offline, with our REST API-enabled P2P support
Data routing via channels Get users only the data they need for a focused, relevant app experience
Changes Feed
Provides developers visibility and notification into data changes
Indexing and querying for JSON Use powerful secondary indexes to query your data on the device
Authentication plug-ins Use popular existing third-party authentication services like Facebook and Mozilla Person instead of writing your own
Attachment support on device and in the cloud Manage binary data, like photos and large files, separately from your JSON documents for optional, speedier sync
What you get
Couchbase Lite
Android
Couchbase Lite iOS
Enable new class of rich data intensive local applications
Rapid development using native JSON data
Highly responsive interactive applications
Always available - online or offline
What you get
JSON Anywhere
•Flexible JSON on device lets you work with local data & modify your data structure on the fly without impacting your back-end.
•Your users can count on having an amazing app experience with a fast and unbreakable local database
Easy Sync
•Effortlessly sync local data with a database in the cloud for updates, replication or collaborative sharing.
•In addition, scale your data tier horizontally and reliably as your data and sync needs grow.
JSONJSONJSON
JSONJSON
IntegrationsCouchbase Lite Plug-in 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
https://github.com/couchbaselabs/Couchbase-Lite-PhoneGap-Plugin
http://plugins.cordova.io/#/com.couchbase.lite.phonegap
IntegrationsCouchbase Lite for Xamarin
• Partnered to support C# community• Available on Developer Center• Includes sample application to help
developers get started today
http://components.xamarin.com/view/couchbase-lite/
IntegrationsCouchbase Lite Titanium
• Build rich native apps for iOS & Android using JavaScript SDK
• Now available on the Appcelerator Marketplace
https://github.com/couchbaselabs/couchbase-lite-titanium/
https://marketplace.appcelerator.com/apps/6706?1396013098
Couchbase Sync GatewayEasy, Reliable Data Sync to the Cloud
•Features• Dynamic sync capabilities via Sync
Function APIs• Easy Administration• Seamless scaleout
•Benefits 10x reduction in development
time Scales to support millions of users
How does sync work?
Collaborate using 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 User-defined filter functions Simply lets you know whether a document should be replicated
•And you can authenticate users
Doc 1 Channel A
Doc 2
Channel A
Channel B
Channel A & B
Channel B
Doc 1Doc 2
Doc 2
Data Routing
Data
Data
Data
Data
Data Routing
Data
Data
DataData
Data
Data
Data Routing
Data Data
DataData
Data
Data
Data
Data
Data Routing
Data
Data
DataData
DataData
Data
Data
Data
Data
Data Routing
Data
Data
DataData
Dat
aDat
a DataData
Data
Data
Data
Data
Data Routing
Data
Data
Data
Data
Dat
aDat
a DataData
Data
Data
Data
Data
The Power of Mobile - LearningThen Now
Classrooms, Whiteboards, One-Size-Fits-All Learning
Multi-Media, Self-Paced, Adaptive,Interactive, Anywhere Anytime
The Power of Mobile - Point of SaleThen Now
Big + odd looking machines, receipt printers, cash drawers
Simple, elegant tablet + square reader, email receipts, touch signing
The Power of Mobile - ExpensesThen Now
Paper receipts, manual spreadsheet entry, paper signature routing
Email/photo receipt, e-routing, e-signature
How do I get started?
Zero to sync in 5
minutes !!!
A little deep dive
• Get familiar with Couchbase Lite through looking at an application
• Introduce the app with a demo create a list / live query my lists create some tasks / live query tasks sign in to the cloud collaborate via the cloud
• Show the code for the features as we use them
Application Runtime (OS Process)
StorageStorage
Couchbase LiteCouchbase Lite
Native Application LogicNative Application Logic
Sync
Couchbase Lite Components
Key-ValueKey-ValueJSON JSON
StorageStorage
Sync Sync EngineEngine
Map/ReduceMap/ReduceView IndexerView Indexer
Query EngineQuery Engine
Application APIApplication API
Application Runtime (OS Process)
StorageStorage
Couchbase LiteCouchbase Lite
Native Application LogicNative Application Logic
Sync
PhoneGap Plugin
StorageStorage
Couchbase LiteCouchbase Lite
SyncREST ConnectorREST Connector
Web RuntimeWeb Runtime
PhoneGap PhoneGap PluginsPlugins
Camera, etcCamera, etc JavaScriptJavaScriptApplication LogicApplication Logic
XHR AjaxXHR Ajax
getURL(function(err, url){getURL(function(err, url){console.log(url)console.log(url)})})
Demo Features
JSON / REST interface
-CRUD operations use HTTP verbs
-Works with libraries like jQuery and BackboneLive Query UI Updates
-UI updated to reflect database changes, even for remote changes
-HTTP long poll API to support quick redraw
Collaborate via Cloud-social network login
-programmable sync function for update validation and channel routing
JSON Document Schema
All Todo Lists
•Rendered with HTML and JavaScript
•View query to show all the lists on a device.
•Form submit event creates a document representing a list.
Task List - Items
•Toggle a checkbox
•Add a photo
•Live update
Toggle a Task Checkboxby updating the JSON Document
Uses a familiar REST paradigm. GET and PUT used here.
Live Update UI
Local and remote updates both trigger a database event, used for redraw.
Sign-in to sync and collaborate
•Example uses Facebook, we support a wide variety of authentication option
•Pick from the list of signed in users when sharing
Photo Attachment
Sync Gateway Components
SyncSyncREST APIREST API
Couchbase Couchbase Smart Smart ClientClient
Revision/Revision/Conflict Conflict
ManagemeManagementnt
AuthenticatiAuthenticationon
AppApp’’s Sync s Sync FunctionFunction
Channel Channel Change Change TrackingTracking
External External Auth Auth
ServicesServices
to client
to Couchbase Server
Sync Function
•Application code run in the cloud
•Access control
•Channel routing
•Update Validation
Your cloud in one page of code.
Sync Gateway: App Logic & Storage
Couchbase Couchbase Smart Smart ClientClient
Revision/Revision/Conflict Conflict
ManagemeManagementnt
AppApp’’s Sync s Sync FunctionFunction
to Couchbase Server
function(doc, oldDoc) {…requireUser(oldDoc.owner);…channel(doc.channel);…access(doc.members, doc.roomID);}
function(doc, oldDoc) {…requireUser(oldDoc.owner);…channel(doc.channel);…access(doc.members, doc.roomID);}
validation
validationroutingroutingaccess access ctrlctrl
rev 1 rev 2
rev 3a
rev 3b
AuthenticatiAuthenticationon
Get Started
mobile.couchbase.com
Sample App
https://github.com/couchbaselabs/TodoLite-PhoneGap
Couchbase Cloud
http://www.couchbasecloud.com