How do developers use the same database for cross-platform mobile and web apps?

We generally develop an API. An API is a backend part that is usually developed in server side language say NodeJS. The API connects with the database and send response as JSON object. The client can now make http request to an API from any mobile device as they all support to make http requests. The API processes the request and returns the response to the client in JSON format. Client interprets the JSON and render the information to client. Web APIs are generally the RESTful APIs and they do not require the backend and front end to be written in same language. So API written in java could b

We generally develop an API. An API is a backend part that is usually developed in server side language say NodeJS. The API connects with the database and send response as JSON object. The client can now make http request to an API from any mobile device as they all support to make http requests. The API processes the request and returns the response to the client in JSON format. Client interprets the JSON and render the information to client. Web APIs are generally the RESTful APIs and they do not require the backend and front end to be written in same language. So API written in java could be accessible to a app written in swift or objective c or android

Generallywe add an API that the mobile app can use, or we make the site responsive so that it renders well on the mobile device.

If the API route is chosen, then we build the app such that it can make calls to the API when data is required. The app may need to keep some data local ms so a local storage mechanism is added to keep that data until it's not needed anymore.

There are two databases in the mobile world. There is SQLite and there is a backend database behind a series of web services. Don’t depend too much on SQLite, especially at the early stages. Just go communicate with the web services. If at some times you need to use SQLite, do so later on.

Quick Summary :- With so many offerings available, it's a challenge for mobile app developers to select the right database for the right application. This blog consists of general criteria and some use cases based criteria to help developers to build scalable and fast mobile apps.

How to Choose the Right Mobile App Database for Your Application

Whether you are building a brand new mobile application or want to add more features to the existing app, choosing the right database can be overwhelming given all the choices available today. There’s a huge possibility that your current database is not s

Quick Summary :- With so many offerings available, it's a challenge for mobile app developers to select the right database for the right application. This blog consists of general criteria and some use cases based criteria to help developers to build scalable and fast mobile apps.

How to Choose the Right Mobile App Database for Your Application

Whether you are building a brand new mobile application or want to add more features to the existing app, choosing the right database can be overwhelming given all the choices available today. There’s a huge possibility that your current database is not sufficient to handle millions of users and frequent updates.

Crisp a messaging platform built their original platform with Firebase as the database. But, they quickly ran into the following challenges:

  • Difficulties in handling complex queries
  • Storing data offline
  • Managing object relations at web scale

For Crisp, it was extremely important that their users are able to effectively communicate with their customers. But customers were often missing important communications sent via the app. Thus Firebase proved to be a bad fit here!

They, later on, moved to a SQL database for data storage and MongoDB to store the messages for better performance and scalability.

Crisp isn’t the only story where a database dramatically compromised the quality and performance of an application.

The face of disruption, Uber had to migrate their database from PostgreSQL to MySQL. Uber made this choice as they faced inefficient database replication features and constant migration from one PostgreSQL version to another.

For better understanding, I’ve divided the blog into the following parts:

  • List of Mobile App Databases
  • General Criteria to Select Right Databases for Mobile Apps
  • Selection Criteria Based on Use Cases
  • Best Practices for Working with Mobile App Databases

Popular Mobile App Databases

Here are some popular databases to build Android apps and iPhone apps. You can select the best database for your mobile app based on your requirements.

MySQL: An open source, multi-threaded, and easy to use SQL database.

PostgreSQL: A powerful, open source object-based, relational-database that is highly customizable.

Redis: An open source, low maintenance, key/value store that is used for data caching in mobile applications.

MongoDB: A schemaless, JSON document database which is known for its flexibility and scalability.

Memcached: A distributed cache system which is multi-threaded, and used primarily for caching objects to speed up applications by alleviating database load.

MariaDB: A popular open source relational database which was created by the original developers of MySQL.

Cassandra: A free and open source, NoSQL database which is designed to handle a large amount of unstructured data at any scale.

SQLite: Embedded database, common usage is to provide local data storage capabilities on mobile phones.

InfluxDB: An open source, fast and time series database which is written in Go.

RethinkDB: An open source, and document-oriented database which stores data in JSON format and sync in real time with the application.

Riak DB: A distributed NoSQL database, which offers high availability, fault tolerance and data resiliency as its core feature.

CouchDB: A document-oriented NoSQL database which uses JSON to store data and javascript as its main query language.

Couchbase: A full Stack NoSQL database that supports offline sync, full CRUD, and query capabilities and runs locally on the device.

ArangoDB: An open source NoSQL database which is known for its multi-model, graph and geo algorithm features.

Selecting the right database for Mobile applications(with multiple layers of data) is a big challenge. I was shocked to see the challenges that developers face when they integrate the mobile app with databases.

General Criteria to Select Right Databases for Mobile Apps

What is the structure of your data?

Structure focuses on how you need to store and retrieve your data. Mobile applications deal with data in a variety of formats. Offline apps store all the data on the mobile device whereas Online apps depend on access to a server for their stored data to function. For example, E-commerce apps fall into the online apps category.

There are other types of apps called Synchronized apps. These apps store all their data on the mobile device and thus can be used offline, but the stored data may be updated on the server when the device is periodically online.

What’s the Size of your data?

The size of data refers to the quantity of the data you need to store and retrieve as critical application data. The amount of data may vary depending on a combination of the data structure selected, the ability of the database to differentiate data across multiple file systems and servers. So you need to choose our database keeping in mind the overall volume of data generated by the application at any specific time and the size of data to be retrieved from the database.

Speed and Scale

Speed and Scale address the time it takes to service incoming reads and writes to your application. Some databases are designed to optimize read-heavy apps, while others are designed to support write-heavy solutions. Selecting a database that can handle your app’s I/O needs goes a long way to a scalable architecture.

For example, MongoDB is faster than MySQL when it comes to handling a large volume of unstructured data. On the other hand, MySQL would be faster for structured data.

Data Modeling

Before you choose any database, it’s advisable to perform Data Modelling. It is a representation of the data structures to be stored in the database and very powerful expression of the business requirements.

Data Modelling is very helpful if your app contains features like search queries, reporting, location-based features, etc. Such apps require multiple databases to manage different types of data. For example, Uber uses MySQL, MongoDB and lot of other databases. They use MongoDB for their CDN and MySQL for business logic. Using MongoDB in their case made it very simple to store high volume incoming data.

Data Security

When you’re using synchronized and decentralized storage it is important to access, transmit, and store data securely. To cover this completely, you need to address authentication, data at rest, data in motion and read/write access.

Authentication should be flexible and allow for the use of standard, public, and custom authentication providers. Support for the anonymous access is also important for many apps. For data at rest on the server and client, you’ll want support for both file system encryption and data-level encryption. For data in motion, communication should be over a secure channel like SSL or TLS. For data read/write access, the database should offer granular control over what data can be accessed and modified by users.

Recommended Read: Mobile Application Security: Checklist for Data Security and Vulnerabilities

Support for the multiple mobile app platforms

Are you planning on supporting iOS, Android, or both? What about IoT devices and wearables? If you plan to support more platforms later, you have to take that into consideration now. A lot of mobile applications today evolve to add a web companion app or a native desktop app, so that’s something you have to think about.

If you are building mobile apps for both iOS and Android platforms then you can use React Native framework. It is easy to simultaneously develop for both Android and iOS as developers can share code on both the platforms. In addition, it supports all types of databases.

Selection Criteria Based on Use Cases

Data Synchronization between local database and backend server

Many mobile applications have features which work offline and requires an internet connection to save local data to the app’s server. For example, In Dropbox, you can edit and create new files, even when you are offline. When you are connected to the internet any changes you made will sync to the cloud.

Data synchronization is a critical part while developing a mobile application. You have to carefully analyze the use cases for your application and know what applies best for each. Are your mobile users going to read data only? Do they modify existing data?

Choose the local database which provides sync service to automatically store the local database to the cloud server and vice-versa.

Couchbase and realm the popular databases which provide Data synchronization between local database and backend server.

Mobile Applications With Multiple Layers of Data

Many applications contain a multi-layer data model in which one set of “fields and tables” is dependent on another set of “fields and tables”. In such apps, it becomes difficult to manage the data.

Generally, most apps change-over-time and require modifications and changes in the database structure. With a structured database(e.g., MySQL, PostgreSQL), you won’t be able to make the changes frequently.

Using an unstructured database like MongoDB would bring in flexibility to change without going through the painful process that you would find yourself in with structured databases. MongoDB allows you to work with unstructured data in multiple layers, adding new app features with flexibility – without the need to change the overall structure of your database.

Users who have a low network issue

When any SQL databases lose network connection with the client side storage, it typically generates an error message instead of transferring the data as needed. If this problem occurs frequently, you may need to re-configure your database. Apart from that, there are other challenges to deal with MySQL and network interruptions such as:

  • Persisting local data including unsynchronized transactions and app state
  • Getting mobile transactions and operations back to the main server-side database

Above listed issues occur on behalf of network interrupts, keeping a database that offers better reliability and resists connection loss is a better option in this case.

For highly scalable mobile applications

When you think of scaling your application, you think of adding more resources in the form of servers and making the database engine more efficient. The database should be able to utilize the resources and handle the parallel processing, that means the Database must be multi-threaded.

Multithreading allows a database to schedule parallel tasks on the available resources and minimize the workload on the server-side. Apart from multithreading, Distributed Design of a database is significantly important for scalability.

In a distributed designed database, you can split up the services on different threads to minimize the workload on the main database. This drastically improves the parallel processing of databases.

Pushing new app updates and database changes

Pushing new updates to the mobile app requires some changes to the local database. So the developers need to keep up with old database versions. Let’s understand how challenging and important it is for developers.

For example, some of your app users are using V1.0 version and you recently pushed V3.0. Now V1.0 users update to V3.0. Note that these users have skipped V2.0 altogether.

The local database you choose should be able to handle such scenarios. The database should be able to add new fields and tables as well as can manage old APIs and database structure for the users who use the latest app version.

You can choose SQLite with any server-side database, and it would work fine. SQLite has built-in OpenHelper tool to check database versions and to call functions such as onUpgrade or onCreate.

Resolve data conflicts between devices

For a mobile application which modifies the same data on multiple devices simultaneously can create conflicts. The database needs to support a mechanism for resolving those conflicts. The flexibility of the conflict resolution mechanism is important and should allow resolution automatically, on the device, in the cloud, by an external system, and by a human.

For more specific use-cases, refer to this table to determine which database would be more suitable for your specific requirement.

Best Practices for Working with Mobile App Databases

Predictive Caching

Predictive caching can be applied to improve the performance of your mobile app by looking at how, when, and where your users are using your application. A segment of users can be identified and can be served with specific information they always lookup based on their behavioral traits.

The best part is that the data can be made available and cached locally before the users even log-in to your app. MongoDB provides predictive caching that allows developers to serve users with predicted-cached data before they even ask for it.

Consider Databases which use Multiversion Concurrency Control (MVCC) Method

Support for Multi-Version Concurrency Control (MVCC) allows simultaneous access without blocking the threads or processes involved.

MVCC allows a reader to view a snapshot of the data before the writer’s changes, allowing the read and write operations to continue in parallel.

For instance, look at this table to see which databases have MVCC implementation:

Low Latency Challenges

Low Latency is crucial for real-time applications and online gaming applications. High latency leaves the app users with a bad impression. Anything that goes below 500ms is considered to be a high latency.

Optimizing latency is a continuous cycle, and each database has its own limits to what extent it can be replicated or optimized.

There are multiple methods to reduce latency, and replication of the database is most popular.

Most companies replicate their production database to separate read/write, request queries and static content operations.

Here are some databases with lower latency than the average:

  • MongoDB
  • PostgreSQL for transactional operations in real time
  • RethinkDB built for real-time application
  • PipelineDB, SQL database for streaming applications

Caching databases to reduce the load

We often add a caching layer to reduce the load on servers. We often cache data on this caching layer to prevent a recurring request for the same data. This reduces the number of requests going to the server and renders our server efficient for performance.

Mobile applications like Amazon get lots of recurring requests. You can reduce the load from the server by adding the caching layer. It can handle millions of requests with the lowest latency. You can use Redis and Memcached for such requirements.

Mobile Application Development Services

Get in touch

Hire dedicated, pre-vetted mobile app developers experienced in a large variety of technologies.

Conclusion

Because mobile apps are subject change either it’s feature improvement or new feature update, it will affect the database. These criteria will help you to determine the right databases for your mobile app. What’s important here is to find a database that’s highly flexible.

Having experience with developing a variety of enterprise mobile applications for our clients, we consider future requirements and scalability to choose the right mobile app database. Let us know if you are facing scalability issues or want to build data-heavy applications from scratch.

A database can be run on any computer. I have several running on this laptop. Fundamentally there is no technical distinction between a server and any other computer other than what you choose to do with it. There are, however, several reasons why you might choose to have a database on a remote server (IE not your local computer). These include

  1. You want the database to be accessible by multiple users or systems. you don’t really want thousands of people connecting to your laptop.
  2. You want applications on the web to have programmatic access to the database. For all kinds of reasons it easier to h

A database can be run on any computer. I have several running on this laptop. Fundamentally there is no technical distinction between a server and any other computer other than what you choose to do with it. There are, however, several reasons why you might choose to have a database on a remote server (IE not your local computer). These include

  1. You want the database to be accessible by multiple users or systems. you don’t really want thousands of people connecting to your laptop.
  2. You want applications on the web to have programmatic access to the database. For all kinds of reasons it easier to have a machine set up for serving database requests to APIs rather than have your local machine doing it.
  3. Whatever application you have as the front end of the database demands enough “oomph” in the machine that a server is a more practical solution. Some databases have tens of millions of rows in their tables and queries that can take minutes or even hours. The more power you can throw at that problem, the more time you have to improve the underlying issues.
  4. The database has scaled to the point where having it on a local machine is unrealistic. Do you really want a 20 terabyte database on your laptop?
  5. You want to take advantage of backup or replication solutions which require the database to be accessible. Production systems are often backed up in real time to multiple other systems, and have nightly snaptops taken etc. These systems need to run constantly and reliably, and a server is likely to be both more stable (because you shouldnt constantly mess with it) and more available (because you don’t turn it off).
  6. The database needs to be available for whatever reason 24/7. Production systems often demand high availability. Our system is up 99.99% or greater every month. to achieve this takes a lot of infrastructure behind it, which means multiple identical servers, failover systems, automated backup and recovery, auto scaling etc. Not something you can do in your living room.
  7. You are synchronising data between multiple databases. Organisations these days expect to be able to pass data around seamlessly between systems. That means they need to be accessible all the time.
  8. You want to access the database personally from whatever machine you are using. I can access our production system from anywhere I have whitelisted the IP, and satisfied a number of other security controls. the actual machine is irrelevant.
  9. Security. No-one is breaking into AWS any time soon, and they have some of the world’s best security around their infrastructure. They also have the ability for you to build extremely secure database solutions. On the flip side people leave their laptop on the train all the time…

My team of developers and I have a local copy of our production database ( redacted, obviously) on our laptops. This allows us to use our laptops as mock ups of the production environment and thus develop new features and fix bugs etc. The production system needs to be accessed by a quarter of a million users, so is on a server that is massively powerful. Actually it’s on 5 servers, but that’s another story :)

You’ll need to write an API which both the web app and mobile app talk to. Depending on how your backend is already set up, if you’re using a language like PHP or Ruby on Rails, there are a lot of gems and tools you can use to get your API set up.

One thing I recommend: when building an API, you’ll want to make sure you provide a way to authenticate against it (which will protect your user’s data as well as fight againt spam). This is commonly done by setting up some kind of token-based auth system whereby you send a token up with every request and verify that the token is valid.

You can definitely use the same database to run a mobile application and a website. The current state of the art, is creating a set of web services (REST API) to hide the implementation (provide Abstraction) of the database from both the Website and the Mobile Apps.

After you define and build your API you can test it and see that it works. You can then make your website and mobile apps connect to the API to get and save data.

There are a few services that make this a little bit easier if you don’t want to do it all yourself. Take a look at Parse Server (open source) and Firebase (Not open source

You can definitely use the same database to run a mobile application and a website. The current state of the art, is creating a set of web services (REST API) to hide the implementation (provide Abstraction) of the database from both the Website and the Mobile Apps.

After you define and build your API you can test it and see that it works. You can then make your website and mobile apps connect to the API to get and save data.

There are a few services that make this a little bit easier if you don’t want to do it all yourself. Take a look at Parse Server (open source) and Firebase (Not open source but run by Google).

Best of luck!

I guess the “fast and easy” answer is: Whichever one you’re most comfortable with and adept at using is a good choice. It is difficult to recommend one database over another without knowing more about the requirements, etc.

Off the cuff, I’d say MySQL is a good choice if you want to host the database externally. MySQL is perhaps the most “universal” contender. It works well, is easy to use and popular enough to make finding help with problems pretty easy.

On the other hand, if you’re looking to embed the database on a phone or something, you might want to look at SQLite for many of the same reas

I guess the “fast and easy” answer is: Whichever one you’re most comfortable with and adept at using is a good choice. It is difficult to recommend one database over another without knowing more about the requirements, etc.

Off the cuff, I’d say MySQL is a good choice if you want to host the database externally. MySQL is perhaps the most “universal” contender. It works well, is easy to use and popular enough to make finding help with problems pretty easy.

On the other hand, if you’re looking to embed the database on a phone or something, you might want to look at SQLite for many of the same reasons.

Well that depends on your use case.

for on the device storage Sqlite is used, and on top of that you might want to use ORMs like GreenDao or Room persistence library from Google.

In case you want to share the data across users/devices Firebase might come handy, other alternatives are Mongodb. They are not traditional RDBMS but they provide good features like listeners on a data node that I feel is very useful, again it depends on the type of application you want to build.

And of course you can always have a server side RDBMS setup like MySQL, Postgress etc. Alongside server side application to in

Well that depends on your use case.

for on the device storage Sqlite is used, and on top of that you might want to use ORMs like GreenDao or Room persistence library from Google.

In case you want to share the data across users/devices Firebase might come handy, other alternatives are Mongodb. They are not traditional RDBMS but they provide good features like listeners on a data node that I feel is very useful, again it depends on the type of application you want to build.

And of course you can always have a server side RDBMS setup like MySQL, Postgress etc. Alongside server side application to interact with it, this server side application can expose a API for your Android application.

A really easy way to do it is to use a BaaS platform such as Parse or App42. With these services you don't even need to create and host your own databases, all you have to do is use their APIs to send an receive data from their platform. It'll save you time of you're building a quick app or an MVP, or even if you want to scale to millions of requests a day.

Can you be more specific about your requirement?

Do you want a link between your App and the website? or else the site itself should turn into a an app?

If it is the first case,

You need a link (URL redirection) to open the site inside the app. Nothing but it is your custom browser. Chrome provides the API for that.

In other case,

You have to turn your existing website to a Progressive Web App . That needs another complete development.

Well, for backend programming, if you're more on the coding perspective, you can try the native PHP/mySQL combination for website and the usual, Java for Android, JSON for passing of data from your database to your mobile Android app. :)

Hope that helps.

PS. That's what I did when I tried to create an Android app that remotely accesses contacts, call logs and messages from one phone to another. We named it iKonek. I dunno if it still in Google Play.