FSD Frontend System Design

Part III — The Speed · Lesson 6.3

Session Storage

In one lineSame API as localStorage, but the data dies when the tab does — and never leaves that tab.

Where you've seen itA multi-step application form open in two tabs for two different people, with neither overwriting the other.

  • Time11 min
  • DiagramTab lifetime and isolation boundaries
  • Chapter6 · Database & Caching

Diagram

diagram
diagram

How it works

  1. Identical API to localStorage — setItem, getItem, removeItem, clear, strings only, ~5MB.
  2. Scope is the tab plus the origin. A duplicated tab starts with a copy, then diverges.
  3. The storage event does not fire across tabs, because there's nothing shared to notify about.
  4. Survives reloads and in-tab navigation, which makes it right for multi-page flows.
js
// step 2 of a wizard survives a refresh, but not a new tab
sessionStorage.setItem('claim:draft', JSON.stringify(form));

// on mount
const draft = JSON.parse(sessionStorage.getItem('claim:draft') ?? 'null');

Trade-offs

Use sessionStorageUse localStorage
Multi-step form draftsTheme and locale
Scroll position for this visitDismissed banners
Per-tab UI state (open panel)Feature-flag overrides
Anything that must not leak between tabsAnything that should persist

A note on tokens: sessionStorage is sometimes recommended for tokens "because it expires". It doesn't expire — it just ends with the tab, and it's equally readable by XSS. The reasoning in 3.5 still applies: prefer HttpOnly cookies.

Interview angle

"Session storage or local storage for a checkout flow?"

  • sessionStorage: the draft is meaningful only for this attempt, and two tabs must not overwrite each other.
  • It survives an accidental refresh, which is the actual failure users hit.
  • Anything that must outlive the tab — a saved cart — belongs on the server, keyed to the user.

Recap

  • Tab-scoped, origin-scoped, dies on close, copied on tab duplication.
  • Right for wizards, drafts, and per-tab UI state.
  • No cross-tab storage event, because nothing is shared.