State management tradeoffs

Server state (React Query/SWR) vs client state (Zustand/Redux) vs URL state. "Where does this state live?" is the frontend design question.

About 30 min read3-question knowledge check

The mental model

Most frontend state bugs and most bloated state libraries come from one unasked question: where should this state live? The answer is almost never "in a global store" by default. The single most useful reframing in modern frontend is that "state" is not one thing — it is at least four different kinds of state with different owners, and the design job is routing each piece to its correct home rather than dumping everything into one bucket.

The four kinds:

  • Server state — data that lives on a server and you cache a copy of on the client: the user's profile, a list of orders, search results. Its defining property is that it is a cache of something you do not own, so it can be stale, needs refetching, deduplication, and invalidation. This is 80% of the "state" in a typical data app, and it is the piece people wrongly put in Redux.
  • Client/UI state — data that only the client knows and owns: is this modal open, which tab is selected, the contents of a form in progress, a theme preference. It never came from a server and has no "stale".
  • URL state — data that belongs in the address bar because it should be shareable, bookmarkable, and survive a refresh: the current page, a search query, active filters, a selected item id.
  • Form state — a special case of client state with its own concerns (validation, dirty/touched tracking, submission) big enough to warrant dedicated tools.

The analogy that sticks: state management is filing, not hoarding. A good office does not keep every document in one giant central cabinet — customer records live in the CRM (server state, someone else's system of record), the note on your desk stays on your desk (UI state), the meeting-room booking is on the shared calendar everyone can link to (URL state). Putting the sticky note in the central customer database, or the customer records in your desk drawer, is exactly the mis-filing that a "just use Redux for everything" architecture produces.

What breaks without this model: teams cache server data in a global store and then hand-write the refetch/dedup/invalidation logic a library gives free (the most common source of stale-data and race-condition bugs); they store isModalOpen globally and cause the whole app to re-render on every toggle; they keep the search query in component state so a shared link opens an empty search; and they reach for a heavyweight store on day one for state that a single useState two components up would hold. "Where does this state live?" is the frontend system-design question, and answering it well makes most state-management libraries optional.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision