Frontend System Design · Lesson 30 of 86 · 4 min
State Patterns: Redux, Zustand and Context
This lesson is about justifying your choice of state manager in an interview, not just listing its features.
After this, you'll be able to explain the specific trade-offs between Context, Zustand, and Redux for a given system design problem. You'll know which tool to reach for and how to defend that choice.
When to use React Context (and when not to)
Use React's built-in Context for global state that changes infrequently. Think theme (light/dark mode), user authentication status, or language preference. Its purpose is to avoid "prop drilling"—passing props down through many layers of components.
It is not a general-purpose state management library.
The trap: Proposing Context for anything that updates frequently, like form state or notifications. When a context's value updates, every component that consumes it re-renders. If your context holds a large object, a change to any single property triggers a cascade of re-renders across your app, even in components that don't use that specific property. This is a common source of performance problems.
An interviewer might ask you to design a "toast" notification system. If you suggest Context, they will immediately ask about performance when multiple notifications are rapidly added and removed. A better answer involves a tool designed for frequent updates.
If you must use Context for slightly more dynamic data, split it into multiple, smaller providers. A ThemeProvider and an AuthProvider are better than a single AppProvider holding both theme and user objects. This limits the blast radius of re-renders.
Choosing a centralized store: Redux vs. Zustand
When state updates are frequent or complex, you need a centralized store. This pattern moves state logic out of your components into a single, global location. Both Redux and Zustand follow this model.
The data flow is a predictable loop: a component dispatches an action, the store runs logic to produce a new state, and then the store notifies subscribed components to re-render with the new data.
Zustand is the modern, lightweight default. It's minimal, fast, and unopinionated. Its key advantage over a naive Context implementation is selective subscription. Components can subscribe to specific slices of the store, so they only re-render when the data they actually care about changes.
This is what that looks like. Notice the selector function (state) => state.count. This component will only re-render when count changes, not when other properties in the store change.
import { create } from 'zustand';
// 1. Define the store
interface CounterState {
count: number;
increment: () => void;
}
export const useCounterStore = create<CounterState>((set) => ({
count: 0,
increment: () => set((state) => ({ count: state.count + 1 })),
}));
// 2. Use it in a component with a selector
function CounterDisplay() {
const count = useCounterStore((state) => state.count);
return <h1>Count: {count}</h1>;
}
Redux is the heavy-duty tool for managing complexity at scale. You should reach for Redux when you have a large, complex state tree with many interdependencies, or when working on a large team that benefits from its strict, opinionated structure.
Its value comes from predictability and tooling. The unidirectional data flow, middleware for side effects (like API calls), and unparalleled Redux DevTools (which allow for time-travel debugging) are invaluable for diagnosing issues in complex applications.
The trap: Talking about "Redux" without mentioning Redux Toolkit (RTK). RTK is the modern standard. It eliminates the boilerplate (action types, creators, switch statements) that gave classic Redux its reputation for being verbose. If you're discussing Redux in an interview, you should be discussing RTK.
How to articulate the trade-offs
In a system design interview, you'll be given a problem and asked for a technical approach. Your choice of state manager reveals your understanding of complexity, performance, and team dynamics.
Frame your answer around the problem's specific constraints.
Scenario: "Design a settings panel for user preferences."
Your answer: "I'd use React Context. The data (theme, language) changes infrequently, triggered only by explicit user action. The main goal is to avoid prop drilling, and the performance cost is negligible. A full-blown state library would be over-engineering."
Scenario: "Design a shopping cart."
Your answer: "Zustand is a great fit here. The cart state (items, quantities, total) updates frequently as the user shops. We need efficient re-renders; for example, the mini-cart icon in the header should update without re-rendering the entire page. Zustand's selective subscriptions handle this perfectly with minimal boilerplate."
Scenario: "Design a collaborative document editor like Google Docs."
Your answer: "This is a case for Redux. The application state is highly complex and interconnected: document content, user cursors, comments, and real-time collaboration events. Redux's strict, predictable flow and powerful middleware are essential for managing this complexity. The time-travel debugging capabilities of Redux DevTools would be critical for tracking down bugs in such a state-intensive application."
What an interviewer is listening for is not "Redux is best," but "For this specific problem, I'd choose X because its strengths align with the core challenges A and B, while avoiding the drawbacks of Y and Z." It demonstrates mature engineering judgment.
Try it
Implement a simple "toast" notification system. Create a global store that holds an array of notification objects. One component should have a button to add a new notification to the array. A separate NotificationContainer component should render the list and automatically remove notifications after 3 seconds.
Build it with Zustand first. Then, consider how you would build it with Context. What specific performance problem would you anticipate with the Context approach as you add and remove notifications rapidly?
Next: We'll cover how to handle the data that populates these stores in Data Fetching: React Query and SWR.
Lock it in — apply this lesson under interview conditions.