FSD Frontend System Design

Part III β€” The Speed

6 Database & Caching

GoalDecide what to store, where to store it, and how long it stays valid.

  1. 6.1 Database & Caching Overview The browser has five storage tiers β€” pick by size, lifetime, and who else needs to read it. Storage tier stack with size, lifetime, and access cost Β· 14 min
  2. 6.2 Local Storage Five megabytes of persistent strings, read and written synchronously on the main thread. Key-value box with limits and the sync-blocking cost Β· 12 min
  3. 6.3 Session Storage Same API as localStorage, but the data dies when the tab does β€” and never leaves that tab. Tab lifetime and isolation boundaries Β· 11 min
  4. 6.4 Cookie Storage Four kilobytes that ride along on every single request β€” which is both the feature and the cost. Request carrying cookies + the attribute matrix Β· 14 min
  5. 6.5 Indexed DB An asynchronous, transactional, indexed store for hundreds of megabytes of structured data. Object store schema with indexes + async transaction flow Β· 16 min
  6. 6.6 Normalization Store every entity once, by id, and reference it everywhere else β€” duplicates are bugs waiting to happen. Nested vs normalized shape, and the update that breaks one of them Β· 15 min
  7. 6.7 HTTP Caching Two headers decide whether a request happens at all, and whether it costs a full download. Cache decision flowchart + fresh vs revalidate Β· 17 min
  8. 6.8 Service Worker Caching A programmable proxy inside the browser β€” you write the cache policy in JavaScript. Intercept flow + the five caching strategies Β· 17 min
  9. 6.9 API Caching Cache responses by key in the client, then decide the one hard thing: when they stop being true. Cache key lifecycle + invalidation triggers Β· 16 min
  10. 6.1 State Management Sort state by who owns it β€” server, URL, or client β€” and most of the hard problem disappears. State ownership map + the scope ladder Β· 17 min

Capstone

Design the full caching strategy for a news feed that must open instantly, work offline, and never show a deleted article.