← Lessons

quiz vs the machine

Gold1390

Frontend

The Normalized State Shape

Storing entities by id to avoid duplication and keep updates consistent.

5 min read · core · beat Gold to climb

What it is

A normalized state shape stores data the way a relational database does: each entity type lives in a lookup table keyed by id, and relationships are expressed as ids rather than nested copies.

The pattern

  • Keep a byId map from id to entity.
  • Keep an allIds array to preserve order.
  • Reference related entities by their id, not by embedding them.

Why avoid nesting

If the same user is embedded inside many posts, updating that user means finding and editing every copy. Miss one and the UI shows stale data. With normalization the user exists once, so a single update is consistent everywhere.

  • No duplicated entities to keep in sync.
  • Updates are shallow and targeted.
  • Lookups by id are constant time.

Key idea

Normalize state into id keyed tables so each entity is stored once, making updates shallow, consistent, and free of duplicated data.

Check yourself

Answer to earn rating on the learn ladder.

1. What is the main risk of deeply nested duplicated entities?

2. What does a byId map provide?

3. How are relationships represented in normalized state?