mapswipe / leaderboard

A simple leaderboard to allow display and aggregation of user metrics
0 stars 0 forks source link

Cost mitigation idea #30

Open laurentS opened 3 years ago

laurentS commented 3 years ago

With the current mapathon ongoing, we've seen the firebase bill go through the roof, even with @Hagellach37 's fix 2-3 days ago on this code (which limits loading to the mappers who've opened the app in the last 24h, instead of all users ever).

There is still a lot of download happening, apparently because users keep refreshing the leaderboard a lot more than we expected. An option to mitigate this cost in downloads could be to run a function server-side (within firebase) that prepares and caches values to show. For instance, we could imagine running a function every 5 minutes, which would simply run the current query, and copy the result onto some cloud storage (or VPN), and modify the frontend to load that file from bulk storage instead of firebase (and we put some caching logic there so that browsers don't reload more often than once/5 minutes for instance).

This would give us both lower transfer costs (we would effectively only have 1 load/5 minutes), and possibly faster loading for the leaderboard.

Hagellach37 commented 3 years ago

We could try to provide files through the back end workers, e.g. as we do here already: https://apps.mapswipe.org/api/users/

This is currently based per project, but we could adjust this and provide a file for all users and use some compression as well. So basically by merging all the existing files.

Currently these things are updated once every hour. Not sure if this is enough? From the backend side updates more frequent than every 15 minutes will be a bit harder.