← Lessons

quiz vs the machine

Gold1400

Frontend

State Normalization in Stores

Store entities by id in flat lookup tables to kill duplication and update bugs.

5 min read · core · beat Gold to climb

The duplication trap

Storing nested arrays of full objects leads to the same entity appearing in many places. Update one copy and the others go stale. Normalization flattens this into lookup tables, the way a relational database does.

  • Keep an object by id mapping each id to its entity.
  • Keep an array of ids to preserve order.
  • Reference related entities by id, not by embedding them.

Why it helps

When a user appears in a list, a detail view, and a comment, normalization stores the user once.

  • An update touches a single record, and every view reflects it.
  • Lookups by id are constant time.
  • The store shape stays predictable as data grows.

The trade off

Reading nested data now requires joining ids back to entities, often done in a selector. That extra step is the cost of avoiding duplication. Most state libraries provide helpers that build the by id map and ids array for you, so the boilerplate is small.

Key idea

Store entities by id with separate id lists, so each record lives once and a single update fixes every view.

Check yourself

Answer to earn rating on the learn ladder.

1. What is the main benefit of normalizing state?

2. What is the cost of normalization?