Angular › State Management

What does it mean for state to be normalized, and why does this matter for larger Angular apps?

Intermediate

Answer

Normalized state stores related data, like users and their posts, as separate flat collections referenced by id, instead of deeply nesting one inside the other. This avoids duplicating the same data in multiple places and makes updating a single piece of information, like a user's name, much simpler and less error prone.
// Not normalized, user data is duplicated inside every post
const posts = [{ id: 1, author: { id: 5, name: 'Alice' } }];

// Normalized, user data lives in one place, referenced by id
const users = { 5: { name: 'Alice' } };
const posts = [{ id: 1, authorId: 5 }];
Real-world example A social media app switches from storing full user objects inside every single post to storing just a user id, avoiding the bug where updating a user's display name previously required updating dozens of duplicated copies across many posts.

Common follow-ups: How do you look up a user's full details from a normalized posts list?;What tools or libraries, like NgRx Entity, help manage normalized state more easily?