Part 4 of 5 · 2 min read
Deciding whether it's worth it
Weighing the read-performance gain against the consistency cost, for a specific real case.
Deciding whether it's worth it
Think of deciding whether to print a hundred name badges in advance. The alternative is looking each person up on a tablet at the door. The right choice depends on how often names actually change, and how fast the lookup needs to be.
In plain words: denormalizing is worth it when a read happens far more often than the underlying data changes, and the read's performance genuinely matters, such as on a hot path with heavy traffic. It's usually not worth it for data that changes often, or for a read that is rarely performed and can tolerate a join's cost.
A worked example. Caching a book's total number of reviews directly on books, updated by a trigger whenever a review is added, is worth it if the book's page is read constantly and the review count is read far more often than it changes. Caching a customer's exact current address on every historical order is less obviously worth it, since addresses change relatively often and old orders rarely need the live current value anyway.
The key lines. No new code; this part is the decision framework itself.
For the curious A common middle ground: materialized views
Level 2's module on views, and Level 6's module on materialized views, cover a structured way to get some of denormalization's speed without managing the duplication by hand: a materialized view is explicitly, visibly a cached copy, refreshed on a known schedule, rather than a silent extra column whose staleness rules live only in someone's memory.
Quick notes
- Denormalization deliberately stores redundant or precomputed data to avoid an expensive join or recalculation.
- Every denormalized copy needs an explicit plan for staying in sync with its source.
- Without that plan, a denormalized copy silently drifts out of correctness over time.
- Denormalizing is worth it when reads vastly outnumber changes, and read performance genuinely matters.
- A materialized view is often a more structured, visible alternative to hand-managed denormalization.