DEV Community

Cover image for State Management Is a Data Ownership Problem
Siddharth Pandey
Siddharth Pandey

Posted on

State Management Is a Data Ownership Problem

“Should we use Redux or Zustand?” sounds like a state management question.

Often, the unresolved questions are more basic: who owns this value, who can change it, how long should it live, and what should happen when two copies disagree?

A library gives you mechanisms for storing and updating data. It cannot decide which part of your system should be authoritative.

Start with the source of truth

Consider a product page with a price, a quantity selector, a delivery postcode, and an open accordion.

These values have different owners.

The server determines the current price. The user controls the quantity they intend to purchase. A delivery postcode may belong to the current checkout session. An accordion's open state can usually stay with the component that renders it.

Putting all four into one global store makes them equally accessible. It does not make their lifecycles or consistency requirements equal.

Before choosing a storage mechanism, describe the authority behind each value.

A cache is not a second authority

Suppose the server returns an order with status processing. The frontend caches it to avoid unnecessary requests.

That cache is a local representation of server state. It needs rules for freshness, invalidation, errors, and reconciliation. Treating it like ordinary editable UI state can leave the browser presenting a reality the server no longer recognizes.

After a mutation, choose a deliberate strategy: update the relevant cached result from the response, invalidate it and fetch again, or apply an optimistic change with rollback and reconciliation.

The appropriate choice depends on latency, failure behavior, and the consequences of displaying an incorrect value.

Copying the same response into a query cache and a separate application store creates another synchronization problem. Do it only when that second representation has a clear purpose and an explicit update policy.

Keep drafts separate from committed data

Editing a profile illustrates a different ownership boundary.

The persisted profile belongs to the server. The unsaved form belongs to the editing session. They may begin with the same values, but they are not the same state.

If a background refresh arrives while the user is typing, blindly resetting the form can erase their work. Never refreshing can hide a conflicting edit from another session.

Make the policy explicit. You might preserve dirty fields, warn about a newer version, or use a version token so the server can reject a stale write.

A form library can help track dirty fields. A store can distribute values. Neither decides what a conflict should mean for the product.

Derive values where possible

Stored state creates an obligation to keep it correct.

If a cart contains line items, a client-side item count can usually be derived:

const itemCount = items.reduce(
  (count, item) => count + item.quantity,
  0,
);
Enter fullscreen mode Exit fullscreen mode

Storing itemCount separately creates another value that every add, remove, and quantity update must maintain.

This does not mean all computed values belong in the browser. The amount charged may depend on server pricing, discounts, tax, and stock checks. A client calculation can be a preview while the server remains authoritative for the transaction.

Derivation reduces synchronization work only when it uses the correct inputs and respects the ownership boundary.

Match storage to lifecycle

A useful starting point is:

Kind of state Typical home Main question
Temporary interaction Component or nearby feature When should it reset?
Shareable navigation URL Should refresh or a copied link preserve it?
Remote resource Server-state cache How does it become fresh again?
Unsaved edit Form or editing session How are conflicts handled?
Cross-feature client workflow Shared store Who can transition it?

These are defaults, not laws. A sensitive value may not belong in a URL. An interaction may need to survive navigation. Let the requirements explain the exception.

Once ownership and lifecycle are clear, compare libraries against the mechanisms you need: subscriptions, debugging, persistence, transitions, or cache coordination.

The most useful state management design is one where developers can explain why a value exists, who can change it, and how it becomes correct again after failure. Pick the library after those answers.

Top comments (0)