Using firestore with large data set, how to cache effectively?

729 views
Skip to first unread message

Alex Egli

unread,
Nov 6, 2020, 4:40:16 AM11/6/20
to Firebase Google Group
Hi,

I'm currently working on migrating a web application built with couchbase and sync gateway to use Firestore (and Firebase in general) instead. I am stuck on how to effectively cache user data for performance and cost. This seems like it would be a common problem so I wanted to know if there are any known patterns for handling this with Firestore.

As an example, in one component I display a chart that shows data for users across a specified timeframe. This chart could contain data for a hundred users and the timeframe can be changed. So I can't use snapshot listeners because it would go over 100 listeners easily and when the timeframe gets changed the query will change so all the listeners will be invalidated, but if the new timeframe includes some of the original data I wouldn't want to re-retrieve everything.

For some background, my team is trying to migrate from Couchbase to Firestore. With couchbase we could use couchbaselite and sync gateway to fully manage our offline cache on our app, and use the sync gateway changes feed to manage an in-memory cache on the web. It initially seemed like the Firestore offline cache could do effectively the same thing but after researching it more and working with it I've found that it's much more limited in functionality and storage. There are a lot of advantages with the Firebase ecosystem so we really want to use it, but this is a big hurdle for us since it seems like Firestore simply wouldn't be appropriate for the amount of data our applications use.

pa...@renshaw.dev

unread,
Nov 7, 2020, 10:36:48 AM11/7/20
to Firebase Google Group
Make an API-like cloud function that uses the admin API to retrieve the data from firestore, set caching headers on the function response and pair it with a hosting rewrite rule, your responses for the same requests will then be cached on the hosting CDN, subsequent requests with the same parameters will not trigger your functions or make any requests to firestore.
Reply all
Reply to author
Forward
0 new messages