There is a lot of chatter circulating the Internet when it comes to mobile application development and data management. Should you use a service, or a software for your mobile apps. Pretty much every decent app today requires fast changing data that is easy to use and syncs between other mobile platforms and devices. I’m a mobile app developer with a number of apps released to the app store and my goal is to give you some perspective on the difference between Couchbase Mobile versus what else might exist in this realm.

What is Couchbase Mobile

In short, Couchbase Mobile is a collection of software consisting of an embedded NoSQL database distributed with your Android and iOS mobile applications and a middleware service used to securely synchronize that locally stored data with Couchbase Server and other devices. These two pieces of software are called Couchbase Lite and Couchbase Sync Gateway, and when used together are a force to be reckoned with.

Couchbase Lite is an embedded NoSQL database. It is very small in footprint and runs in process while your application is running (or while it is in the background). This in process database exposes a RESTful web service that can be accessed via the Couchbase Lite API or through your own HTTP requests if you really wanted to. Couchbase Sync Gateway, being middleware, acts as the data orchestrator between the device and the server. It channels the data, handles conflicts, and gives you the best possible experience as both a developer and end user.

Why Couchbase Mobile Should Be Used

Couchbase Mobile was designed to make your life, as a mobile developer, very easy and stress free. Using what is already baked into Android and iOS is great and it works, but it certainly isn’t easy. Let’s compare a few things now.

Couchbase Lite versus SQLite

Anyone who has worked with SQLite knows that certain things can be a pain to do. It isn’t particularly difficult to query an SQLite database, but when you find yourself needing to upgrade the schema because your application has new data requirements, it can turn into a nightmare. You’ll find yourself needing to write clean upgrade scripts so you don’t cause data loss or corruption on your customer’s devices. You might think that you’ve made a bulletproof database schema that will never need to be changed, but a seasoned developer knows that data is always changing.

Couchbase Lite is NoSQL and uses schema-less documents for storing your data. This means you can store constantly changing data and never have to think about a mobile database upgrade plan. Although Couchbase Lite doesn’t use an ORM, you’re still storing your data in a form that closer resembles how it is actually used. This saves the time typically spent querying for SQL data, parsing it into an object you want to use, and using it.

But what about data synchronization with other platforms and devices?

Couchbase Sync Gateway versus the Manual Approach

Anyone that has needed to sync their data with other devices and platforms knows it can be a tricky thing if you have to build the solution from scratch. Handling conflicts and efficient, secure, syncing without draining the users battery is a complicated subject that can easily be avoided with Couchbase Mobile.

This is where Couchbase Sync Gateway comes into play.

The Sync Gateway takes the pain out of data replication or synchronization between your devices or other applications. By using replicators in Couchbase Lite, data can be pushed and pulled from the Sync Gateway giving you a true offline-first experience. Worried about data authorization? Sync Gateway let’s you authenticate with services like Facebook and grant users or roles access to data so you can only access what you’re allowed to.

Imagine having an SQLite database on your device that you need to synchronize with a remote MySQL database. How would you handle checking for local data that needs to be pushed or remote data that needs to be pulled? What happens if there is a conflict in that data? What would you do? Whatever you chose, probably wouldn’t be easy. Definitely not less than a few lines of code like Couchbase Mobile offers. You get offline-first development with minimal effort when it comes to Couchbase Mobile.

The Offline-First Experience

Couchbase Mobile promotes an offline-first approach to mobile application development where you develop as if you have no intentions of using the Internet, then slip in network functionality after you’ve got a smooth offline user experience. The trick here is that this is made possible by having an offline-local database that your code directly interfaces with. You’re not issuing requests to your remote database and waiting for responses that can often be slow. Instead you’re reading and writing to your local database only. The Couchbase Lite API will worry about pulling and pushing data when able to. No Internet, no problem, because you aren’t reading from the Internet, you’re reading from your local device.

How Couchbase Mobile Differs From Data Services

Couchbase Mobile is not a service. Unlike services like Facebook’s Parse, Dropbox’s Datastore API, and Paypal’s StackMob, you own your data with Couchbase Mobile. Why is this important? Well, the three data services I just mentioned have all announced that they are shutting down. This means that anyone who invested time and resources into these services will have to jump ship and find something else. This could involve changing their entire application source code, manipulating their data to fit a new software or service, and cost a lot of money.

When you own your data, you’re in control.

You might say that it is an inconvenience to manage the servers in which software like Couchbase is installed. The reality is that there really is no inconvenience. Services like Amazon Web Services (AWS), Microsoft Azure, and so many others, have Couchbase images available and ready to go. Just deploy the images and you’re ready to go. Worried about data stability, load balancing, and uptime? This shouldn’t be considered an inconvenience either because Couchbase nodes can be clustered in minutes, and when clustered, offers data replication and load balancing. There is no need to spend endless hours playing the role of system operations when you’re really a developer.

Conclusion

With so many data options out there for mobile, it becomes difficult to choose. However, knowing about data as a service and that these services can be shut down at any time, the obvious choice should be in data that you own. Couchbase Mobile, with Couchbase Lite and Couchbase Sync Gateway, makes an obvious choice in this realm. You get an offline-first experience in your apps leaving you with always fast and available applications with data that you have control over.

Author

Posted by Nic Raboy, Developer Advocate, Couchbase

Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in Java, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Apache Cordova. Nic writes about his development experiences related to making web and mobile development easier to understand.

Leave a reply