Node.js › Databases
What is database normalization, and what specific problems can over-normalization or under-normalization cause?
IntermediateAnswer
Normalization organizes relational data to minimize redundancy, typically by splitting data into multiple related tables connected via foreign keys rather than repeating the same information across many rows. Under-normalization (excessive duplication) risks data inconsistency when the same fact needs updating in many places. Over-normalization can require excessive joins across many tables for even simple queries, hurting both query performance and code complexity, which is why some applications deliberately denormalize specific frequently-read data for performance.
-- Normalized: customer info stored once, referenced by ID
CREATE TABLE customers (id SERIAL PRIMARY KEY, name TEXT, email TEXT);
CREATE TABLE orders (id SERIAL PRIMARY KEY, customer_id INT REFERENCES customers(id), total DECIMAL);
-- vs. denormalized: customer name duplicated on every order row for fast readsReal-world example A reporting dashboard querying heavily normalized order data across five joined tables was too slow for real-time use; the team deliberately denormalized a subset of frequently-needed fields into a dedicated reporting table, trading some redundancy for significantly faster read performance.