What is denormalization and when is it used?

Answer

Denormalization is the intentional introduction of redundancy into a normalized schema to improve read performance. Examples: storing a pre-calculated order_total in the orders table (instead of summing line items each query), duplicating a user's name in a comments table (avoiding a JOIN), or maintaining a posts_count column on the users table. Denormalization trades write complexity (maintaining consistency of duplicated data) for faster reads and fewer JOINs. It is commonly used in: read-heavy applications, data warehouses/OLAP, caching layers, and document databases. Always normalize first, then denormalize specific bottlenecks based on profiling.