Schema design · senior
When to denormalise
Denormalise on purpose when reads vastly outnumber writes and joins or aggregates become the bottleneck (counters, read models, materialised views, snapshots), and always decide how the copy stays in sync and how stale it may be.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Common cases: like/follower counters on the parent row, a precomputed 'order summary' read model, materialised views for dashboards, search documents in Elasticsearch, cached JSON in Redis.
- Keeping copies in sync: same transaction (counter update with the insert), triggers, background jobs, or change data capture/events; each has a staleness window.
- Materialised views (Postgres) store a query result; REFRESH MATERIALIZED VIEW CONCURRENTLY rebuilds without blocking readers.
- Hot counters cause row-lock contention (a viral post); shard the counter or aggregate in Redis and flush periodically.
- JSONB columns are a form of denormalisation: great for flexible attributes, bad for data you join or constrain on.
- Normalise first, measure, then denormalise the specific hot path; document the source of truth.
The red pen
Common traps: mistake → fix
Mistake: Denormalise early for speed
Fix: you pay the consistency cost everywhere before knowing where the bottleneck is.
Mistake: A counter column is always correct
Fix: without updating it in the same transaction (or a repair job) it drifts.
Easy to hard
Questions interviewers ask, easy to hard
- When is denormalisation the right call?
- How would you show 'likes' on a feed of 50 posts quickly?
- How do you keep a denormalised copy in sync?
- Materialised view vs Redis cache for a dashboard?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.