Full answer
Common, defensible forms:
- Snapshot values: an invoice stores the customer's address and the price at the time of sale. This is not just a speed trick; the copy is the correct historical record.
- Counters and totals:
orders.totalorposts.comment_count, maintained by the application, a trigger or a periodic job. - Reporting tables or materialized views that pre-join and pre-aggregate data for dashboards.
Before denormalizing, check that an index, a better query or a materialized view does not solve the problem. Then decide who keeps the copy correct and how drift is detected, for example a nightly check that recomputes totals and compares.
A useful interview framing: normalize the source of truth, then denormalize derived data where measurements justify it.
Key points
- Denormalization adds deliberate redundancy
- Historical snapshots are a legitimate copy
- Counters and reporting tables speed reads
- Someone must keep copies consistent
Common mistakes
- Denormalizing before measuring
- Copying live data without any way to detect drift
Follow-ups
- How would you keep a comment_count accurate?
- How does a materialized view compare with a denormalized column?
Tips
- Separate snapshots from caches