3 ms·
I don't think you want to be storing individual view events in a relational database. You are looking at billions of events. Of course running a count(*) every
by Gigachad 5y ago
I don't think you want to be storing individual view events in a relational database. You are looking at billions of events. Of course running a count(*) every time you want to show the view count would be absurd. But I imagine how it would work in practice is you store all events in something like elasticsearch and then every x minutes you recalculate the number of views if there were any new events and store that calculated number somewhere.
What I would _not_ be doing is something like the active record cache_key to calculate if any changes have occurred to decide if you grab from redis or run the query again. For something like view count, it doesn't matter if the data is slightly stale.