Home > Enterprise >  Are the same document ids in subcollections lead to hotspots in Firestore?
Are the same document ids in subcollections lead to hotspots in Firestore?

Time:11-11

I count some user specific data e.g. received likes and follower in a user document.
Because of the 1 write per second limit I want to move the counters from the user document into a subcollection:

users
    userId1
        userCounters
            likesCounter
            followerCounter
    userId2
        userCounters
            likesCounter
            followerCounter
    ...

So every user got these counters documents with the same name in his subcollection.
I'm wondering if using the same names for the documents in subcollections leads to hotspots?
Is it better to use auto generated ids here or does it not matter?

CodePudding user response:

When documents are written to different (sub)collections, the document writes themselves are not going to cause hotspotting. The subcollections are essentially separate shards here, so the document IDs themselves won't matter.

Hotspots in this scenario can happen when you have a collection group index on the userCounters collections, as documents from all those (sub)collections will then end up in the same index. In a collection group index the documents are identified by their path (instead of just their ID), but it's still more likely to lead to hotspots due to having to write all of them into the same index.

  • Related