Developing Offline First Apps
with Xamarin and Couchbase Mobile
Always On and Available Mobile Apps
Martin Esmann
Developer Advocate, Developer Experience
1
Who’s to blame
Martin Esmann
Copenhagen
Windows/.NET
Enterprises, startups, students
@martinesmann –
martin@couchbase.com
2
Who is Couchbase?
Couchbase at a Glance
Fastest growing NoSQL
database company
4x growth in 2013
Mission critical use at
Internet scale
400+ customers; 10,000+ paid
production nodes deployed;
worldwide customer base
Leader in scalability &
performance
Easily & reliable scale your app;
Get consistent low latency &
high throughput
Worldwide operations
with 250+ employees
100+ in engineering; Offices in US,
UK, India, Japan, China (soon)
4
What is a NoSql Key-Value store?
7
Relational Data
User
Type Name
Int UserId
String Name
OrderLine
Type Name
Int OrderLineId
Int ProductId
String Product Name
Int ParentOrderId
Int Quantity
Order
Type Name
Int OrderId
String Title
Address OrderAddress
Int UserId
Product
Type Name
Int ProductId
double Price
String Product Name
String Description
Web Page
Order details for
user
[User, Order,
OrderLine’s,
Product]
8
De-normalizing data
User
Type Name
Int UserId
String Name
OrderLine
Type Name
Int OrderLineId
Int ProductId
String Product Name
Int ParentOrderId
Int Quantity
Order
Type Name
Int OrderId
String Title
Address OrderAddress
Int UserId
Product
Type Name
Int ProductId
double Price
String Product Name
String Description
Web Page
Order details for
user
[User, Order,
OrderLine’s,
Product]
9
Key-Value Storage
Web Page
Order details for
user
[User, Order,
OrderLine’s,
Product]
Document
{
”Order": {
"Id": ”Order-1-93459328572015",
”Address": ”Street, Copenhagen",
”OrderLines": [
”Order::21342134”,
“Order::34824282”
],
"Time": "2015-04-15T00:20:00",
”Header": ”New Monitors for developers",
”User": ”martinesmann"
},
"type": ”order"
}
Couchbase Mobile
What is the business problem?
Today’s Mobile Apps
12
Try again
later.
No Internet
please wait…
How does this affect what people think about your
app?
13
Doesn’t work a lot of the time and when
it does it’s slow.
How does this affect application uninstall
rates?
14
0%
20%
40%
60%
80%
100%
UninstallRate
Freezing
Crashing
Slow Responsiveness
Source: uSamp
Data Location is the Problem
15
Local Data + Sync is the Solution
16
What does this mean for your apps?
17
Always work both online & offline
Always perceived as being blazing fast
Built with orders of magnitude less code
Users get what they expect from a modern
app
What is Couchbase Mobile?
Couchbase Lite Sync Gateway
Couchbase Lite
NoSQL mobile database.
Runs in-process.
Small footprint.
Document-Oriented Database
o Key-value collections, with versioning
o Schemaless
o Code fast. Run fast
{
”Order": {
"Id": ”Order-1-93459328572015",
”Address": ”Street, Copenhagen",
”OrderLines": [
”Order::21342134”,
“Order::34824282”
],
"Time": "2015-04-15T00:20:00",
”Header": ”New Monitors for developers",
”User": ”martinesmann"
},
"type": ”order"
}
var database = Manager.SharedInstance
.GetDatabase("database-name");
var doc = database.CreateDocument();
doc.PutProperties(new Dictionary<string, object> {
{"key1","value1"},
{"key2","value2"}
});
var doc = database.GetDocument(id);
var value1 = doc1.UserProperties["key1"];
var value2 = doc1.UserProperties["key2"];
var doc = database.GetDocument(id);
doc.Delete();
o Build indexes in your native language
o Results are persisted for fast querying
o Just set breakpoints to debug!
MapReduce Indexes
Manager.SharedInstance.GetDatabase(DatabaseName)
.GetView("all-docs")
.SetMap((doc, emit) =>
{
emit(doc["_id"], null);
},
”revision#2");
o Listen/Observe for changes.
o Databases, queries, replications—even documents.
o Enables responsive code patterns.
Change Notifications
doc.Change += (sender, e) => {
if (e.Change.IsConflict)
{
// well then resolve it!
}
};
Sync
o Full multi-master replication.
o Continuous or ad-hoc in either direction.
o Change notifications & conflict detection.
o Filters, Authentication & Authorization
var pull =
Manager.SharedInstance.GetDatabase(DatabaseName).CreatePullReplication(RemoteSyncUrl);
pull.Continuous = true;
pull.Changed += ReplicationProgress;
pull.Start();
var push =
Manager.SharedInstance.GetDatabase(DatabaseName).CreatePushReplication(RemoteSyncUrl);
push.Continuous = true;
push.Changed += ReplicationProgress;
push.Start();
Cocoapods
Maven
Central
Nuget
Github
Demo
Couchbase Lite – Intro
o Authentication
o Authorization
o Data orchestration
Sync Gateway
33
o requireUser (username)
o requireRole (rolename)
o requireAccess (channels)
Sync Function
o channel (name)
o access (username, channelname)
o role (username, rolename)
Sync Function
Orders Products
Customers
Admin
{
"interface":":4984",
"adminInterface":":4985",
"log":["CRUD", "CRUD+", "HTTP", "HTTP+", "Access", "Cache", "Shadow",
"Shadow+", "Changes", "Changes+"],
"databases":{
"sync_gateway":{
"server":"http://10.0.0.4:8091",
"bucket":"sync_gateway",
"users": { "GUEST": {"disabled": false, "admin_channels": ["*"]}},
"sync":`function(doc) {channel(doc.channels);}`
}
}
}
Environment Setup
Couchbase Lite + Sync Gateway + Couchbase Server + Azure
App
What about the backend?
Couchbase Server - Multi-purpose
capabilities
High availability
cache
Key-value
store
Document
database
Embedded database Sync
management
Support’s a broad range of apps and use cases
Enterprises often start with cache, then broaden usage to other apps and use cases
Demo
Couchbase Lite – Sync demo
Questions?
Resources – continue the adventure
44
Couchbase Lite Documentation
http://developer.couchbase.com/mobile/develop/guides/couchbase-lite
Sync Gateway
http://developer.couchbase.com/mobile/develop/references/sync-gateway
Couchbase Server
http://docs.couchbase.com/admin/admin/Couchbase-intro.html
Couchbase Blogs
https://forums.couchbase.com
Demo Repo/Source
https://github.com/couchbaselabs/ToDoLite-Xamarin-Forms
Questions?
Continue the conversation online…
forums.couchbase.com
Thanks for listening!
Martin Esmann
Developer Advocate, Developer Experience
Twitter: martinesmann
E-mail: martin@couchbase.com

Offline First Apps With Couchbase Mobile and Xamarin

  • 1.
    Developing Offline FirstApps with Xamarin and Couchbase Mobile Always On and Available Mobile Apps Martin Esmann Developer Advocate, Developer Experience 1
  • 2.
    Who’s to blame MartinEsmann Copenhagen Windows/.NET Enterprises, startups, students @martinesmann – martin@couchbase.com 2
  • 3.
  • 4.
    Couchbase at aGlance Fastest growing NoSQL database company 4x growth in 2013 Mission critical use at Internet scale 400+ customers; 10,000+ paid production nodes deployed; worldwide customer base Leader in scalability & performance Easily & reliable scale your app; Get consistent low latency & high throughput Worldwide operations with 250+ employees 100+ in engineering; Offices in US, UK, India, Japan, China (soon) 4
  • 5.
    What is aNoSql Key-Value store?
  • 6.
    7 Relational Data User Type Name IntUserId String Name OrderLine Type Name Int OrderLineId Int ProductId String Product Name Int ParentOrderId Int Quantity Order Type Name Int OrderId String Title Address OrderAddress Int UserId Product Type Name Int ProductId double Price String Product Name String Description Web Page Order details for user [User, Order, OrderLine’s, Product]
  • 7.
    8 De-normalizing data User Type Name IntUserId String Name OrderLine Type Name Int OrderLineId Int ProductId String Product Name Int ParentOrderId Int Quantity Order Type Name Int OrderId String Title Address OrderAddress Int UserId Product Type Name Int ProductId double Price String Product Name String Description Web Page Order details for user [User, Order, OrderLine’s, Product]
  • 8.
    9 Key-Value Storage Web Page Orderdetails for user [User, Order, OrderLine’s, Product] Document { ”Order": { "Id": ”Order-1-93459328572015", ”Address": ”Street, Copenhagen", ”OrderLines": [ ”Order::21342134”, “Order::34824282” ], "Time": "2015-04-15T00:20:00", ”Header": ”New Monitors for developers", ”User": ”martinesmann" }, "type": ”order" }
  • 9.
  • 10.
    What is thebusiness problem?
  • 11.
    Today’s Mobile Apps 12 Tryagain later. No Internet please wait…
  • 12.
    How does thisaffect what people think about your app? 13 Doesn’t work a lot of the time and when it does it’s slow.
  • 13.
    How does thisaffect application uninstall rates? 14 0% 20% 40% 60% 80% 100% UninstallRate Freezing Crashing Slow Responsiveness Source: uSamp
  • 14.
    Data Location isthe Problem 15
  • 15.
    Local Data +Sync is the Solution 16
  • 16.
    What does thismean for your apps? 17 Always work both online & offline Always perceived as being blazing fast Built with orders of magnitude less code Users get what they expect from a modern app
  • 17.
  • 18.
  • 19.
    Couchbase Lite NoSQL mobiledatabase. Runs in-process. Small footprint.
  • 20.
    Document-Oriented Database o Key-valuecollections, with versioning o Schemaless o Code fast. Run fast
  • 21.
    { ”Order": { "Id": ”Order-1-93459328572015", ”Address":”Street, Copenhagen", ”OrderLines": [ ”Order::21342134”, “Order::34824282” ], "Time": "2015-04-15T00:20:00", ”Header": ”New Monitors for developers", ”User": ”martinesmann" }, "type": ”order" }
  • 22.
    var database =Manager.SharedInstance .GetDatabase("database-name"); var doc = database.CreateDocument(); doc.PutProperties(new Dictionary<string, object> { {"key1","value1"}, {"key2","value2"} }); var doc = database.GetDocument(id); var value1 = doc1.UserProperties["key1"]; var value2 = doc1.UserProperties["key2"]; var doc = database.GetDocument(id); doc.Delete();
  • 23.
    o Build indexesin your native language o Results are persisted for fast querying o Just set breakpoints to debug! MapReduce Indexes
  • 24.
  • 25.
    o Listen/Observe forchanges. o Databases, queries, replications—even documents. o Enables responsive code patterns. Change Notifications
  • 26.
    doc.Change += (sender,e) => { if (e.Change.IsConflict) { // well then resolve it! } };
  • 27.
    Sync o Full multi-masterreplication. o Continuous or ad-hoc in either direction. o Change notifications & conflict detection. o Filters, Authentication & Authorization
  • 28.
    var pull = Manager.SharedInstance.GetDatabase(DatabaseName).CreatePullReplication(RemoteSyncUrl); pull.Continuous= true; pull.Changed += ReplicationProgress; pull.Start(); var push = Manager.SharedInstance.GetDatabase(DatabaseName).CreatePushReplication(RemoteSyncUrl); push.Continuous = true; push.Changed += ReplicationProgress; push.Start();
  • 29.
  • 30.
  • 31.
    o Authentication o Authorization oData orchestration Sync Gateway
  • 32.
  • 33.
    o requireUser (username) orequireRole (rolename) o requireAccess (channels) Sync Function
  • 34.
    o channel (name) oaccess (username, channelname) o role (username, rolename) Sync Function
  • 35.
  • 36.
    { "interface":":4984", "adminInterface":":4985", "log":["CRUD", "CRUD+", "HTTP","HTTP+", "Access", "Cache", "Shadow", "Shadow+", "Changes", "Changes+"], "databases":{ "sync_gateway":{ "server":"http://10.0.0.4:8091", "bucket":"sync_gateway", "users": { "GUEST": {"disabled": false, "admin_channels": ["*"]}}, "sync":`function(doc) {channel(doc.channels);}` } } }
  • 37.
    Environment Setup Couchbase Lite+ Sync Gateway + Couchbase Server + Azure
  • 38.
  • 39.
  • 40.
    Couchbase Server -Multi-purpose capabilities High availability cache Key-value store Document database Embedded database Sync management Support’s a broad range of apps and use cases Enterprises often start with cache, then broaden usage to other apps and use cases
  • 41.
  • 42.
  • 43.
    Resources – continuethe adventure 44 Couchbase Lite Documentation http://developer.couchbase.com/mobile/develop/guides/couchbase-lite Sync Gateway http://developer.couchbase.com/mobile/develop/references/sync-gateway Couchbase Server http://docs.couchbase.com/admin/admin/Couchbase-intro.html Couchbase Blogs https://forums.couchbase.com Demo Repo/Source https://github.com/couchbaselabs/ToDoLite-Xamarin-Forms
  • 44.
    Questions? Continue the conversationonline… forums.couchbase.com
  • 45.
    Thanks for listening! MartinEsmann Developer Advocate, Developer Experience Twitter: martinesmann E-mail: martin@couchbase.com

Editor's Notes

  • #4 Who is Couchbase?
  • #5 Couchbase at a Glance We had 4x growth in 2013 but we are an entirely Open Sourced company and project. We are deployed world wide across mission critical use. With more 250 employees, we are also hiring. [Click]
  • #6 Enterprise Customers Across our product lines we got customers in the “Services and Consumer” industries as well as the “Enterprise” space. Some of our customers are listed here as you can see. [Click]