Skip to the page

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.

The 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

  1. When is denormalisation the right call?
  2. How would you show 'likes' on a feed of 50 posts quickly?
  3. How do you keep a denormalised copy in sync?
  4. Materialised view vs Redis cache for a dashboard?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview