0% completed
A Method for Any Frontend Design
On This Page
The Five Steps
Requirements for Search
The Search Architecture
The Search Data Model
The Search Interface
Search Optimizations
Using This in an Interview
Key Takeaways
Practice Questions
Where should a frontend design begin when the task is "design the search page for an online grocery store"? With the components, with the API, or with the choice of where the page is rendered?
It should begin with none of them. Each of those choices depends on answers that come earlier: what the page must do, on which devices, and how fast. A component tree drawn before those answers are known often has to be drawn again once they arrive.
A fixed order of five steps solves this, because each step uses what the step before it produced. The sections below describe the five steps and then apply them to Basket's search page.
The Five Steps
| Step | The question it answers | What it produces |
|---|---|---|
| 1. Requirements | What must the page do, for whom, and how well? | Actions on screens, and quality targets in numbers |
| 2. Architecture | Which parts exist, and how does data move between them? | A diagram of components, the store, the data layer and the server |
| 3. Data model | What data does the client hold, and in what shape? | The entities and the shape of the client store |
| 4. Interface | What crosses each boundary? | The requests and responses, and the props and events of key components |
| 5. Optimizations | Where will the design miss a target, and what fixes it? | Choices for performance, accessibility, security and monitoring |
Look at the return arrow. The order is a default, not a rule that forbids going back: an optimization such as "send the first products inside the HTML" can change the architecture. Notice also that every step has a concrete output. A step that ends without one has not been done.
Requirements come first because every later step is checked against them, as Requirements for a Frontend Design showed. Architecture uses the four layers from The Parts of a Web Client to place each feature. The data model comes before the interface because a request should be shaped by the data the client needs, not the other way around. Optimizations come last because they are chosen by comparing the design with the numbers, using estimates like those in Estimating Bytes Frames and Requests.
When a design has to fit into a fixed time, such as a 45 minute design discussion, a split like this one keeps the later steps from disappearing:
| Step | Minutes |
|---|---|
| Requirements | 6 |
| Architecture | 10 |
| Data model | 7 |
| Interface | 10 |
| Optimizations | 12 |
The largest share goes to optimizations because that is where the design is tested against its numbers. The smallest goes to requirements, which should be short and specific.
Requirements for Search
The functional requirements for Basket's search page are three actions. The shopper types a query and sees up to 8 suggestions from the first letter typed. The shopper picks a suggestion or presses Enter and sees matching products, 30 per page, with diet and category filters. The shopper can share or reload the page and get the same results.
The non-functional requirements come with numbers:
- Each key press shows a visible response within 200 ms on the target phone.
- Suggestions appear within 500 ms after the shopper stops typing.
- The search box works with a keyboard and a screen reader, in English and Spanish.
- Search result pages are not indexed by search engines, so they do not need server-produced HTML for that reason.
The Search Architecture
The architecture places each part of the search page in a layer and shows how data moves between them.
Look at where the query lives: in the URL, owned by the router. That one choice meets the requirement that a shared or reloaded page shows the same results. Notice also that the suggestion list belongs to the search box alone, while the grid reads the results from the data layer's cache. Only the data layer writes to that cache, so data still flows one way.
Data flows one way, as described in The Parts of a Web Client. A key press changes the text in the search box, and pressing Enter changes the URL. The data layer sees the new query and fetches results, and the grid draws them.
The Search Data Model
An entity is one kind of thing the client keeps data about, with an id that identifies each item. The search page has one entity, the product, plus the suggestions for the current text and one list of results:
interface Product { id: string; name: string; priceCents: number; imageUrl: string; inStock: boolean } interface Suggestion { text: string; productId?: string } interface SearchResults { query: string; filters: string[]; productIds: string[]; page: number; total: number }
The results hold product ids, and each product is kept once under its id. A product that appears in the results and in the cart is then one copy, so a price change shows the same value in both places. Prices are whole cents, because fractions such as 0.1 are not exact in JavaScript numbers.
The Search Interface
The interface is written as the requests the page sends and the props of its key component. The search request and its response:
GET /api/search?q=oat%20milk&diet=vegan&page=1
{ "query": "oat milk", "total": 14, "items": [ { "id": "p-118", "name": "Oat Milk 1 L", "priceCents": 249, "imageUrl": "https://cdn.basket.example/p-118-320.jpg", "inStock": true } ], "nextPage": null }
Each item contains only the fields a card shows. Around the items, the response adds the query, the total for the "14 results" line, and the next page, which is null here because 14 results fit on one page. The search box's props say what it receives and what it reports:
interface SearchBoxProps { value: string suggestions: Suggestion[] onChange: (text: string) => void onSelect: (suggestion: Suggestion) => void }
Search Optimizations
Each optimization answers one requirement, and the arithmetic shows whether it is needed.
- Wait for a pause in typing. Sending a request on every key press means 8 requests for "oat milk", one for each character, including the space. Debouncing means waiting until input has stopped for a set time before acting. With a 250 ms wait, a shopper who types "oat", pauses, then types "milk" sends 2 requests. The wait also fits the 500 ms target: 250 ms, plus a 150 ms round trip, plus about 50 ms of server time, is 450 ms.
- Ignore old answers. The reply for "oat" can arrive after the reply for "oat milk". Each response is checked against the current query, and a stale one is dropped.
- Keep answers by query. Suggestions are cached under their query text, so pressing backspace from "oat m" to "oat" shows the earlier suggestions at once.
- Make the list usable without a mouse. Arrow keys move through the suggestions, Enter picks one, and a screen reader announces how many suggestions there are.
- Treat the query as text. The query is shown on the page as text and never inserted as HTML, so a query containing a script cannot run it.
- Measure it. The page records how long key presses take to respond on real phones and how many search requests fail, so a slow release is noticed.
Using This in an Interview
Name the five steps at the start and keep to them: "I will spend a few minutes on requirements, then draw the architecture, the data model and the API, and use the rest on optimizations against those numbers." It shows the plan before any detail.
Two follow-up questions are likely:
- "If you had only ten minutes left, which step would you shorten, and why?"
- "Why did you define the data model before the API response?"
Key Takeaways
- A frontend design runs in five steps: requirements, architecture, data model, interface and optimizations, and each step uses the output of the one before.
- Every step ends with something concrete: numbers, a diagram, types, a request and response, or a list of fixes.
- The order is a default, so an optimization may send the design back to change its architecture.
- In a fixed time, give the largest share to optimizations, because that is where the design is tested against its numbers.
- On Basket's search page, the query lives in the URL, results are cached by query, and typing waits 250 ms before a request, which still meets the 500 ms target.
The five steps work for one component, one application, or an application and its API. The next lesson, How a Browser Turns HTML into Pixels, begins with what happens inside the browser after the HTML arrives.
Practice Questions
Try each question first, then open the answer.
1. A design for Basket's search page begins with the sentence "We will use a global store library for all state." What is wrong with starting there?
<details> <summary>Show answer</summary>It makes an architecture choice before the requirements are known. Without knowing which data is shared, what must survive a reload, and how fast the page must respond, there is no way to tell whether a global store is needed. On the search page, the query belongs in the URL and the suggestions belong to the search box alone, so much of the state would not go into the store at all.
</details>2. Put each item into one of the five steps: (a) cache suggestions by query text, (b) suggestions appear within 500 ms after typing stops, (c) a Product type with priceCents, (d) the JSON returned by GET /api/search.
(a) Optimizations, (b) requirements, (c) data model, (d) interface. The cache is a fix chosen to meet a target. The 500 ms limit is a quality target in numbers. The type describes data the client holds. The JSON response is what crosses the boundary between client and server.
</details>3. A teammate wants to wait 600 ms after the last key press before asking for suggestions, to save requests. Does that meet the 500 ms requirement on the slow profile?
<details> <summary>Show answer</summary>No. The wait alone is 600 ms, which already exceeds the target before the request is sent. With the 150 ms round trip and about 50 ms of server time, the suggestions arrive about 800 ms after typing stops. Only an answer already in the cache, shown before the wait ends, could appear in time, so the wait has to be shorter, as 250 ms is.
</details>4. Why does Basket keep the search query and filters in the URL rather than only in the store?
<details> <summary>Show answer</summary>Because one of the requirements is that a shared or reloaded page shows the same results. Data in the store is lost on reload and is not part of a link. The URL survives both, and the router can rebuild the page from it. The back button also returns to the previous search, because each search is a separate URL.
</details>5. The five steps put optimizations last. Give an example where an optimization sends the design back to step 2, and explain why that is acceptable.
<details> <summary>Show answer</summary>Sending the first products inside the HTML changes the architecture. If the estimates show that the product list misses its LCP target while it waits for the JavaScript, the fix is to have the server produce the first products. That moves work from the data layer in the browser to the server and the platform layer. Going back is acceptable because the order is a default, and the fix is driven by a requirement.
</details>Reading Progress
0%
On This Page
The Five Steps
Requirements for Search
The Search Architecture
The Search Data Model
The Search Interface
Search Optimizations
Using This in an Interview
Key Takeaways
Practice Questions