skip to Main Content

I’m currently building a todo application with Flutter.
Currently my structure looks like this:

users/{userid}/projects/{projectid}/tasks/(all the tasks) (1)

But I’ve also come up with the following idea. (2)

users/{userid}/projects/{projectid}
users/{userid}/tasks/{taskid} // All tasks hold a reference to the projectid

Is there a difference in performance by getting all tasks from a project collection (1) or by searching all tasks by their projectid (2)?

Feel free to correct me if you come up with better ideas. Also list some positive/negative points about the two approaches if you can.

Enter image description here

Here is the current structure (userid, todos, and all the todos).

2

Answers


  1. Based on my observation:

    1. You store all of a project’s tasks under a project collection. If you wish to access all the tasks associated with a project at once, this structure may be helpful. Yet, it could be challenging and time-consuming to do a search or filter job based on certain criteria.

    2. You are keeping tasks independently and referencing their project If you wish to search or filter tasks based on certain criteria, this structure may be helpful. But challenging and time-consuming to retrieve every job for a project at once.

    So choice of the structure can be considered based on your usecase and requirements

    Login or Signup to reply.
  2. Firestore’s read and query performance does not depends on the number of document it needs to consider, but instead solely depends on the number and size of the documents it has to return. So there is no difference in performance between the two data models based on that.

    Firestore’s main limitations are about write-performance, where you’ll want to avoid so-called hotspots. Hotspots occur when the database has to write data that is close to each other on disk in rapid succession, e.g. when you’re updating the same document over and over, when you have sequential document IDs, or when you have indexes that have such sequential values (such as when you have the current timestamp).

    A lot of this is covered in the documentation, so I recommend checking out the page on best practices with Firestore and in the video series Get to know Cloud Firestore.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search