Denormalization
Denormalization
Improving read performance through deliberate data duplication.
Denormalization
Improving read performance through deliberate data duplication.
Denormalization is a technique that intentionally adds redundant data to a normalized database to optimize read performance. Normalization guarantees data integrity, but complex joins can degrade query performance.
The main strategies of denormalization include adding redundant columns (copying frequently queried data), storing derived columns (storing calculated values in advance), merging tables (consolidating tables with a 1:1 relationship), and creating summary tables (precomputing aggregated data).
Read performance improves, but additional logic is required to maintain data consistency and storage space increases. It is mainly used in OLAP systems, reporting dashboards, and read-centric APIs.
-- 정규화된 구조 (조인 필요)
SELECT o.order_id, c.customer_name, o.total
FROM orders o
JOIN customers c ON o.customer_id = c.id;
-- 비정규화된 구조 (중복 저장)
CREATE TABLE orders_denormalized (
order_id INT PRIMARY KEY,
customer_id INT,
customer_name VARCHAR(100), -- 중복 저장
total DECIMAL(10,2),
created_at TIMESTAMP
);
-- 파생 컬럼 예시: 주문 수와 총액 저장
ALTER TABLE customers
ADD COLUMN order_count INT DEFAULT 0,
ADD COLUMN total_spent DECIMAL(12,2) DEFAULT 0;
-- 트리거로 동기화 유지
CREATE TRIGGER update_customer_stats
AFTER INSERT ON orders
FOR EACH ROW
BEGIN
UPDATE customers
SET order_count = order_count + 1,
total_spent = total_spent + NEW.total
WHERE id = NEW.customer_id;
END;
Backend developer: "Dashboard queries are too slow. Because we join 5 tables every time..."
DBA: "Shall we denormalize and create a summary table? What if we precompute order statistics in the customer table?"
Backend developer: "How do we handle data synchronization?"
DBA: "We update it with triggers or batch jobs, and if real-time freshness isn't important, allowing a 5-minute delay is also an option."
Interviewer: "Please explain when denormalization is needed and what to watch out for."
Candidate: "It's suitable when read performance is important and write frequency is low. It reduces join costs and precomputes complex aggregations. However, because of the risk of inconsistency caused by data duplication, synchronization logic at the trigger or application level is essential."
Interviewer: "Do you have any experience actually applying it?"
Candidate: "Yes, in a reporting system, I created a daily sales summary table and reduced query time from 8 seconds to 200ms."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
Reviewer: "I see you added a last_order_date column to the customer table?"
Developer: "Yes, we often query customer lists based on the most recent order date, so I denormalized it."
Reviewer: "Good. But is there also logic to update this value when an order is deleted or canceled?"
Developer: "Ah, I missed the order cancellation case. I'll add a synchronization method to the service layer."