Front-End Design: Scalable Product Search with Unbounded Results
System DesignModel answerLast updated
Design the component tree and performance strategy for a search-driven product grid that must handle an arbitrarily large catalog.
Product Search Page — Front-End System Design
You are building the front end for an e-commerce search experience. At the top of the page sits a text input. Below it, a grid of product cards updates to reflect the user's current search term. The underlying catalog has no practical size limit, so any given query could return thousands of matching products.
Your interviewer wants two things from you:
- The component hierarchy — what components exist, what each one is responsible for, and where shared state lives.
- A performance strategy — how you keep the experience fast and correct as the user types, given that the full result set can never be held in the browser at once.
This is a design discussion, not a coding exercise. Lead with the decisions that matter most and explain your trade-offs.
Before You Design — Clarify These
State your assumptions if answers are not given:
- Do results update on every keystroke, or only on an explicit submit (Enter / button click)?
- Does a search API already exist? Does it return paginated results, a total count, and support cursor- or offset-based paging?
- What does a product card display — image, name, price, rating?
- Do you use infinite scroll or numbered pagination?
- Should the search term appear in the URL so the page can be bookmarked and shared?
- Which devices and network conditions are in scope (mobile on 4G, desktop on broadband)?
Part 1 — Component Tree and State Ownership
Describe the component hierarchy. For each component, state what it renders and what state or props it owns. Cover:
- How the search term and the current results flow through the tree
- Where loading, empty-results, and error states live and how they are displayed without causing layout shifts
- How the active query stays in sync with the URL
Part 2 — Keeping Results Fast for an Unbounded Catalog
Explain how you make the grid feel responsive after each keystroke when the result set can be arbitrarily large. Cover:
- How you control the number of outgoing requests and handle responses that arrive out of order
- Whether and how you cache results, and when the cache is invalid
- How you page through results and limit rendering cost as the user scrolls or pages forward
- What requirements you place on the backend search API to make all of this work
Hints
Hint 1
Start with clarifying questions — whether results update on every keystroke versus on submit changes almost every decision that follows, especially how aggressively you debounce and how you handle stale responses.
Hint 2
For Part 1, find a single component that owns the query string, the current result page, and the request status. Everything else should be a pure consumer. Ask yourself: if two sibling components both need the search term, where does it live?
Hint 3
For Part 2, think in three layers — client (debounce, cancel stale requests, in-memory cache), network (CDN-cacheable API responses, connection reuse), and server (inverted index, pre-computed relevance scores). A complete answer touches all three and names a trade-off for each technique.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Clarifying Questions First
A strong answer opens with assumptions stated out loud. Reasonable defaults:
- Results update as the user types (live search), not only on submit.
- The backend exposes a paginated search endpoint:
GET /search?q=&page=&pageSize=returning{ items, totalCount, nextCursor }. - Each card shows a thumbnail, product name, and price.
- Infinite scroll on mobile; numbered pagination is also acceptable on desktop.
- The query lives in the URL (
?q=shoes&page=2) so results survive a page refresh and can be shared.
State these up front rather than waiting to be asked — it shows you know what decisions depend on them.
Part 1 — Component Tree and State Ownership
Hierarchy
<SearchPage> ← owns: query, page/cursor, results, status
<SearchBar> ← controlled input, fires onQueryChange
<ResultsRegion> ← receives results + status as props
<StatusBanner> ← renders loading / error / empty-state
<ProductGrid> ← receives items[], renders rows
<ProductCard> ← pure, renders one item
<PaginationControls> ← receives totalCount + currentPage
SearchPage is the single source of truth. It holds:
query: string— the current search term, mirrored to?q=in the URL viahistory.replaceState(or the router's equivalent).page: number(orcursor: string) — current position in the result set.results: Product[]— the current page of items.status: 'idle' | 'loading' | 'success' | 'error'— drives what the region displays.
SearchBar is fully controlled. It reads query from props and fires onQueryChange(value) on every keystroke. It owns no state of its own.
ResultsRegion is a layout shell. When status === 'loading', it shows skeleton cards at fixed dimensions rather than a spinner — this prevents the grid from collapsing and re-expanding, eliminating layout shift (important for CLS).
ProductCard is a pure component. Memoize it (React.memo or equivalent) so a new fetch for page 2 does not re-render page 1 cards that are already on screen.
URL Sync
Mirror query and page into the URL on every change. Use replaceState while the user is typing (to avoid polluting history), and pushState when the user navigates to a new page number. This makes the Back button work correctly and lets users share links.
Part 2 — Performance Strategy
Control Request Volume — Debounce + Abort
With live search, a user typing "running shoes" produces 13 keystrokes. Sending 13 requests is wasteful and creates a race condition where a slow response for "r" could overwrite the correct response for "running shoes".
Debounce the query: wait 200–300 ms of silence before firing a request. This cuts traffic by ~10× for a typical typing speed.
Cancel stale requests: every time a new request goes out, abort the previous one using AbortController. This is more reliable than "only show the response if the query still matches", because it also frees network resources.
const controller = useRef(null);
function fetchResults(query, page) {
controller.current?.abort();
controller.current = new AbortController();
fetch(`/search?q=${encodeURIComponent(query)}&page=${page}`, {
signal: controller.current.signal,
})
.then(r => r.json())
.then(data => setResults(data))
.catch(err => { if (err.name !== 'AbortError') setStatus('error'); });
}
Common mistake: checking if (responseQuery === currentQuery) instead of aborting — this still wastes bandwidth and can cause subtle flicker.
Caching
Store results in a Map keyed by ${query}::${page}. On a cache hit, render immediately, then optionally revalidate in the background (stale-while-revalidate). Libraries like TanStack Query do this out of the box.
Cache invalidation rules:
- Invalidate after a configurable TTL (e.g., 60 s) if the catalog changes frequently.
- For a read-heavy catalog that changes infrequently, set
Cache-Control: public, max-age=60on the API response and let the CDN cache it. This reduces origin load dramatically for popular queries.
Paging and Rendering Cost
Never load the entire result set. A page of 24–48 items is a reasonable default. Two strategies for navigating large result sets:
Numbered pagination: simple, URL-friendly, predictable. Works well when users want to jump to page 10.
Infinite scroll with a virtual list: as the user scrolls, fetch the next page and append items. Use a virtualized list (e.g., react-window) so only the ~20 cards in the viewport are in the DOM — critical when results run into the hundreds of items. Without virtualization, DOM size and memory grow linearly and scrolling becomes janky.
Images: lazy-load card images using loading="lazy" or an IntersectionObserver. Serve correctly sized images via a CDN image transformation service (e.g., ?w=300&format=webp) to avoid sending a 2 MB hero image into a 150 px thumbnail.
Backend Requirements
The client strategy only works if the API provides:
- Offset or cursor pagination — without it you cannot request a specific page.
totalCount— needed to render "Showing 1–24 of 4,832 results" and to know when there are no more pages.- Fast full-text search — an inverted index (Elasticsearch, Typesense, Postgres full-text) with pre-computed relevance scores. A
LIKE '%shoes%'table scan will not meet a <100 ms target on millions of rows. - Response time SLA — the debounce window should be tuned relative to p95 API latency. If the API routinely takes 400 ms, a 200 ms debounce still produces a perceptible lag.
Measuring "Fast" for Real Users
Define two metrics:
- Time to first result — the interval from the debounce firing to the first card appearing on screen. Target: <300 ms on a good connection.
- Interaction to Next Paint (INP) — how long the UI is unresponsive after each keystroke. Keep this under 200 ms (Google's "good" threshold) by keeping the input handler lightweight.
Track both in production via the Web Vitals API or a real-user monitoring tool. Lab-only testing misses the long tail of slow devices and congested networks that real users hit.