kuklis
kuklis

Reputation: 131

Firestore Collection Write Rate

The article about Best practices for Cloud Firestore states that we should keep the rate of write operations for an individual collection under 1,000 operations/second.

But at the same time, the Firebase team says in Choose a data structure that root-level collections "offer the most flexibility and scalability".

What if I have a root-level collection (e.g. "messages") which expects to have more than 1,000 write operations/second?

Upvotes: 0

Views: 230

Answers (2)

David
David

Reputation: 135

The limit of 1,000 ops/sec per collection only apply to realtime update, so as long as you don't have a snapshot listener this should be okay.

I asked the question on the Cloud Firestore Google Groups

The limit is 10,000 writes per second if no other limits apply first: https://firebase.google.com/docs/firestore/quotas#writes_and_transactions

Also just keep in mind the best practices for scaling cloud firestore

Upvotes: 0

Alex Mamo
Alex Mamo

Reputation: 138814

If you think at that limitation of 1,000 operations/second it's pretty much but if you find your self in a situation in which you need more than that, then you should consider changing your database schema to allow writes on multiple collections. So you should multiply the number of collections. Having a single collection of messages, in which every user can add messages doesn't sound as a good way to go since you can reach that limitation very soon. In this case you should split that collection into multiple other collections. A possible schema might be the one I have explained in the following video:

See, at the end of that video, there is collection named messages which in term contains a roomId document. This document contains a subcollection named roomMessages which contains as documents all messages from a chat room. In this case, there are no chances you can reach that limitation.

But at the same time, the Firebase team says in Choose a data structure that root-level collections "offer the most flexibility and scalability".

But also rememeber, Firestore can as quickly look up a collection at level 1 as it can at level 100, so you don't need to worry about that.

Upvotes: 1

Related Questions