Skip to content

State management at scale

Most frontend complexity is state: what the user is looking at, what they’ve typed, what came from the server, what’s loading, and what’s out of date. Small apps survive putting it all in one place. Large apps, with many teams and screens, slow down and break in confusing ways unless each kind of state has a clear home.

The most useful step is recognizing that “state” is several different things with different owners.

Kinds of state and where each lives1. Data owned by the server is fetched into a cache that tracks freshness and refetches. 2. What the user is viewing lives in the URL, so it can be shared, bookmarked and restored, and keys the cache. 3. Transient UI and form state stays in the component that uses it. 4. Only genuinely app-wide client state, such as the session and preferences, goes in a global store. Server stateorders, profiles, prices Query cachefetch, cache, refetch URL statefilters, page, selection Local UI stateopen, hovered, editing Form statedrafts, validation Shared client statesession, preferences1keyed by234
Kinds of state and where each lives Server data belongs in a cache that knows it can go stale; the rest stays as close as possible to where it is used.
  1. Data owned by the server is fetched into a cache that tracks freshness and refetches.
  2. What the user is viewing lives in the URL, so it can be shared, bookmarked and restored, and keys the cache.
  3. Transient UI and form state stays in the component that uses it.
  4. Only genuinely app-wide client state, such as the session and preferences, goes in a global store.
Kind Examples Best home
Server state Orders, account details, product data A server-state cache such as TanStack Query (opens in a new tab), SWR, RTK Query or Apollo Client
URL state Search terms, filters, current page, selected item The URL (path and query string)
Local UI state Is the menu open, which tab is active The component
Form state Field values, validation errors, dirty flags A form library or the form component
Shared client state Signed-in user, theme, feature flags, a shopping cart before checkout A small global store or context

Most “global state” in large apps is really a copy of server data, and copies go stale. A server-state cache handles what hand-written stores get wrong: deduplicating requests, caching by key, refetching when data may have changed, retrying, pagination, optimistic updates, and invalidating related queries after a change. Moving server data out of a global store and into a query cache usually removes most of the store.

  • Keep state as close as possible to where it’s used. Lift it up only when two parts of the UI need it.
  • Derive, don’t duplicate. Compute totals and filtered lists from source state instead of storing them separately.
  • Put shareable state in the URL. If a user would expect a link or the back button to restore it, it belongs in the URL.
  • One owner per piece of state, and clear boundaries between teams. In micro-frontends, each one owns its own state and shares only through explicit contracts such as URL, events or a small shell API.
  • Design optimistic updates with rollback. Show the change immediately, and undo it clearly if the server rejects it.
  • One giant global store holding server data, UI flags and form drafts, where every change re-renders half the app.
  • Stale data after a mutation because nothing invalidated the cached queries.
  • Filters that reset on refresh because they weren’t in the URL.
  • Micro-frontends sharing a global store, which couples teams as tightly as a monolith.

Written and edited by Abhinav Taduka, enterprise software architect.