Storing nested/relational API data as-is in Redux forces every reducer touching it to deep-clone deeply nested structures on every update, and makes 'find this one item and update it' an O(n) tree walk, normalizing into { ids: [], entities: {} } turns both problems into O(1) object-key lookups, at the cost of needing selectors to reassemble relational views.
You are viewing the 40% free preview. Upgrade to DeepFrontend Pro to unlock the complete 25-minute masterclass, live interactive engines, and staff-level interview loops.
โUnder the Hood: Deep architectural internals & edge cases
โInterview Q&A: Senior/Staff model answers & red flags
A typical API response is nested and relational: a post has an author object, which has its own fields; a post has an array of comments, each with its own author. Storing that shape directly in Redux state, as-is, causes two concrete problems.
Problem 1, updating one nested field requires deep-cloning the whole path. Renaming Ada from every post she authored means walking the entire posts array, finding every match, and rebuilding each one immutably (per the no-mutation rule from Actions & Reducers), an O(n) scan, with deeply nested spread logic.
Problem 2, the same author data is duplicated across every post/comment that references it. Ada's { id: 10, name: "Ada" } object appears wherever she's referenced; updating her name in one place doesn't update it anywhere else unless every duplicate is found and rewritten too.
This is exactly the shape a relational database would use, separate tables, joined by foreign-key-style IDs, instead of nested/duplicated objects. Each "table" (posts, authors, comments) is itself { ids: [...], entities: { [id]: {...} } }: ids is an ordered array (for list rendering), entities is a lookup object keyed by ID (for O(1) direct access).
Renaming Ada is now a single, O(1) update, no scanning, no nested spreading:
function authorsReducer(state, action) { if (action.type === "author/renamed") { const { id, name } = action.payload; return { ...state, entities: { ...state.entities, [id]: { ...state.entities[id], name } }, // ONE entity touched }; } return state;}
Every post and comment referencing author 10 automatically reflects the update, because they only ever stored the ID, 10, never a duplicated copy of the name.
Finding a specific item by ID is O(1), state.posts.entities[42], instead of state.posts.find(p => p.id === 42), an O(n) scan through a potentially large array, repeated every time any component needs that one post.
The tradeoff: reassembling relational views needs selectors#
const selectPostWithAuthor = createSelector( [(state, postId) => state.posts.entities[postId], (state) => state.authors.entities], (post, authors) => ({ ...post, author: authors[post.author] }) // re-attach the FULL author object for rendering);
Normalization pushes the "reassemble the nested shape a component actually wants to render" work into selectors, exactly the memoized-selector pattern from Selectors & Reselect. This is a deliberate tradeoff: the store stays flat and update-cheap, and the (memoized, so not repeated needlessly) cost of reconstructing a nested view is paid only where it's actually needed for rendering.