The use case:
- 50K to 100K trucks updating both location and internal engine info in real time.
- From a console, it's crucial to update the interface every time a truck within some range changes location OR changes internal engine info. So if location is the same but engine info is new, should trigger update.
The problem:
- Geofire only queries by location, so I'd have to create a Geoquery AND listen to each truck's info individually, which is impracticable ad expensive both in Realtime DB and Firestore.
- Firestore is not clear about real time listeners combined with Geoqueries(as far as I know there is no onSnapshot for Geoqueries in Firestore and even so would be super expensive for this case).
The suboptimal alternative: [Web Javascript Firebase V9 Modular] I would use Firestore, create a Geoquery for a given range(which is static, not real time) and get all docs from it. Then in the console the user would only see real time info by clicking into a specific truck(document), so I could attach onSnapshot to that document.
Is this use case simply not supported or is there a way to model data to accommodate it at a reasonable cost ?
GeoFire is only fully supported on the Realtime Database. GeoFire's data is intended to be kept separate from your own data and linked to it by a unique key/id. This minimises the indexing required to execute queries and minimises the data handed around while querying.
There is a workaround for Cloud Firestore but it's not ideal for your use case because it grabs all the nearby records then filters the rest on the client.
If you are curious, a GeoFire entry looks similar to the following when uploaded (this is formatted for readability):
As can be seen above, there isn't any user-provided data here only a "key". This key can have any meaning such as the code of an airport in a registry, a push ID under a Realtime Database location, a Cloud Firestore document ID or some base64-encoded data.
With the introduction of Firestore, a number of users store the GeoFire data in the Realtime Database and link it back to Cloud Firestore documents using the key stored in GeoFire.
In the below example, a
truckInfoobject looks like this:For the below code to work, you must define two callback methods:
These callbacks are then invoked by the following "engine":