3 ms·
I'm surprised about: >4. Database queries can probably be left uncached ...but maybe I am thinking about it wrong. Imagine building Quora as a Rails App. For
by andrenotgiant 5y ago
I'm surprised about:
>4. Database queries can probably be left uncached
...but maybe I am thinking about it wrong. Imagine building Quora as a Rails App. For all the interesting user stats like "your answers have been viewed 28,000 times" I feel like your choice is to either denormalize in the application logic and database or cache the complex queries. Are most people taking the first approach?
- ch4s3 5y agoThe DB should be caching some things, and you'd index which is basically a cache.
- Gigachad 5y agoI 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.