0
votes

In the Cloud Firestore 'Usage and Limits' documentation, the stated rate limit for writing documents to a single collection (accounting for sequential indexing) reads:

Maximum write rate to a collection in which documents contain sequential values in an indexed field: 500 per second

I understand this limit is due to 'hotspotting' when creating the sequential indexes.

My question is: if I disable indexing by all sequential fields in a collection (e.g. timestamp) and only use compound indexes (e.g. [user_id, timestamp]) would the rate limit still apply to the timestamp field across the entire collection or only within a specific user_id?

1
Check out cloud.google.com/firestore/docs/solutions/shard-timestamp. You are sharding by user_id in your case. - Juan Lara

1 Answers

3
votes

It appears that this solution will provide a mitigation against the rate limit for a single collection, as mentioned here by official Firebase staff and with an example solution provided for sharding timestamps.

The essence of the solution just comes down to ensuring that sequential values being indexed are scattered across multiple database shards. This is because close neighbouring sequential values will tend cluster to single internal database machines, forcing throttling to occur when too many writes occur in a short amount of time to a single machine.

Having a prefix before indexing on a sequential value (which can be achieved using a composite index) ensures that these indexes are partitioned across internal machines (given that variance is presented in the first part of the composite index). The rate limit can then be determined by writes within a given composite index prefix, rather than globally in a collection.