Skip to the page

State management · mid

Where state lives: signal services and large app design

Sort state by kind, then give each kind one home. A root service with signals covers most apps.

The notes

What you must know

  • Kinds of state: server data, shared client state (cart, user, filters), local UI state, URL state (filters in query params), form state.
  • A service with signals: a private writable signal, public read-only signals and computed, and methods that change state.
  • Example cart store: private readonly state = signal<CartState>({ items: [] }), items = computed(() => this.state().items), plus count and total computed.
  • Keep money in paise (integers) to avoid floating-point errors.
  • Server data: resources or HttpClient with caching per feature.
  • Session state (user, permissions, feature flags): root signal services or a root Signal Store.
  • Feature state: route-scoped stores via route providers, destroyed when the user leaves. Local state stays in the component.
  • NgRx is needed when many teams, strict traceability or complex workflows need it. It is not the default answer.

The red pen

Common traps: mistake → fix

  • Mistake: Every app needs NgRx

    Fix: sort the state first; many apps need only services with signals.

  • Mistake: Put all state in one global store

    Fix: feature and local state belongs close to where it is used.

Easy to hard

Questions interviewers ask, easy to hard

  1. Do you need NgRx?
  2. How would you build a cart store with signals?
  3. Design state for a large enterprise portal.
  4. Where should filter state live?

Practise

Practise with these questions

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview