Skip to content
tezvyn:
Menu

How would you structure a scalable store for interconnected domains?

Source: ngrx.ioMediumHow cards are made

Tests domain-driven state partitioning and cross-slice derived data. Strong answers use feature slices, normalized entities, and memoized selectors; keep computed state out of the store. Red flag: a monolithic state tree with component-level recomputation.

What's really being asked

This tests whether you can apply domain-driven design principles to client-side state management. The interviewer wants to see if you understand how to prevent a global store from becoming a tightly coupled monolith where every state change ripples unpredictably through unrelated domains. They are looking for awareness of normalization, selector composition, and the boundary between state and computed derivations.

The full answer

First, partition the store into domain-scoped slices such as users, products, and orders rather than mixing them into a single flat structure. Second, normalize state shape so that each slice owns its entities by ID and cross-domain references are stored as foreign keys, not nested objects. Third, use memoized selectors to compute cross-slice derived data; the selector layer is where you join users to orders or compute totals, keeping the store itself serializable and minimal. Fourth, keep computed or aggregate state out of the store to avoid synchronization bugs and redundant writes. Fifth, enforce unidirectional data flow where feature slices expose only their own actions and selectors, and shared selectors live in a thin orchestration layer.

The mistakes people make

A red flag is proposing a single monolithic state object with deeply nested domain data. Another is storing computed values like cart totals or filtered lists directly in state, which creates multiple sources of truth. Candidates who suggest that components should manually combine multiple observables or stores to build derived data are missing the selector abstraction and will trigger excessive re-renders. Similarly, normalizing everything but then denormalizing inside reducers or actions shows confusion about where derivation belongs.

What usually comes next

The interviewer may ask how you would handle a transaction that spans multiple domains, such as placing an order that must reserve inventory and update user loyalty points. They might also probe performance: how memoization works, how selector arity affects cache invalidation, or how to avoid selector recalculation when only unrelated slices change. Another follow-up is how to lazy-load feature stores in a micro-frontend or module federation context.

A concrete example

Suppose an order detail view needs the order, the product names, and the user profile. In a normalized store, the orders slice stores productIds and userId. A composed selector starts from the orders slice, then looks up products by ID from the products slice and the user from the users slice. The component receives a single denormalized view model from the selector without knowing the store structure. If the user edits their profile, only the users slice updates and the order selector for unrelated orders does not recompute because its input references remain stable.

Interview question

In a normalized store, an order detail view needs product names and user profiles alongside order data. Where should this cross-slice joining occur?

  • a.Pre-computed and stored as nested objects inside the orders slice
  • b.In the component, by manually combining separate observables for each slice
  • c.In a memoized selector that composes lookups across the orders, products, and users slicesCorrect
  • d.In the reducer, denormalizing the order slice whenever related entities change
Why?

Composed memoized selectors join normalized slices at read time, which keeps the store serializable and minimal while caching derived views. Denormalizing inside reducers is wrong because it couples domains and forces redundant state updates whenever referenced entities change.

Just read this? Test yourself on what you have been reading.

Read the original → ngrx.io

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on state-management — each one lists the topics its interview covers.

See open roles