Promatics Blog

Cloud Firestore vs Realtime: How to choose the best database for your Mobile App?

Cloud Firestore vs Realtime Database How to pick one over other-Promatics Technologies

Like two peas in a pod; Cloud Firestore vs Realtime Database from Firebase present a difficult case of choice for budding developers. Both are cloud-based client-accessible database solutions for mobile apps that support real-time data syncing.

 

For some time now; developers have used Realtime Database as a tool that sets up and provides a back-end database as a service easily. There is a development-friendly bias towards Realtime database because of its low barrier of entry, low maintenance costs, and fast queries. However, the Real Time database doesn’t come without drawbacks. This has lead to developers looking for alternatives. In a quest to please the developers with a state-of-the-art backend solution, Firebase launched Cloud Firestore that features a radically different architecture that focuses on different priorities like complex querying and data integrity. Cloud Firestore is launched as a richer, faster, and more scalable solution for mobile app development.

 

We at Promatics have experimented with both the systems, in the past. We have seen how each one of them performs in real-world environments. We would like to share the lessons we have learned with fellow and upcoming developers about both these services.  In the article below we have covered details like differences, pros and cons for each service.

 

Introduction to Cloud Firestore and Realtime Database

Talking of Realtime Database, it is a cloud-hosted NoSQL database with SDK support for iOS, Android and the web. The data is stored here in JSON document, so everything is either a key or a value. The database uses web sockets for its data sync needs. This ensures lightning fast transactions. The database also aids in dealing with updates when the device is offline, synching all the changes as soon as the network is reconnected. The database offers enhanced ease of use and is fairly easy to install. Queries fire and respond in near real time using Realtime Database, and it prolific. However, it is true only when the data structure is laid out in a way to support all the queries you want to make, and will ever want to make, in the app. The list of perks also includes a lot of the built-in Realtime SDK features. The database easily integrates with other tools for authentication, file storage, analytics etc that Firebase offers. Realtime Database supports queries on one field only.

 

Developers opting for this particular database need to write most of the system’s application codes on their own. This means they need to handle most of the logic part in their client’s application. They need to duplicate codes across Android, iOS and web manually. To cater to client logic, a developer also has to write data validation on his own.

 

On the other hand, Cloud Firestore is the newest offering on the market. It features traditional relational schema hierarchy. A document on Cloud Fitestore is a single JSON object structure that can hold subcollections of more documents or key-value pairs of data. This NoSQL database is organized into collections. The collections comprise of documents that in turn feature subcollections and data fields.

 

Numerous fields inside a document like strings, numbers, booleans, objects, arrays, null values, date timestamps, geo-points, and shallow references to other documents offer vivid benefits to developers. It helps them manage data integrity as well as considering bugs that result from mismatching types. The references can also help with data denormalization, considerably reducing the number of locations a developer needs to manage duplicated data. While the Cloud Firestore doesn’t allow queries across subcollections or inside references, developers can always use these references to directly fetch the local document’s related data.

 

Common Features in Realtime Database and Cloud Firestore

a.) Both offer ease of use to developers.

b.) They both integrate well with Firebase’s suite of other services, including each other.

c.) A developer can set up both a Realtime Database and Cloud Firestore for his/her client’s advantage with a single Firebase project.

d.) File storage, Cloud Functions, authentication, crash reporting, analytics, and Firebase Cloud Messaging are other amenities that come complimentary with both databases.

e.) The data is exposed to admin users via the Firebase Console in both cases.

 

Common features of Cloud Firestore and Realtime Database

 

f.) When it comes to exploration, both platforms feature a console that follows the same paradigm in both databases. It allows one to browse top-level nodes/collections and drill down into your data until the search is complete.

g.) Realtime Database and Cloud Firestore allow conveniences like adding/editing/deleting data, which is useful for beginners.

h.) Both platforms offer enhanced speed and efficiency to developers. It is easy to set up listeners that trigger either cloud code or local client code as and when data is modified, resulting in lightning-fast updates for users. The USP of these updates is that they can be made offline and synchronized as well.

i.) Both the platforms allow you to combine several important operations together into batches or transactions. This ensures that multi-step processes don’t leave the data in bad shape even in case of failures.

j.) The security is implemented through Firebase Rules in both the platforms. It is done through a configuration document that enlists what locations have restricted read/write permissions.

 

Key Differences Between Realtime Database and Cloud Firestore

 

I. Querying Support

A distinct advantage of choosing Cloud Firestore over Realtime Database is robust querying support. While Realtime Database queries only allow for a single sorting parameter or condition, the new Cloud Firestore facilitates records matching multiple field comparisons. Cloud Firestore caters well to compound queries that require an index. When you execute a query the requires an index, it might fail. However, it would give you a URL to present to Firebase console to get it indexed. Although copying and pasting URLs is not exactly what excites a developer, it is better than the process of creating indexes manually. Evidently, Cloud Firestore is more structured one of the two. It is a document-model database. All of your data is stored here in objects called documents that consist of key-value pairs.     The values can contain any number of things, from strings to floats to binary data to maps, which are then grouped into collections. With Cloud Firestore you can store your data hierarchically in a way that makes sense logically without worrying about downloading tons of unnecessary data. While creating a query across multiple fields was a lot of work in Real Time Database that required denormalizing the data, it is fairly convenient with Cloud Firestore’s automatic search across multiple fields.

 

II. Importing/Exporting Data

Real-time nature of the Realtime Database is a plus for building features like chat or enabling magical collaborative experiences. Realtime Database also provides an easy way to import/export data (via simple JSON files) in the Firebase Console. It is of vivid importance to non-developers in need of adding/editing data in the database quickly; without any need for scripts or an API. Realtime Database allows one to upload totally new datasets for your app to consume. With the new Cloud Firestore, even a one-time fetch query is organic as it is built as a primary use case within the Firestore API. Developers can ensure that the clients receive updates whenever there is a change in data of the database by adding support for listeners.

 

Key difference between Cloud Firestore and Realtime Database

 

III. Scaling

Scaling massively can be a tough territory with Realtime Database. Cloud Firestore, instead, is built on top of Google Cloud infrastructure that has a proven track record. It is much more easily scalable than Realtime Database. The upper limit to Realtime Database is 100,000 concurrent connections, whereas Cloud Firestore accepts up to 1,000,000 concurrent client connections per database. Additionally, Cloud Firestore promises a more robust Service Level Agreement than the Realtime Database. There is also a prolific uptime guarantee in multi-region instances (more on that below) and 99.99% uptime in regional instances with the Firestore, which is significantly better than what Database offers. Along with an all-new querying structure, the Cloud Firestore queries get scaled to the size of the result set and not to the size of data.

 

IV. Multi-Region Support

Cloud Firestore comes with the privilege of multi-region support. This ensures that the data is copied to multiple geographically separate regions at once, automatically. This means that data can be served even in case of any unforeseen disaster plagues your data centre. Moreover, Cloud Firestore offers better consistency with Multi-Region Support. This ensures that an app user is subjected to the latest version of data available every time he/she logs onto the app.

 

With Cloud Firestore, you can host your data in two different multi-region locations. Even if you are a business that doesn’t need the heavy-duty capabilities of a multi-region database, Cloud Firestore offers regional instances in locations around the world, which offer a low-cost solution to app businesses. The Realtime Database, on the other hand, is only hosted in North America.

 

Which Database is Best Suited for Your App Business?

In a nutshell, you must settle for Realtime Database if your data is not complex or hierarchical by nature. When you need to scale under 100,000 concurrent connections 1000 writes/second in a single database, it can be your best bet. In this case, the costs increase with the total amount of data you send via database read/write operations, regardless of how many API calls that may take. Realtime Database charges for overall bandwidth and storage and not individual operations performed. It is best suited for apps that feature lots of small transactions like location updates or live chat messages.

 

However, for data more complex and hierarchical; Cloud Firestore would be a better choice. It allows the data to scale over 100,000 concurrent connections. Cloud Firestore costs increase for every API call made, regardless of how much data is sent/received. It is best suited for apps that have a set precise limit for spending and a database which charges primarily on individual operations. It is best suited for apps with traditional RESTful requests that makes fewer calls with larger responses.

 

We at Promatics, analyze the nature of the business first when we develop apps. This helps us in making the decision about the database we must pick for the app.

Sahil Verma

Sahil Verma

A highly detail oriented and committed professional with years of experience in technical project management. His quick understanding and instant problem solving ability not only makes clients' life easier, but also helps deliver the assignments with assured quality. He is well versed with agile and waterfall methodologies. He has comprehensive knowledge of various technologies and is quickly adaptable as per the requirement. Good communicator, leverage technical, business and financial acumen to Communicate effectively with client executives and their respective teams. Sahil enjoys spending time with his family and friends and fond of reading technical article, blogs and literature.

Leave a Comment

You've decided to leave a comment. That's fantastic! Please keep in mind that comments are moderated. So, please do not abuse, use a spammy keyword or it will be deleted. Let's have a meaningful conversation instead. Thanks for dropping by!

Enter same string as shown below:
Image

Search

About Promatics

Promatics is an ISO 9001:2008 certified offshore web and mobile application development company with a strong team of 100+ highly skilled IT experts delighting SMEs across USA, Europe and APAC. Our services and solutions help clients to achieve tangible business value and remain competitive in today’s evolving marketplaces.

Stay Connected

Facebook Twitter Google Linkedin

REQUEST A QUOTE