Speeding Up a Cold Storefront Page and a 10M-Row Browser Table
System DesignModel answerLast updated
Audit and cut a 5-second cold-cache load on a retail landing page, then design a browser table that can browse 10 million API records without freezing or crashing.
Part 1: A slow first visit
A content-heavy retail landing page takes about 5 seconds to become usable when a visitor opens it in a private window with an empty cache. You are asked to bring that number down.
- Describe how you would investigate where the time goes before changing anything.
- Explain how you would shorten the critical rendering path and prioritize resources.
- Compare splitting JavaScript into chunks with preloading resources, and say when each one helps or hurts.
Part 2: Ten million rows in one table
A web app has to present 10 million records, retrieved from an API, in a single table.
- Explain what goes wrong if you fetch everything and render it directly into the DOM.
- Propose an architecture that lets users explore the data without crashing the tab or making the UI stutter.
Your answer should cover:
- Memory limits of a browser tab running V8.
- How virtualization (windowing) works and how you would build it.
- Fetching strategy: offset pagination, infinite scroll, or cursor-based loading, with trade-offs.
- How to keep the table accessible to keyboard and screen-reader users while rows are virtualized.
Also be ready to say briefly how JavaScript's single-threaded model and event loop affect both parts.
Hints
Hint 1
Start by measuring: split the 5 seconds into network time, first paint, and main-thread work, and find which phase dominates before choosing fixes.
Hint 2
For Part 1, think about what blocks painting (CSS, synchronous scripts), what the browser discovers late (hero image, fonts), and what keeps the main thread busy (bundle execution, hydration, third-party tags).
Hint 3
For Part 2, do the arithmetic: records times bytes per record for the heap, rows times cells for DOM nodes, and rows times row height for scroll height. Then design so that only a constant number of rows and a bounded cache ever exist at once.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Part 1: Cold-load performance
Measure first
Reproduce the problem under controlled conditions: DevTools Performance panel or Lighthouse/WebPageTest with the cache disabled, 4x CPU throttling and a Fast 4G profile. Split the 5 seconds into phases:
- Network: DNS, TLS, TTFB, and the request waterfall.
- Rendering: First Contentful Paint and Largest Contentful Paint.
- Main thread: long tasks over 50 ms from parsing, compiling, executing and hydrating JavaScript.
Lighthouse no longer reports TTI, so use Total Blocking Time in the lab and Interaction to Next Paint in the field as proxies. Most slow cold loads come from one of three things: a slow origin or missing CDN, render-blocking resources found late, or a large JS bundle that monopolizes the main thread.
Shorten the critical rendering path
- CSS blocks rendering. Inline the critical above-the-fold CSS (around 14 KB, so it fits in the first round trip) and load the remainder asynchronously.
- Synchronous scripts block the parser. Use
deferfor application code (order preserved, runs after parsing) andasyncfor independent scripts such as analytics. Push third-party tags behind consent or idle time. - Send useful HTML immediately. Server-render or statically generate the page, and stream HTML so the head flushes before slow data queries complete.
Prioritize resources
preconnectto the CDN and image host; use HTTP/2 or HTTP/3 and Brotli.- Mark the hero (LCP) image
fetchpriority="high", never lazy-load it, and serve responsive AVIF/WebP. Lazy-load below-the-fold images with explicit dimensions to prevent layout shift. - Preload only one or two critical fonts, subset them, and use
font-display: swap. - Defer chat widgets, A/B tools and tag managers; on retail pages they often account for 30-50% of main-thread time.
Reduce main-thread work
Tree-shake, drop unneeded polyfills and swap heavy libraries for lighter ones. Cut hydration cost with islands, progressive hydration or server components so static product content ships no JS. Break long tasks up (yield to the event loop) because interactivity depends on a free main thread, not just on bytes arriving.
Code splitting vs. preloading
| Code splitting | Preloading | |
|---|---|---|
| Benefit | Smaller initial bundle, less parse and execute work | Starts fetching late-discovered resources early |
| Cost | Chunk waterfalls; a delay the first time a split feature is used | Competes for bandwidth with critical assets; wasted bytes if unused |
| Best for | Routes and below-the-fold features (reviews, carousel, checkout) | Fonts, the LCP image, the current route's chunk |
Combine them: split by route and interaction, modulepreload chunks the current route certainly needs, and prefetch likely-next chunks at idle priority (for example on hover over "Add to cart"). Preloading everything recreates the monolith.
Part 2: 10 million rows
Why direct rendering fails
- Heap: a tab's V8 heap is capped in the low gigabytes (about 4 GB with pointer compression). At 100-300 bytes per object, 10M records is 1-3 GB before any UI, and parsing one giant JSON response holds the raw string and the parsed tree at once. The result is "Aw, Snap" crashes and GC pauses of hundreds of milliseconds.
- DOM: 10M rows times 5 cells is over 60M nodes. At hundreds of bytes to 1 KB each (with style and layout data) that is tens of GB, and every style recalculation or layout scales with node count.
- Main thread:
JSON.parse, node creation and first layout become huge long tasks. Because JavaScript runs on a single thread driven by the event loop, input, scrolling and painting all wait. - Element height limits: 10M rows at 30 px is 300M px, while Chrome caps element height near 33.5M px and Firefox near 17.9M px.
Architecture
1. Virtualization. Render only visible rows plus a small overscan (roughly 30-60 rows), so DOM size is constant. Recycle row elements on scroll and position them with transform: translateY() so movement is composited rather than relaid out. Prefer fixed row heights; variable heights need a measurement cache and a prefix-sum index. Apply contain: strict to the viewport to limit style, layout and paint scope.
2. Bounded data in memory. Keep a sparse page cache (a Map keyed by page) with LRU eviction so only a few thousand rows are resident. Parse and normalize in a Web Worker, using columnar or typed-array layouts transferred as ArrayBuffer, to cut heap use and keep parsing off the main thread.
3. Scaled scrolling. When total height exceeds the browser limit, map scrollbar position to a row index with a scale factor, or draw a custom scrollbar.
Fetching strategy
- Offset pagination allows jumping to row 7,500,000, but
OFFSET nis O(n) in the database and results drift if rows are inserted. - Infinite scroll suits feeds; for a table the scrollbar becomes meaningless and users cannot reach the end.
- Cursor (keyset) pagination (
WHERE id > :last ORDER BY id LIMIT 500) is O(log n) with an index and stable under writes, but cannot jump to arbitrary positions.
Recommended: cursor-based fetching tied to the virtual window, prefetching one page ahead in the scroll direction, with a server-provided total count. For random jumps, add an index-based seek endpoint (or approximate jump by key range). Cancel stale requests with AbortController, and push sorting, filtering and search to the server since the client never holds all rows.
Accessibility
Virtualization removes rows from the DOM, which assistive technology cannot see, so compensate:
- Use
role="grid"ortablesemantics witharia-rowcountset to the true total andaria-rowindexon each rendered row, so screen readers announce "row 7,500,000 of 10,000,000". - Keep focus management in code: arrow keys, PageUp/PageDown, Home/End move a logical active cell, scrolling it into view and rendering it before focusing. Never let the focused row be recycled away.
- Use a roving
tabindexso the table is a single tab stop. - Provide non-scroll navigation (go-to-row, search, filters) and an
aria-liveregion for loading states. - Do not rely on native find-in-page; offer in-app search.
Common mistakes
- Reaching for
React.memoor debouncing before addressing the node count. - Rendering all rows with
content-visibilityalone, which still leaves the data and node creation costs. - Using offset pagination at depth, or forgetting that the focused row must stay mounted.
- Ignoring the browser element height cap.
- Preloading everything in Part 1, and quoting TTI without noting current metrics.