Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Frontend System Design Fundamentals
  1. 1.Introduction to Frontend System Design
  2. 2.Core Frontend Architecture Concepts
  3. 3.Client-Server Interaction Fundamentals
  4. 4.Basic Performance & Accessibility Considerations
  5. 5.State Management Basics & Data Flow
  6. 6.Advanced State Management & Global Stores
  7. 7.Component Libraries & Design Systems
  8. 8.Frontend Build Tools & Development Workflows
  9. 9.Advanced Performance Optimization Techniques
  10. 10.Data Fetching Strategies & Caching
  11. 11.Frontend Security Essentials
  12. 12.Micro-Frontend Architectures
  13. 13.Real-time Communication & WebSockets
  14. 14.Observability, Monitoring, & Logging
  15. 15.Offline-First & Progressive Web Apps (PWAs)
Frontend System Design Fundamentals
06

Frontend System Design · Lesson 6 of 15 · 5 min

Advanced State Management & Global Stores

In an interview, this is where you show you can think about architecture, trade-offs, and how to keep a large app from turning into a mess.

After this, you'll be able to justify your choice of state management library in an interview and explain the trade-offs between a global store, local state, and server cache. You won't just name libraries; you'll articulate a strategy.

When to reach for a global store

You need a global store when passing props through components that don't use them becomes painful. This is called "prop drilling," and it's a code smell. It couples components that should be independent and makes refactoring a nightmare.

A global store decouples components by providing a central place for state. Instead of passing data down, components connect directly to the store to get the data they need.

The trap: Don't put everything in the global store. A bloated store is just as bad as prop drilling. State belongs in a global store only if it's truly global—data that many disconnected parts of the UI need to read or update.

Good candidates for a global store:

  • User authentication status
  • Site-wide settings like theme or language
  • A shopping cart

Bad candidates:

  • Control state for a single dropdown menu (isOpen)
  • The value of a form input
  • Data fetched from an API that's only displayed in one place

How to choose the right tool

There is no single best tool. The correct answer in an interview is always about the trade-offs for a given scenario. Your job is to know the menu of options and their costs.

Option 1: React Context

Use Context for low-frequency updates of simple, global data. Think theme, user object, or internationalization config. It's built into React, so there's no library to add.

The major drawback is performance. When the context value changes, every component that consumes that context re-renders, even if it only uses a part of the data that didn't change. For a context holding a large object with frequent updates, this can kill your app's performance.

Option 2: Redux (via Redux Toolkit)

Redux was the classic solution for complex state. Today, you should only consider it using Redux Toolkit (RTK), which removes most of the historical boilerplate.

Its strength is its strict, opinionated structure: a single store, immutable updates via reducers, and a rich middleware ecosystem. This predictability is valuable for very large applications with many developers. The Redux DevTools, with time-travel debugging, are unmatched for complex bug hunts.

The cost is ceremony. Even with RTK, it's more verbose than other options. It's overkill for most small to medium apps.

Option 3: Atomic Stores (Zustand, Jotai)

This is the modern default for many projects. Libraries like Zustand and Jotai treat state as a collection of "atomic" pieces. Components subscribe only to the specific atoms or slices of state they need.

This solves the performance problem of React Context. If one piece of state updates, only the components subscribed to that exact piece will re-render. They offer 80% of Redux's power with 20% of the boilerplate.

Zustand is particularly simple, using a hook-based API that feels like a global useState.

A practical example with Zustand

Zustand shows how a modern store provides state and actions with minimal code. It also makes selective subscriptions, the key to performance, obvious.

This code creates a store for a simple counter. Notice how the components select only the state they need.

import { create } from 'zustand';

interface CounterState {
  count: number;
  increment: () => void;
  decrement: () => void;
}

const useCounterStore = create<CounterState>((set) => ({
  count: 0,
  increment: () => set((state) => ({ count: state.count + 1 })),
  decrement: () => set((state) => ({ count: state.count - 1 })),
}));

// This component only cares about the count.
// It will only re-render when `count` changes.
const CounterDisplay = () => {
  const count = useCounterStore((state) => state.count);
  return <h1>Count: {count}</h1>;
};

// This component only cares about the actions.
// It will *not* re-render when `count` changes.
const CounterControls = () => {
  const { increment, decrement } = useCounterStore();
  return (
    <div>
      <button onClick={increment}>+</button>
      <button onClick={decrement}>-</button>
    </div>
  );
};

The function you pass to the hook, (state) => state.count, is a selector. It tells the library you are only interested in that specific value. This is the mechanism that prevents unnecessary re-renders and makes atomic stores more performant than a naive Context implementation.

How to answer "Design our state management"

This question tests your architectural thinking. Don't just name a library. Break the problem down first.

You're building a large e-commerce app. How would you manage state for the user's session, the shopping cart, and the product list?

Your answer should follow this structure:

  1. Categorize the state. Show you understand that not all state is the same.

    • Global State: Data needed across many components (user auth, cart contents).
    • Server Cache: Data that lives on the server and is just cached on the client (product lists, user profiles). This is a distinct category.
    • Local UI State: State for a single component (is a modal open, a form input's value).
  2. Assign tools to categories.

    • "For global state like the cart and auth status, I'd use a lightweight atomic store like Zustand. It's simple, performant, and avoids the re-render issues of Context."
    • "For server cache like product data, I would not put it in a global store. I'd use a dedicated data-fetching library like React Query or SWR. They handle caching, re-fetching, and invalidation automatically, which a global store doesn't."
    • "For local UI state, I'd stick with React's built-in useState and useReducer. It's the simplest tool for the job and keeps component logic self-contained."
  3. Justify the trade-offs.

    • "This approach avoids bloating a global store with server data, which is a common mistake. It also uses the simplest effective tool for each job, keeping developer overhead low while ensuring performance by using selectors for global state and dedicated hooks for local state."

This layered answer shows you think about the problem from first principles instead of just reaching for your favorite tool.

Try it

Find a small personal project or create a new one with a parent, child, and grandchild component. Pass a prop from the top all the way to the bottom. Now, refactor it to use a simple Zustand store. The intermediate component should no longer have any knowledge of that prop. This should take about 15 minutes.

Next: Now that your data flow is clean, we'll focus on making the components themselves efficient and reusable in Component Libraries & Design Systems.

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

State Management Basics & Data Flow

Next

Component Libraries & Design Systems