Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Cloud Functions // Snapshot has no readTime

I'm getting strange warning messages in my Firebase Cloud Functions logs:

Snapshot has no readTime. Using now()

I have quite a number of functions running and it happens with a good handful of them. But it doesn't happen with each invocation, just occasionally.

A google search turned up the line responsible for this message in the snapshotConstructor function within the firebase-functions lib. You can find it on Github here. It seems like the data.value.readTime isn't available on the Event.

What exactly is causing this error and is it a problem?


UPDATE: I've discovered this is happening when onWrite functions are triggered at the same time by the same document. I have a few functions that start like this:

functions
.firestore.document('organizations/{organizationId}/updates/{updateId}')
.onWrite(async (change, context) => {...

Again, it doesn't happen every time they're triggered, but often enough to warrant concern.

like image 436
CDoe Avatar asked Dec 06 '25 02:12

CDoe


1 Answers

Firestore used to have a soft-limit of 1 write per second for a single document. This soft-limit has been removed from the documentation but there is still information such as the Firebase documentation on read/write operations:

Read and write operations

  • The exact maximum rate that an app can update a single document depends highly on the workload. For more information, see Updates to a single document.

That link points to documentation that provides warnings about writing to a single document:

Updates to a single document

As you design your app, consider how quickly your app updates single documents. The best way to characterize your workload's performance is to perform load testing. The exact maximum rate that an app can update a single document depends highly on the workload. Factors include the write rate, contention among requests, and the number affected indexes.

A document write operation updates the document and any associated indexes, and Firestore synchronously applies the write operation across a quorum of replicas. At high enough write rates, the database will start to encounter contention, higher latency, or other errors.

That's what's happening here:

  1. You have multiple writes to a single document in a very short period of time
  2. You have onWrite-triggered functions that are firing in response to these events
  3. Firestore is attempting to acquire information about the document being written but due to a race condition caused by the high write rate to the single document it is unable to do so
  4. The error is then surfaced in the logs

The solution is that you need to limit the write-rate to a single document. This answer explains that the key visualizer should be used to identify hotspots in your application's read/write behavior to limit these issues. Otherwise you will continue to see the contention, higher latency, or other errors mentioned in the documentation.

like image 129
anothermh Avatar answered Dec 08 '25 04:12

anothermh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!