Quick revision
The short answer
Denormalization means storing redundant data on purpose so that reads are cheaper, accepting that writes become more complex. Two good examples are a price snapshot on an order line, which must not change when the product price changes later, and a comment_count on posts kept up to date in the same transaction as the insert. A bad example is copying a user's email into many tables with no update path, so notifications go to an old address.
What to remember
In this answer, we defined denormalization as deliberate redundancy that makes reads cheaper at the cost of more complex writes. A price snapshot on an order line is safe because it is never updated, a comment counter is safe because it changes in the same transaction as the comments, and an email copied into many tables without an update path causes real bugs. The deciding question is whether a copy is a snapshot or a cache, because only caches need updating.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Denormalization means storing redundant data on purpose so that reads are cheaper, accepting that writes become more complex. Two good examples are a price snapshot on an order line, which must not change when the product price changes later, and a comment_count on posts kept up to date in the same transaction as the insert. A bad example is copying a user's email into many tables with no update path, so notifications go to an old address.
Why this question is asked
Every production schema has some denormalization, and the difference between a good one and a bug is usually not the redundancy itself but whether anyone decided what the copy means. Interviewers ask this to see whether we can name that difference. In this answer, we will define denormalization against normalization, work through the two good examples with code, reproduce the email bug, and end with the one question that tells us whether a copy needs updating.
1A Quick Recap of Normalization and Its Opposite
A normalized schema stores each fact once. The product's price lives in products, the user's email lives in users, and anything that needs them joins to that row. The benefit is that a change happens in one place and everyone sees it.
Denormalization stores a fact, or something computed from facts, in a second place. We do it because a join or an aggregation on every read costs time, and some pages are read thousands of times for every write. The price we pay is that every write must now consider the copies too, or the copies go wrong.
2Good Example 1: A Price Snapshot on the Order Line
When a customer buys a lamp for 40.00, the order must keep saying 40.00 even after we raise the price to 45.00 next month. If order lines only referenced the product, the invoice would change after the fact.
Strictly, this is not even redundancy in the harmful sense. The copied value is a different fact: the price that applied at the moment of purchase. It is written once and never updated, so there is nothing to keep in sync.
3Good Example 2: A Counter on a Hot Page
A post page shows '1,284 comments'. Running SELECT count(*) FROM comments WHERE post_id = ? on every view reads all those comment index entries every time, which adds up on a popular post. Instead we keep a counter on the post and update it in the same transaction as the comment.
Because both statements commit or roll back together, the counter cannot drift from the real number of comments, as long as every code path that inserts or deletes comments also updates it. That is the catch with this kind of copy: it is a cache of current data, so every writer must remember it. Putting the logic in one repository method, or in a trigger, keeps it in one place.
4The Bad Example: An Email Copied Everywhere
Someone added an email column to orders, subscriptions and support_tickets so that each service could send notifications without joining to users. Nobody wrote an update path. The user changes their email in their profile.
Unlike the price, this copy is supposed to mean the same thing as the source: the user's current email. So it must be updated whenever the source changes, and nothing does that. Worse, the old address might now belong to somebody else, which turns a stale copy into a privacy incident.
5The Question That Decides: Snapshot or Cache?
Every denormalized column should say which of two things it is. A snapshot records a value as of a moment and is never updated afterwards. A cache mirrors the current value of a source and must be refreshed, with a known mechanism and a known delay.
| Copy | Kind | Needs updating? | How |
|---|---|---|---|
order_lines.unit_price | Snapshot | No | Written once at order time |
posts.comment_count | Cache | Yes | Same transaction as the comment |
subscriptions.email | Cache | Yes | Nothing does it, so it drifts |
Writing the kind into the column comment or the design document costs one sentence and prevents the third row. If a cache has no reliable update path, the honest options are to add one (same transaction, trigger or event) or to remove the copy and join.
6Follow-up questions
How do counters behave under high write concurrency?
UPDATE posts SET comment_count = comment_count + 1 is correct under concurrency, because the database applies each increment to the latest committed value. But every writer must take the row lock on that post row, so on a very popular post the increments queue up one after another and the row becomes a hot spot. The usual fixes are to batch increments asynchronously and accept a slightly stale number, or to spread the counter over several rows (for example ten shard rows per post) and sum them when reading.
Why not compute the count with an index-only scan instead?
For moderate numbers an index on comments(post_id) makes count(*) fast enough, and that should be tried first. The counter becomes worth it when a page is read far more often than it is written and the counts are large, so the read cost grows with every comment while the counter read stays one row.
Is a materialized view a form of denormalization?
Yes. It stores the result of a query, so it is a cache of current data with an explicit refresh rule. The difference from a hand-made copy is that the database knows how to rebuild it, so the refresh rule is visible and cannot be forgotten in one code path.
7Conclusion
In this answer, we defined denormalization as deliberate redundancy that makes reads cheaper at the cost of more complex writes. A price snapshot on an order line is safe because it is never updated, a comment counter is safe because it changes in the same transaction as the comments, and an email copied into many tables without an update path causes real bugs. The deciding question is whether a copy is a snapshot or a cache, because only caches need updating.
Open with
Denormalization is storing redundant data on purpose to make reads cheaper, and accepting that writes get more complicated. A good first example is the unit price on an order line.
Then, if they want more
When we sell a lamp for 40, the order must keep showing 40 even after the catalog price changes, so we copy the price at order time and never update it. Strictly it is a different fact, the price at the moment of purchase. A second good example is a comment_count column on posts.
Counting comments on every page view of a popular post is wasteful, so I increment the counter in the same transaction as the comment insert, and since both commit together the number cannot drift, provided every code path goes through the same method or a trigger.
A bad example is copying the user's email into orders, subscriptions and tickets so each service can send notifications without a join, with no update path. When the user changes their email, the copies keep the old address, reminders go to the wrong place, and if the old address now belongs to someone else it is a privacy problem.
The rule I use is to label every copy as either a snapshot, which never changes, or a cache of current data, which needs a defined refresh mechanism and a known delay. If a cache has no refresh path, I either add one or remove the copy.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What is denormalization, and give two examples where it is a good idea and one where it...": https://scrivio-interview-library.netlify.app/databases/data-modeling/e5226d8824/