1

I am starting to use Firebase to store data information. I learned that it is better to have it in a narrow structure instead of deep structure.

I have the following structure:

MainDetail
  -Kd92jd93kaod93  <----ID
  -Kfirkd9rmtiepr
  -.....More than 1 million more

The question I have is that, I have over a million data and over a million ID's will be stored in a linear sequence under each main nodes like above.

Is this a good approach to have all the ids in one nodes? or should I break it down further such as by a date? Like...

01_MainDetail
  -20170902
      -Kd92jd93kaod93 
      -Kfirkd9rmtiepr
      -....
  -20170901
      -Kd92jd93rt4e3 
      -Kfer5hrmtiepr
      -....      
  -....

This contradicts what I read online as now I am not making it narrow and having multiple children.

What is the right approach when I have lots of data?

Community
  • 1
  • 1
Steve Kim
  • 5,293
  • 16
  • 54
  • 99

2 Answers2

1

The Good approach is to keep data organised like you said in chunks of dates under parent node.

This approach will not be a source of trouble for you.

1

There is no realistic limit on the number of child nodes under a node. It all depends on how you want to access those child nodes. Specifically:

  1. Querying long lists of data will always take more time than querying a shorter list of data.
  2. Reading a list of nodes will always be faster that querying for those same nodes from a longer list.

See these answers for more:

It is often best to partition data to match with how you want to access it. The second data structure you show is an example of that, since it allows you to access the nodes for a specific date without needing to query for them.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807