What counts as a Firestore "Write" ?

452 views
Skip to first unread message

bill....@hallsteninnovations.com

unread,
May 24, 2018, 12:55:10 PM5/24/18
to Firebase Google Group
TL:DR; Does updating sub-documents multiple "Write" counts? Quota usage seems waaay higher than expected 

Background:

Each device has a document created per day to hold the data.

Each document has a a sub-document for each hour of the day. 

Which in turn has a sub-document for each minute.

Which in turn has a sub-document for each second.

So I can record a particular sensor reading in time like

db.collection(device).document("\(dateKey)").updateData([

"\(hour).\(minute).\(second)": value])

Kato Richardson

unread,
May 24, 2018, 1:06:27 PM5/24/18
to Firebase Google Group
Hi Bill,

Can you be a bit more specific? How are you verifying that each sensor is only being written once per second? What does that code look like? How many writes are you expecting and how many have you seen?

For reference, that's presumably 86k writes per sensor, per day.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/08be716a-c79c-4359-9750-fd5657ee4881%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

bill....@hallsteninnovations.com

unread,
May 24, 2018, 2:38:16 PM5/24/18
to Firebase Google Group
Hi Kato,

I ran my test harness for about 1hr and saw ~10k writes.  

Yes, I expect about 86k writes per day per device. 

It seems that updating sub-documents cascades the write-count. 

So I will be forced to look at the RTDB as the data sink.

See attached for an example on the data structure. Document has root elements of 0-24 for each hour.



--Bill
Screen Shot 2018-05-24 at 1.55.59 PM.png

Kato Richardson

unread,
May 24, 2018, 2:51:02 PM5/24/18
to Firebase Google Group
Still not really sure what you mean by "updating subdocuments". A lot probably depends on exactly how you're doing that. Writing to a document in a nested child collection should be roughly the same as writing to a parent collection. Writing to both would probably count as 2 writes. Some code might clear things up and help us break down what's happening. 

Also, how many writes are you conducting that pricing is even a concern here? The pricing calculator suggests that 15 million writes would run you about $25 / month. Is that prohibitive? How strict is the every second constraint? You could half your costs or double capacity by simply dialing that back to every other second.

☼, Kato


For more options, visit https://groups.google.com/d/optout.

bill....@hallsteninnovations.com

unread,
May 24, 2018, 3:45:39 PM5/24/18
to Firebase Google Group
Hi Kato,

I am not sure code will help with this question. 

If you look at the screenshot -- you'll see the data structure. Each second, updateData is called on a nested subdocument. 

So for example, a call to updateData("16.7.45": data) //note the key representing my nested data structure

I just did the quick math -- and to me -- confirms that a write multiples with subdocuments.

So assume 86k writes per day, or 3600 per hour.

I expect to see 3600 per hour with updateData("16.7.45": data), but instead see ~10k. 

I am going to assume this is because my document is 3 levels deep. 

Kato Richardson

unread,
May 24, 2018, 4:37:40 PM5/24/18
to Firebase Google Group
But I doubt that doing a write on a nested object property with dot notation is having an affect on the number of writes. There could be some infrastructure detail here I don't know about, but that seems unlikely. 

I couldn't guess what's actually happening without seeing some code. If it is a bug or inefficiency at our end, seems likely to be nuanced around exactly how the writes are occurring. Other possibilities are Functions invocations or simply that more writes are being sent than one every second.

If all the values are all known at once, you might also get significant gains by batching the writes. But again, I can't tell what you're already doing without seeing the implementation.

One thing you could try is turning on debug logging. That might offer some clues.

Sorry I can't be more helpful.

☼, Kato


For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages