chris
chris

Reputation: 727

When is Nesting OK in Firebase?

Firebase's Structuring Data documentation explicitly says to "Avoid Building Nests". The primary reason given is that

when we fetch data for a node in Firebase, we also retrieve all of its child nodes.

With this in mind, is it still efficient to nest deeply if the data is still denormalized properly?

For example, here is a possible Firebase structure for an app with geotagged posts and geo-indexes by post language:

posts/{postId}
indexes/
        languages/
                  en/geohashes/{geohash}
                  es/geohashes/{geohash}
                  de/geohashes/{geohash}

Compare this to a completely flat structure:

posts/{postId}
index_en_geohashes/{geohash}
index_es_geohashes/{geohash}
index_de_geohashes/{geohash}

I find the first nested structure clean and self-documenting. Is this just as efficient as the flat structure? (Let's say the most common use-case is 'query language x geohashes')

Upvotes: 3

Views: 816

Answers (1)

chris
chris

Reputation: 727

A query from the nested structure /indexes/languages/en/geohashes/ and flat structure /index_en_geohashes/ are computationally equivalent.

Upvotes: 1

Related Questions