Nominalista
Nominalista

Reputation: 4840

Is there any limit for multiple writes to the Cloud Firestore?

I make new documents multiple times without checking the success of the write:

for element in data {
   val document = firestore.collection("test")
   document.set(element)
}

Sometimes data contains hundreds of elements and I have discovered that in some rare cases not every document is uploaded to the cloud (e.g. 5% are not successfully uploaded, but only the last elements).

Is there any limit for multiple writes? Should I wrap it into the batch?

Upvotes: 2

Views: 734

Answers (1)

robsiemb
robsiemb

Reputation: 6354

Yes, there are limits on Firestore performance for a large number of writes.

  • There is a one update per second limit to a single document. In this case, it would definitely be better to write the document all at once rather than one value at a time (plus, it would cost a lot less). The documentation notes that this limit is somewhat soft but recommends strongly against exceeding it.

  • If you are writing in a narrow document range (or with a new collection), you may also run into performance problems. Make sure you are either using automatic ids or are scattering them around the range.

Finally, there are some flat out limits to writes, including a 500 per second write rate to a collection in which documents contain sequential values on an indexed field.

Based on another recent question batching is at best a wash against parallel writes, and does add complexity, but it is faster than doing sequential writes. That answer also suggests not using the client SDKs for bulk writes (e.g. use the Admin SDK).

Upvotes: 5

Related Questions