0%
Frontend System Design Interviews: Components, Rendering, State, Caching and Performance
Walkthrough: Designing an Autocomplete
Design an autocomplete is one of the most common frontend system design prompts, and it looks deceptively small. A text box and a dropdown. Most candidates can sketch the happy path in two minutes, which is exactly why the interviewer asks it: the signal is not in the happy path but in everything around it. What happens when the user types faster than the network responds? What happens when responses arrive out of order? How does a screen reader user know that suggestions exist? How do you avoid sending forty requests for one search? How would three different product teams reuse the same widget?
This lesson works the problem end to end with the six step framework from the first lesson: requirements, architecture, data model and state, interface, deep dives and wrap up. The aim is to show what a complete forty five minute answer sounds like, including the decisions and the reasons for them. Networking techniques were covered in depth in the networking lesson and accessibility in the accessibility lesson; here you apply them to one concrete component and see where each one earns its place.
Clarify what kind of autocomplete
The word autocomplete covers several products that need different designs, so the first job is to narrow it. Ask which of these the interviewer means. A search suggestion box, like the one at the top of a shopping or video site, shows popular queries and maybe a few direct results as you type, and pressing Enter runs a full search. An entity picker, like the field where you choose a city, a coworker or a tag, requires the user to pick one item from a known set, and the chosen value is an ID, not free text. A mention or command popup, like typing an at sign in a chat box, appears inside a larger text area at the caret position. An address field calls a third party geocoding service with strict quotas.
For this walkthrough, assume the interviewer says: a search suggestion box for a large content site, used on desktop and mobile web, backed by a suggestions endpoint that the company already runs. Free text is allowed, so the user can ignore suggestions and search for anything. Then add a second requirement that makes the design more interesting: the same widget should be reusable by other teams for entity pickers, such as choosing a user to share a document with. Saying this out loud early tells the interviewer that you will design a component, not a page.
Functional requirements
Write the functional requirements as a short list the interviewer can see. As the user types, show up to about eight suggestions that match the current text. Highlight the part of each suggestion that matches what was typed. Let the user move through suggestions with the mouse, touch and keyboard, and select one with a click, a tap or Enter. Pressing Escape closes the list without losing the typed text. Selecting a suggestion fills the input and triggers a search, or for the entity picker variant, records the selected item. Show recent searches when the input is focused but empty. Show a clear state for no results and a quiet state for errors, so that a failed suggestion request never blocks the user from searching.
Then name what you are leaving out unless asked: spelling correction and query understanding live on the server; personalised ranking is a server concern; rich result cards with images can be a later extension. Scoping out loud protects the time you need for the deep dives.
Non functional requirements
Non functional requirements are where frontend candidates show judgement. The most important one is perceived speed. Typed characters must appear in the input instantly, within one frame of about sixteen milliseconds, no matter what the suggestion logic is doing. A slow keystroke echo feels broken in a way that slow suggestions do not. Suggestions themselves should appear within roughly three to four hundred milliseconds of the user pausing, which is around the point where people stop perceiving the list as reacting to them.
The second requirement is server load. A large site might have millions of people typing at once. If each keystroke sends a request, a ten character query costs ten requests, and most of them are wasted on prefixes nobody wanted. The client is the cheapest place to cut that load. Third is correctness under bad networks: on a mobile connection, latency varies from fifty milliseconds to two seconds, so responses arrive out of order and some never arrive at all. Fourth is accessibility: the widget must work fully with a keyboard and announce itself correctly to screen readers, because search is often the main way people navigate a site. Fifth is reusability: other teams will configure it, so its behaviour must be adjustable without forking the code. Sixth, briefly, is security: suggestion text comes from user generated content, so it must never be inserted as raw HTML.
Turn speed into a budget
A strong answer converts the speed requirement into a budget split across the pipeline. Echo the keystroke in under sixteen milliseconds. Wait about one hundred and fifty milliseconds for the user to pause. Allow about two hundred milliseconds for the network round trip at the median. Leave about fifty milliseconds to render the list. That totals roughly four hundred milliseconds from the last keystroke to a visible list, and it tells you what to optimise: the debounce delay and the network are the big items, so caching and prefetching will matter far more than micro optimising the render.
Budgets also show the interviewer where your trade-offs sit. A longer debounce saves server load but eats into perceived speed. A shorter one feels snappier but sends more requests. Writing the numbers down lets you discuss the trade-off precisely instead of saying it should be fast.
Sketch the screen
Finish the requirements step with a quick wireframe: an input with a search icon and a clear button, a dropdown panel under it with up to eight rows, each row showing the suggestion text with the matched part in bold and perhaps a small type label such as query, channel or user. At the top of the panel when the input is empty, a recent searches heading. At the bottom, an optional see all results row. On mobile, the panel may expand to full screen when the input is focused, because the on screen keyboard takes half the viewport. You do not need pixel detail, but the wireframe anchors every later decision: the rows tell you the data shape, the recent searches tell you about local storage, and the mobile layout tells you about viewport and keyboard handling.
Scoping questions worth asking
A handful of questions settle most of the design. Is it free text or must the user pick from a list? How large is the candidate set: could the whole list ship to the client, as with a list of fifty countries, or does it need a server? Is there an existing endpoint, and what is its latency? Are suggestions personalised, which affects caching? Which devices and network conditions matter most? Must it support right to left languages and input method editors, such as those used for Chinese and Japanese? Each answer removes a branch. The candidate set size is especially important: if it is small and static, the right design is to load it once and filter locally, with no network logic at all. Saying that shows you are designing for the problem, not reciting a template.
If the full list is small enough to ship with the page, such as a few hundred countries or tags, filter it locally and skip debouncing, caching and cancellation entirely. The server driven design is only needed when the set is large or changes often.