Hacker News new | ask | show | jobs
by pdkl95 2351 days ago
"There are two hard things in computer science: cache invalidation, naming things, and off-by-one errors." (Phil Karlton, et al)

Views (both regular and materialized) are really useful, but remember that storing data in two places really is one of the of the hard problems in CS. Refreshing the materialized view on a timer might seem easy, but 6 months from now when something important reads from the stale view instead of the real table could become a really frustrating bug. A materialized view might still be a worthwhile optimization; just remember that you're also adding cache management, which might be more complicated than you suspect.

2 comments

Presumably if you're materializing a view, you have to have a cache for speed — it's either this or ElasticSearch or Redis. For me, where possible, it's nice to have a correct cache a `REFRESH MATERIALIZED VIEW` away instead of needing to make sure your cache book-keeping is perfect with other solutions.

But yes, you're right that this is caching, with all associated pitfalls.

At the end of the day, whatever benefits are supposed to derive from the technique seem mostly academic.