Skip to content
Tech Interview Prep
Technical interview guide

Schema Design & Normalization

Structuring tables to avoid redundant, inconsistent data, and knowing when to deliberately break the rules for performance.

Minutes to read
4
Practice MCQs
25
Interview Q&A
25
Edition
v4
Editorial status
Reviewed

Scope: SQL principles with PostgreSQL 18 examples; vendor-specific behavior must be verified.

Overview

Curated: · Written: · Reviewed:

Schema Design & Normalization

In one line

Normalize until every fact is stored once, so an update cannot leave the database disagreeing with itself. Break that on purpose only when a measured read pattern justifies copying a value, and name what the copy costs to keep consistent.

Key definitions

  • Functional dependency X → Y: rows that agree on X must agree on Y.
  • 1NF: each column holds one atomic value. A tags column you filter by a single tag violates it.
  • 2NF: every non-key column depends on the whole primary key. Depending on part of a composite key is a partial dependency.
  • 3NF: no non-key column depends on another non-key column (a transitive dependency).
  • Surrogate key with unique natural key: the surrogate is the stable reference, and the unique constraint keeps the real-world rule enforced.
  • Snapshot vs copy: a point-in-time fact such as price paid belongs on the child row. A copy of a current value is redundancy you must keep in sync.

How it works

Constraints live in the database, so they hold for every writer. Rules in application code hold only while every writer remembers them.

A check-then-insert is a race. Two transactions both see no row and both insert. A unique index, partial unique index or exclusion constraint makes the check and the insert atomic.

A denormalized copy needs three things named: the read/write ratio, the write amplification, and the mechanism that keeps copies honest (same-transaction trigger, generated column, or reconciliation job).

Schema changes follow expand, migrate, contract. Add a NOT VALID constraint, then VALIDATE it separately to avoid a long lock.

Expand: add nullable column or NOT VALID constraint Deploy v2: write old and new Backfill in bounded batches Deploy v3: read new column Contract: drop old column

When to use and when not to

ChoiceUse whenAvoid when
Normalized tablesValues change and writes are frequentA join on the hot path is measured as the bottleneck
Denormalized copyRead/write ratio is high and the value rarely changesThe source changes often or is written from many paths
Snapshot columnThe fact is point-in-time, such as price at purchaseThe value should track the current source
Surrogate key plus natural uniqueBusiness identifiers may changeThe identifier is stable and never referenced elsewhere
JSON columnAttributes vary per row or the payload is opaqueKeys are fixed and get filtered, joined or aggregated
Lookup tableThe set changes or rows need attributesA small fixed set with no attributes (use a CHECK)
Partial unique indexOne active row per entity while keeping historyThe database lacks partial indexes (use a generated column)

Traps interviewers probe

  1. Enforcing uniqueness with SELECT then INSERT. Fix: declare a unique, partial unique or exclusion constraint so the database enforces it under concurrency.
  2. Dropping the unique constraint because the surrogate is the primary key. Fix: keep both. The surrogate gives stable references, and the unique constraint keeps duplicates out.
  3. Treating a copied current value as a snapshot. Fix: ask whether it is the same fact or a point-in-time record. Copy only the latter onto the child row.
  4. Overwriting in place when history will be asked for. Fix: model validity ranges or an append-only event table before the column exists. The past cannot be recovered later.
  5. Adding a constraint or NOT NULL in one step on a live table. Fix: add NOT VALID, validate separately, and run expand, migrate, contract across separate deploys.

Interview tips

Open with the access patterns: which queries run, the cardinality of the columns they filter on, and the read/write ratio. Then draw the normalized shape and say which part you would denormalize and why.

Expect these follow-ups: what happens under concurrent writes; which index you would add and why that column order; how the design changes at ten times the data; how you would backfill existing rows; and what changes if the read/write ratio is inverted.

30-second outline: Start from the queries and the read/write ratio. Normalize to 3NF and name any functional dependency that violates it. Enforce uniqueness and overlap rules in the database, not in a validator. Denormalize only the one value the hot path needs, and name the trigger or reconciliation that keeps it correct. Finish with the expand, migrate, contract sequence for rolling it out.

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.