RBA's (www.rbaconsulting.com) Enterprise Mobile Technology Lead, Joe Koletar, presented at the April 16 Minnesota Enterprise Mobile User Group on the topic of Synchronizing Mobile Data Using Couchbase and Azure.
2. A Digital and Technology Consultancy
Agenda
• Sync background
• Azure Mobile Services Sync
• Couchbase Sync
3. A Digital and Technology Consultancy
Mobile DataAlwaysConnected
• Store data
remotely
• Access via REST
• Requires
connection
• Can be slow NeverConnected
• Store data
locally
• Access via
SQLite
• Connection not
required
• Always available
SometimesConnected
• Store data
locally and
remotely
• Access via
SQLite and
REST
• Connection not
required
• Always available
4. 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
5. A Digital and Technology Consultancy
Sync Challenges
• Managing changes
• Server
• Adds
• Deletes
• Updates
• Client
• Adds
• Deletes
• Updates
• Need to resolve conflicts
6. A Digital and Technology Consultancy
Approaches to manage sync
• Timestamp
• Id hell
• Guids
• Compete replacement
7. A Digital and Technology Consultancy
Azure Mobile Services
9. 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
10. 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
11. 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);
}
12. A Digital and Technology Consultancy
Couchbase
• Awesome demo at Evolve
• Near instantaneous synchronization between devices
15. 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
16. 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
17. A Digital and Technology Consultancy
Couchbase Server
• Must have sync_gateway data bucket
• Stores synced data and corresponding metadata
18. A Digital and Technology Consultancy
Couchbase Client
• Database.CreatePullReplication
• Database.CreatePushReplication
19. 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