MN Enterprise Mobile User Group April 2015 Meeting
Transcript of MN Enterprise Mobile User Group April 2015 Meeting
@rbaconsultingwww.rbaconsulting.com blog.rbaconsulting.com
Mobile Sync with Couchbase and
Azure Mobile Services
Joe Koletar
A Digital and Technology Consultancy
Agenda
• Sync background
• Azure Mobile Services Sync
• Couchbase Sync
A Digital and Technology Consultancy
Mobile DataA
lways
Co
nnect
ed • Store data
remotely
• Access via REST
• Requires
connection
• Can be slowN
eve
r C
onnect
ed • Store data
locally
• Access via
SQLite
• Connection not
required
• Always available
So
metim
es
Co
nnect
ed • Store data
locally and
remotely
• Access via
SQLite and
REST
• Connection not
required
• Always available
A Digital and Technology Consultancy
What is Sync
• Supports occasionally connected mobile access.• Provides a rich user experience
• Retrieves updates when connected
• Store offline updates until connected
A Digital and Technology Consultancy
Sync Challenges
• Managing changes• Server
• Adds
• Deletes
• Updates
• Client• Adds
• Deletes
• Updates
• Need to resolve conflicts
A Digital and Technology Consultancy
Approaches to manage sync
• Timestamp
• Id hell
• Guids
• Compete replacement
A Digital and Technology Consultancy
Azure Mobile Services
• Can dynamically define tables• GUID Ids required
• Must create a SyncContext• Tracks PendingOperations
• Merges updates that haven’t been synced
A Digital and Technology Consultancy
Push/Pull/Purge
• PushAsync
• Must push all tables
• Maintains referential integrity
• PullAsync
• Works per table
• Can specify tables to pull via LINQ query
• Executes Push first to empty PendingOperations
• PurgeAsync
• Clears items from the local store
• Executes Push first to empty PendingOperations
A Digital and Technology Consultancy
Conflict resolution
• Throws MobileServicePushFailedException
• Can provide sync handler on client in InitializeAsync
public interface IMobileServiceSyncHandler
{
Task OnPushCompleteAsync
(MobileServicePushCompletionResult result);
Task<JObject> ExecuteTableOperationAsync
(IMobileServiceTableOperation operation);
}
A Digital and Technology Consultancy
Couchbase
• Awesome demo at Evolve
• Near instantaneous synchronization between devices
A Digital and Technology Consultancy
Sync Gateway
• Traffic cop of the configuration
• Bidirectional, multi-master sync
• Manages and authenticates users
• Authorizes document access
• Routes documents to users
A Digital and Technology Consultancy
Sync Gateway
• Two APIs• Sync REST API – port 4984
• Admin REST API – port 4985
• Sync Function
• Conflict resolution pushed to device
A Digital and Technology Consultancy
Couchbase Server
• Must have sync_gateway data bucket
• Stores synced data and corresponding metadata
A Digital and Technology Consultancy
Couchbase Client
• Database.CreatePullReplication
• Database.CreatePushReplication
A Digital and Technology Consultancy
Sync Function
• JavaScript Function• Enforce validity or schema
• Enforce role membership
• Tag document with channels
• Grant users access to channels
A Digital and Technology Consultancy
Sync Gateway
• Configuration• Command line
• JSON Configuration file
{ "log": ["CRUD+", "REST+", "Changes+", "Attach+"],
"databases": {
"sync_demo": {
"server":"http://localhost:8091",
"bucket":"sync_gateway",
"sync":`function(doc) channel(doc.channels);}`,
"users": {"GUEST": {"disabled": false,
"admin_channels": ["*"]}
}
}
}
}
A Digital and Technology Consultancy
Sync Gateway Users
• Sync Gateway manages mobile user accounts
• Authentication mechanisms• HTTP Basic
• Session cookie
• Custom
A Digital and Technology Consultancy
Channels
• Tags attached to documents
• Used to link users to documents
• Users mapped to channels
A Digital and Technology Consultancy
References
• Azure Mobile Services• http://channel9.msdn.com/Series/Windows-Azure-Mobile-Services/Build-
offline-apps-Azure-Mobile-Services
• http://blogs.msdn.com/b/azuremobile/archive/2014/04/07/deep-dive-on-the-offline-support-in-the-managed-client-sdk.aspx
• Couchbase• Evolve presentation: https://www.youtube.com/watch?v=g7WlnfvOvhI
• https://www.youtube.com/watch?v=g1EVj9B5Z6g