Firebase is not a relational database. It offers two types of databases – Realtime Database and Cloud Firestore – both of which are NoSQL databases. They employ a different data modeling approach compared to traditional relational databases.
The Realtime Database is Firebase's original database offering. It is a NoSQL database that stores data as JSON objects, allowing for real-time synchronization across connected devices. Key features of the Realtime Database include:
Cloud Firestore is the newer, more advanced database offering from Firebase. It is also a NoSQL database, but it uses a document-based approach to store data. Key features of Cloud Firestore include:
To understand why Firebase is not a relational database, it's important to know what defines a relational database. Relational databases have the following characteristics:
Data is stored in tables: Data is organized into rows and columns, with each row representing a unique record and each column representing an attribute.
Schema-based: The structure of the data is defined by a schema, which specifies the tables, fields, and relationships between them.
Relationships between tables: Tables can be related to each other through primary and foreign keys, allowing for complex data relationships and queries.
SQL support: Relational databases use Structured Query Language (SQL) for querying and manipulating data.
Firebase databases model data either as JSON objects in the Realtime Database or as documents in Cloud Firestore, allowing for flexible data structures. In contrast, relational databases organize data into tables with rows and columns, providing a more rigid structure.
Firebase (Realtime Database) example:
This JSON object represents a user with a name and age in a Firebase Realtime Database.
Relational Database example:
This SQL statement creates a table named "users" with columns for user_id, name, and age in a relational database.
Firebase databases are flexible and schema-less, allowing for dynamic data structures that can adapt to changes in the application requirements. On the other hand, relational databases are schema-based, which means that the structure of the data, including tables, fields, and relationships, must be defined upfront.
Firebase (Realtime Database) example:
This JSON object adds an email field to the user object in a Firebase Realtime Database without modifying a predefined schema.
Relational Database example:
This SQL statement alters the "users" table in a relational database by adding an email column, requiring a schema change.
Firebase databases have limited support for data relationships, and developers often manage these relationships through denormalization or client-side logic. In contrast, relational databases offer rich support for data relationships through primary and foreign keys, allowing for complex data queries and connections between tables.
Firebase (Cloud Firestore) example:
In this example, a post in Cloud Firestore references its author through the author_id field, which corresponds to the user's document ID in the users collection.
Relational Database example:
This SQL statement creates a "posts" table in a relational database with a foreign key, author_id, that references the user_id in the "users" table, establishing a relationship between the two tables.
If you decide to use firebase for your project, Lido is here to help. In just a few clicks you can import any firebase database into a lido spreadsheet and quickly build admin panels or search data with ease. Click here to try lido for FREE!