I've seen in the Firebase Firestore documentation's 'Best Practices' that you should:
Avoid high read or write rates to lexicographically close documents, or your application will experience contention errors.
An example given of how not to write document IDs is:
Customer1, Customer2, Customer3, ...
I'm mapping data from an external service into a Firestore collection, and I want to keep their original ID names. They are prefixed with entry_
, but then suffixed with a random / unique string as follows:
entry_{Unique_String}, entry_{Unique_String}, ... entry_{Unique_String}
Does each document ID being prefixed with entry_
, but followed by a random string, categorise the documents together as being lexographically close and therefore predisposed to hotspotting?
Or, would it only be classed as such if they were indeed named:
entry_1, entry_2, entry_3, entry_4 ... <and so on>
I could of course strip / add entry_
to the IDs when reading / writing, but this would add more complexity to the server / client.*
*Edit to clarify as per Alex Mamo's comment:
Complexity would increase due to the following examples:
- Introduction of strip / prepend
"entry_"
function wherever docs are being read / written in context of original dataset or need to be sent back to external service. - May require creation of document fields to track (e.g.
type = "entry"
) where multiple categories of document ID are used in the same collection -- This may not be a disadvantage depending on use-case, e.g. if performing type comparisons. - Tedious to reimplement the above for other category types (e.g.
foo_
,bar_
) that originate from the same external service, with the same prefixed unique strings.