A discussion platform precomputes ranked feeds as materialised views. What does this buy, and what are the failure modes?
Show the full answer Hide the answer
What it buys
Read cost decoupled from computation cost. A ranked feed requiring an expensive aggregation over votes, recency and engagement is computed once and read many times. For a read-dominated workload with expensive reads, this is the difference between viable and not.
It also bounds tail latency, because the read path no longer depends on a query whose cost varies with data volume.
The failure modes
1. Staleness at the wrong moment. A user's own action — voting, commenting — not reflected immediately looks like the system lost it. Their own action must appear; other users' can lag. This asymmetry drives the design: apply the user's own change optimistically on top of the materialised result.
2. The refresh becoming the bottleneck. For hot content the view must refresh constantly, so the write amplification moves the problem rather than removing it. The usual answer is refresh frequency scaled by popularity — hot items refreshed often, the long tail rarely.
3. A silently wrong view. A bug in the refresh produces incorrect rankings with no error. This is the characteristic failure of any derived data and needs reconciliation against a recomputation, sampled.
4. Rebuild cost. If the view is corrupted or the ranking changes, regenerating it for the whole corpus may take longer than is acceptable. A rebuild path that has been exercised is a requirement, not a design detail.
5. Unbounded growth, where views are materialised for content nobody reads. Materialise lazily for cold content and eagerly for hot.
The decision between database-maintained and application-maintained
Database-maintained views are coherent by construction and refresh on the database's terms — simpler, and limited to what the database can express.
Application-maintained projections handle arbitrary logic and a different storage technology, at the cost of a pipeline that can lag, fail and be silently wrong.
Prefer the database-maintained version when it can express the computation. The pipeline is the expensive part, and avoiding it avoids most of the failure modes above.
The correctness boundary
Decisions with consequences are validated against the source of truth, never against the view. Ranking may be stale; permission checks and vote deduplication may not.