Logo

dev-resources.site

for different kinds of informations.

Dev Video Review: Firestore Data Structure, Limitations, and IMHO

Published at
12/31/2024
Categories
firebase
database
firestore
datastructures
Author
imkven
Author
6 person written this
imkven
open
Dev Video Review: Firestore Data Structure, Limitations, and IMHO

It’s been a long time since I last used Firestore (Before Firebase acquired by Google), as my work has mostly focused on server-side development. Traditional databases often make more sense in terms of cost and flexibility. However, while working on a recent React Native project, I had the chance to revisit Firestore and refresh my knowledge. Inspired by an official Firestore video, I decided to share some of the rules outlined in the video along with my opinions on Firestore's data structure.

Rule #1: Document have limit

Understanding database limitations is crucial when modeling your data structure. Firestore, like all database systems, has certain limits to prevent exhausting the compute and memory resources. Below are some key limitations you should consider:

  • Max 1MB limit per document
    Technically, Firestore allows any data types, but just because you can store an image inside a document doesn’t mean you should. 1MB document should be enough for 99.99% of your use cases.

  • Max 20k fields limit in document
    When you modeling the data structure, you have to prevent keep adding new fields in the document.

  • Max depth of sub-collections is 100
    Avoid excessively nesting sub-collections in your data structure.

For more details, please check this link: https://firebase.google.com/docs/firestore/quotas#collections_documents_and_fields

Rule #2: You can't retrieve a partial document

Firestore doesn’t allow partial document retrieval. If you need to check a specific field, Firestore will return the entire document, and you’ll need to extract the field yourself.

Fortunately, Firestore charges based on document reads, not size or bandwidth (Talk more in Rule #4 later). However, took this consideration when modeling your data structure, especially when query come from mobile apps, as it may increase battery and data usage.

Rule #3: Queries are shallow

When you query a document, Firestore retrieves the document but not its sub-collections. Keep this in mind while modeling your data structure to avoid unexpected behavior.

Firestore - Queries are shallow

Rule #4: You're billed by the number of reads and write your platform

Firestore is charges based on the number of reads and writes rather than the storage size. Optimize your data structure to minimize reads and writes, but don’t over-complicate your code for just saving a few dollars per month, totally not worth for the engineering cost.

Rule #5: Queries find documents in a single collection

Firestore queries can only retrieve documents from a single collection. This limitation means no joins (or groups) are possible, so you’ll need to plan your data modeling accordingly.

Rule #6: Arrays are weird... maybe not now

Firestore is supports arrays, and while there were limitations in the past. However, improvements have make them more reliable for now. You can now use special array operators for manipulation the array. Learn more here: https://firebase.blog/posts/2018/08/better-arrays-in-cloud-firestore

datastructures Article's
30 articles in total
Favicon
Data structures
Favicon
Introduction to Trie (Prefix Tree)
Favicon
Golang e DSA
Favicon
Wanna Know Big O Basics!
Favicon
Time Complexity, Big-O for Beginners
Favicon
This Is Your Sign to Start Learning DSA 🖥️✨
Favicon
How to learn DSA , Complete Roadmap with Resources
Favicon
From 0 to O(n): A Beginner's Guide to Big O Notation
Favicon
Entity and Relationship
Favicon
Your journey to MAANG: Understanding Arrays
Favicon
Kadane's Algorithm: Leetcode 53 Maximum subarray
Favicon
linked list java insert , delete , update , search , print
Favicon
Time and Space Complexity
Favicon
Dev Video Review: Firestore Data Structure, Limitations, and IMHO
Favicon
Yay! Reached 1035+ days Daily Coding Streak on Leetcode!
Favicon
Understanding Linked Lists: A Solution to Array Limitations
Favicon
Data structures and algorithms in C#
Favicon
Heaps, Data Structures
Favicon
Valid Anagram
Favicon
Sorted Data Structures in Python
Favicon
Recursion it is : LeetCode 494
Favicon
Hashing, DSA Complete Syllabus
Favicon
How Memory Shapes Data Structures: Arrays and Allocation
Favicon
🔍 Mastering the Sliding Window Technique: A Developer's Guide
Favicon
DSA ROADMAP FOR BASIC TO INTERMEDIATE IN 6 MONTHS
Favicon
Transforming AI with Image Datasets for Machine Learning
Favicon
Data Structure
Favicon
211. Add and Search Word - Data structure design
Favicon
701. Insert into a Binary Search Tree
Favicon
706. Design HashMap

Featured ones: