1

I'm using geofire to query Firestore as a user walks around. Here's my question:

Let's say my Firestore database has 5000 geohashed records in it and they're randomly located around the world. The records are all stored off a root node in the db. When I execute a geofire query with a very small radius, which of these is happening (assuming the default geofire params):

Option 1: the 1st geoquery generates 5000 billable firebase read ops as it searches all 5000 keys for matches. Each geoquery thereafter (from the same location or different location) uses a cached copy of the 5000 keys and does not generate billable read ops.

Option 2: every geoquery generates a new 5000 billable firebase read ops, regardless of whether the geoquery centerpoint or radius changes

Option 3: something else entirely!

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Reckless
  • 89
  • 1
  • 10

1 Answers1

3

The only billable reads that occur in Cloud Firestore are for those documents returned to the client. GeoFire doesn't change this fact. GeoFire just takes your requirements, translates that into a Firestore query that matches, at minimum, the number of documents that would fall into your requested radius, and possibly some extra. It does not consider all of the documents in the collection. That would be massively inefficient, and defeats the purpose of geohashes in the first place.

From their documentation:

GeoFire selectively loads only the data near certain locations, keeping your applications light and responsive, even with extremely large datasets.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • I think this answers the core of my question. – Reckless Aug 23 '19 at 22:34
  • Can you clarify this statement though, "GeoFire just takes your requirements, translates that into a Firestore query that matches, at minimum" If you ran the same query twice in a row, does GeoFire do any caching or is the same billable query run twice. – Reckless Aug 23 '19 at 22:36
  • All it's saying is that GeoFire knows how to take your query and turn it into an efficient Firestore lookup. Firestore also knows how to cache query results. If you want to know more, you will have to study how geohash queries work. – Doug Stevenson Aug 23 '19 at 23:22