Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase vs MySQL database (hierarchical/relational)

I am fairly new to Firebase, I have some knowledge of databases because I have worked with MySQL before but reading the benefits of Firebase and what it has on offer - real-time database, login (auth), analytics etc.

I am looking to implement Firebase into the project I am working on. Whilst MySQL is a relational database, through my search I found (I believe) Firebase is a hierarchical database because of the how it structured database like a JSON-tree.

Following the correct way of development, I would like to draw ERDS and database tables to get an idea of how my project will communicate with the backend. However, I am not quite sure how I can represent the data structure using these mediums because in SQL you would have primary keys and foreign keys linking tables. Is this the case for Firebase as well?

For example, in MySQL the table would look like: [d]
The ERD would like like:

My questions are:

  • Am I correct in saying Firebase is a hierarchical data structure?
  • How can data be represented in ERD and Database tables to show the data structure of firebase?
  • Does Firebase uses primary and foreign keys like in MySQL
    If so, are these represented in the same way like in when designing ERDs and tables for MySQL database?
  • How / what is the best way to structure data in Firebase and show these in ERD and tables?

I am new to Firebase, so any help would be nice. Thanks.

like image 329
SumOne Avatar asked Jan 09 '17 11:01

SumOne


People also ask

Is Firebase database better than MySQL?

Compared to Firebase, MySQL is better for multi-row transactions. On the other hand, Firebase is a satisfactory choice when it comes to managing huge data sets because NoSQL horizontally scales data and it is much faster than MySQL.

Can Firebase replace SQL?

It is not possible to use Firebase in this way. Firebase is a real-time object store. It is not a SQL database and is not intended to be a replacement for one. It completely lacks mechanisms such as JOINs, WHERE query filters, foreign keys, and other tools relational databases all provide.


1 Answers

This is an incredibly broad topic, as can be seen by the fact that you have four questions in a single post. I recommend watching our Firebase for SQL developers series and reading NoSQL data modeling.

A few quick answers:

  • Firebase is indeed a hierarchical data structure: it's really just a JSON tree in the cloud.
  • there is no defined way to display hierarchical data in an ERD. It's more common to show a JSON tree.
  • Firebase has the concept of keys, which are the names of the nodes that you store data under. You could somewhat compare those to the primary keys of a relational database. But there is no concept of a managed foreign key.
  • as your second question: it is a common practice to model your Firebase database as JSON, which is quite convenient as that's also the format that the database stores.
like image 148
Frank van Puffelen Avatar answered Oct 08 '22 01:10

Frank van Puffelen