Using Firebase for NoSQL DB
What is Firebase?
Firebase is a mobile and web application platfrom which provides tools and technology to build applications. The most popular services are Firebase Analytics, Firebase Cloud Messaging, Firebase Auth, Realtime Database, Firebase Storage and Firebase Hosting.
But, why Firebase is a good option for your Database?
Firebase has some features which make it better than others Databases depending on your needs.
Efficient: Firebase Storage is developed to be simple, easy to understand and efficient in the use of bandwidth.
Strong security: Firebase Storage has an strong way to authenticate using a declarative security model to allow access based on filename, size, content type, and other metadata.
Scalability: Firebase Storage is backed by Google Cloud Storage for petabyte scale when your app goes viral.
Fast: The Firebase Storage SDK is used for save time and bandwidth for its hability to retry the operation right where it left off.
Special handle for media: Firebase Storage stores your files in a Google Cloud Storage bucket shared with the default Google App Engine app, making them accessible through both Firebase and Google Cloud APIs.
Access Control: Firebase Storage has an important feature in its authentication, it identifies the roles of the users, therefore it lets you set access controls on individual files or groups of files, so you can make files as public or private as you want.
Firebase applied like NoSQL DB
The Firebase Realtime Database is a NoSQL Database which has a lot of optimizations and features compared with most of relational databases. It includes a flexible rules to define how the data should be structured to provide security and flexibility.
Firebase is a Database stored as JSON objects, which is easier to use than some SQL databases for the way to handle the data like a tree. When you start adding data to your database ut automatically creates a node in the existing JSON structure with an associated key.
"users" : {
"key_sample" : {
"about" : "I love reu.",
"displayName" : "Juan Guerrero",
"email" : "sample@gmail.com",
"photoURL" : "https://www.sample.jpg",
"providerId" : "facebook.com",
"publicAccount" : false,
"uid" : "1234567890"
}
}
When your are designing your Database model, you should have some practices that could make your Database safer and easier to use in your apps.
Avoid nesting data
When your are using NoSQL Databases you should be careful to handle a lot of information in a inappropriate way because if you have a nested design, the iterating through the data becomes very problematic.
Flatten data structures
The data should be separated or denormalized, because in this form it could be efficiently downloaded in separate calls just downloading few bytes and fetching metadata faster.