| Dec 08, 2016

3 MIN READ

Written by Ashnik Team
Data Pipeline and Analytics

Couchbase Mobile for secure and easy access, sync and storage of Mobile data

In this day and age of Big data, where data is raw material of business and is mined, analyzed to get precious information, organizations cannot afford to lose data.

Recently we came across a requirement where customer who is one of the leading insurance providers in South East Asia. The Customer wanted the data on their agent’s (field agents) devices to be uploaded onto a common server. This was  particularly required to ensure that the data on the device is not lost due to sudden loss of device and can be retrieved. The new system was to also ensure that any centralized changes including Policy changes or product launch, gets reflected to the individual devices of their agents.

The requirement as such seems pretty straight. It requires a two-way sync set-up between the device and the database server. However, developing a sync from the device to a database server can be a tricky thing if the solution needs to be built from scratch. The sync function should efficiently handle the conflicts, access and secure synchronization of data.
The real challenge was handling all the above without draining the user’s battery and the function staying generic and modifiable, leads to complexities and requires enormous amount of effort and time. This can be avoided using Couchbase Mobile.
What is Couchbase Mobile?
Couchbase Mobile is a NoSQL database for mobile. It can be used for building fast, powerful and secure mobile and web apps. It provides a fully-integrated embedded database, real-time synchronization and highly scalable database server. The embedded database on the device can be synced with the Couchbase database server, via the Couchbase Sync Gateway.
Couchbase Mobile has three major components:

  • Couchbase Lite is the embedded NOSQL database that manages and stores data locally on the device. It has a very small footprint. The data fed into the device is primarily stored in the Couchbase Lite database. This is then synced to the Couchbase server.
  • Sync Gateway provides the synchronization between Couchbase lite database and Couchbase server. Being the middleware, acts as data orchestrator between the device and the server. It provides a HTTP listener that acts as a passive replication endpoint for Couchbase lite and uses a Couchbase server bucket as a persistent storage for all database documents. User authorization, data routing, validating documents, etc., are handled by Sync Gateway through the Sync function API.
  • Couchbase Server is the data store or database server that stores and manages data. Couchbase is primarily a NoSQL document database which provides the flexibility of JSON with the power of SQL.

How Couchbase Mobile solved the challenge?
Couchbase mobile is designed to make the lives of mobile developers very easy and stress free.
The NoSQL database on Couchbase Mobile ensures the use of schema-less documents. The data is stored in the form of JSON documents. Couchbase Lite is the embedded database on the iOT device and provides fast access to documents even in the absence of network connections. This is made possible by directing the reads and writes to the local database. The system does not wait for the remote database to respond to the requests. The data is synced later by the Couchbase API on the availability of network. The replication of data between the local database and the remote one runs asynchronously in the background. The progress can be observed by monitoring the notifications.
Coming back to our customer challenge, developing a sync function from scratch is complicated and tricky. Couchbase sync gateway handled this efficiently and took the pain out of data replication or synchronization. Replication objects could be then used to successfully push and pull data from Sync gateway. The Sync function was setup to restrict agent’s access to documents. Every time a new document is added or an existing document is updated or deleted, the sync function is called to examine the document. This function then validates the document, authorizes the change, assigns the document to a channel, and grants user access to respective channels. The document is synced to the server on successful validation.
Authorization & Authentication:
Sync Gateway provides the following REST APIs to authorize users:

  • The Public REST API is used for client replication.
  • The Admin REST API is used to administer user accounts and roles. It can also be used to look at the contents of databases in superuser mode.

Sync Gateway does not allow anonymous or guest access by default. A new server is accessible through the Public REST API only after you enable guest access or create some user accounts.
Sync Gateway supports the following authentication methods:

  • Basic Authentication: provide a username and password to authenticate users.
  • Custom Authentication: use an App Server to handle the authentication and create user sessions on the Sync Gateway Admin REST API.
  • OpenID Connect Authentication: use OpenID Connect providers (Google+, Paypal, etc.) to authenticate users.
  • Static providers: Sync Gateway currently supports authentication endpoints for Facebook, Google+ and OpenID Connect providers.

Many data options are available for mobile that satisfy the above requirements but require tradeoffs when running in production. Couchbase Mobile provides a complete NoSQL solution with data storage, access, sync and security across the stack. An added advantage is the offline experience in the apps that ensure fast and available applications.
Aparna Umashankar – Database Solution Consultant, Ashnik



Go to Top