In Part 1 of this series, we compared the process of creating an App and integrating frameworks to your XCode project.
In this second part, we will approach the Databases used for both platforms.
Firebase and Parse take distinct approaches for storing and querying data, so depending on your project, one technology might be better fitted to your specific case than the other.
Firestore & Realtime Database
Firebase used a technology called Realtime Database, which was a cloud-hosted database. Data used to be stored as JSON and synchronized in realtime to every connected client, so all clients shared one Realtime instance and automatically received updates with the newest data.
Later on, Firebase changed its database to Firestore, the current technology, which is a scalable database that stores data in documents arranged in collections, so data is stored similarly to the way data is stored in JSON, allowing Firestore to require less denormalization and data flattering.
Both databases support realtime SDK, local storage, and are mobile-first driven.
Firestore speeds atomic write and transaction operations: transactions will keep retrying until they’re completed, while operations can be batched and completed automatically.
In Realtime Database, data can be written as an individual operation, while transactions require a completion callback.
Parse, on the other hand, supports distinct database products in its backend.
You can run Parse on a MongoDB instance, which is also a document-oriented NoSQL database, or you can run it on a PostgreSQL, which is an open-source relational database. Whatever floats your boat.
Creating the Database
On Firebase, you first have to hit the Create Database button
Then choose a mode. I used Test Mode as this is a testing application.
Finally, you can choose which location (a.k.a. datacenter) you want your instance to run.
It is important to understand that this location cannot be changed later in any circumstance.
You can then click Start collection to create your first collection
Give your collection a name
And finally, add a new Document to it
And you can see your saved result:
Parse on the other hand have the Database built-in for the App when you first create it:
To create a new Class (a.k.a. Table for the SQL users out there), you click the Create a class button above.
Parse provides a few templates in case you need them, but a Custom class will allow us to mold it as we need.
With the Cars class created
We can start adding Properties to it (a.k.a. columns for SQL). You do that by clicking the Add a new column button within that Class:
You can then input all properties and its data types
When done, Parse will present the created properties as columns along with the data types
And finally, we can start adding data by clicking the Add a row button:
And the results show up in a spreadsheet format
Region (location) change
As we saw, Firebase makes it clear when creating a database that the location cannot be changed later.
Parse on the other hand can change to a different region.
Here at Back4app the default location is in the United States East Coast, but per client request, we can host it practically anywhere. Even in China.
This is one of the aspects where both platforms differ.
Firebase uses a realtime engine that keeps the data synchronized among all clients at all times.
At this moment, Parse does not support that feature. While it has been discussed to implement that feature, it simply is not present at this point.
But Parse can achieve that functionality using something very clever called Live Queries.
Live Queries are essentially Websockets that notify clients every time an event happens in the database. You can subscribe to the classes you need realtime information, and every time a new record is created, deleted, or changed, you get a notification and can take action on that.
But have in mind that, while this is a very neat resource for realtime data delivery, it is not a realtime database engine, so you have to write specific code for that functionality.
Schemas & Relational Data
Parse delivers the full database schema to its clients, so you can know the database structure and constraints at any given moment.
This is very useful because, through this, you can keep Relational data even in a NoSQL database such as MongoDB.
By using Pointers (One to Many relations) or Relations (Many to Many relations) you can have linked records among Classes and perform queries on them, returning data from the child classes when querying its parent records.
Firebase does not support that and does not deliver the schemas for its data structures, so it is quite hard (not to say impossible) to have relations as easily.
Both databases engines are very efficient, scalable horizontally and vertically, so performance is usually not an issue.
That said, any database engine is as performative as the queries running on them, so having inefficient queries will impact performance on both.
Backup & Exporting Data
Parse offers backup engines and Parse hosting services such as Back4app allow you to download data from your classes for your own use.
Just go to the menu and choose Export data
Your data will be backed up and sent to you.
Firebase also offers exporting capabilities, but only in JSON format:
Parse also lets you import data in a number of ways.
You can upload JSON or CSV files and Parse will read those files and populate the database accordingly:
Firebase also supports importing data, but only in JSON format:
Both platforms offer resources for the developer to easily build databases, but with distinct features and approaches.
Firebase has the advantage of having realtime database sync with the clients, while Parse allows for data relation and support more databases, including SQL databases such as PostgreSQL.
In the last post we called a draw between Parse and Firebase, but this time I am going to give the slight advantage to Parse because:
- it supports data relations
- it supports more formats for importing and exporting data
- it supports both SQL and NoSQL databases
- it supports region (location) change after creation
- it is able to deliver real-time data even it’s not a realtime database
So Parse is a nose ahead in this comparison.
Let’s see how it keeps up in the next part.
Originally published at https://blog.back4app.com on July 29, 2020.