Courses / Frontend System Design, with JavaScript Foundations / Chapter 1
Module 1 · The Frontend Interview · Chapter 1 of 21
The Frontend System Design Interview
Start here. Next up: Values, Coercion, Scope and Closures.
Part 1 · What frontend system design asks
The question
A frontend design round gives you one or two lines, such as "design an autocomplete" or "design a chat app", and asks you to plan the part that runs in the browser. You talk and draw; you are not expected to finish a working program.
Public guides sort these prompts into two families. A UI component question asks for one reusable piece: an autocomplete, a star rating, a modal, a data table. An application question asks for a whole product: a news feed, a video player, a chat app, a calendar. The skills overlap, but the weight differs. A component answer goes deep on the component's inputs, events, states and keyboard use. An application answer spends more time on how data arrives, where it is kept and how the screens share it.
In both, the question is deliberately short. Your first job is to turn it into something you can design, by asking what the user does, on which devices and what is out of scope. Two candidates given "design an autocomplete" can end up designing different things: one a search box for a shopping site that must work on slow phones, the other an address picker inside an internal tool used on desktops. Both are fine answers if the requirements were stated first.
How it differs from backend design
A backend design round is about a service that many users share. You count requests per second, choose a database and decide how to split data across machines. A frontend design round is about a program that one user runs on one device. The scarce resources are different.
| Backend design | Frontend design | |
|---|---|---|
| Unit of scale | Requests per second, terabytes stored | One tab on one phone |
| What runs out | CPU, disk, network between servers | Main-thread time, memory, battery, the user's data plan |
| Where state lives | Databases and caches | Component state, a client store, a cache, the URL, browser storage |
| Typical failure | A node dies, a queue backs up | A flaky network, a slow device, a user who navigates away mid-request |
| Main drawing | Services, queues, databases | Components, a store, a data layer, the API boundary |
The two meet at the API. A good frontend answer states what the client asks for, what it gets back and what it does when the reply is late, partial or an error. It does not design the database behind that API. If the prompt is a news feed, say how the feed is paged and cached on the client, and leave the ranking service to the system design course.
What is in scope
Most prompts let you show the same set of topics. Treat this as a map of the course, because every later chapter fills in one of these rows.
| Topic | What you decide |
|---|---|
| Architecture | The client pieces and how they talk: views, a store, a data layer, a cache |
| State and data | What is kept on the server, in a client cache, in component state, in the URL |
| API contract | Endpoints or operations, pagination, error shapes, real-time transport |
| Rendering | Where HTML is produced: browser, server, or both |
| Performance | Load speed, input response, layout stability, long lists |
| Accessibility | Keyboard use, roles and names, focus, motion |
| Internationalisation | Text direction, number and date formats, text that grows |
| Security | Untrusted input, cookies and tokens, third-party code |
Out of scope for almost every prompt: choosing a database, sharding, and the details of a ranking or search service. If the interviewer pushes you there, a short sentence about the contract is enough.
Name the two families of frontend design prompts and one example of each.
- A UI component question asks for one reusable piece, such as an autocomplete or a data table.
- An application question asks for a whole product, such as a news feed or a chat app.
Why is a database choice usually out of scope in a frontend round?
Part 2 · How the round runs and what is scored
Phases of a round
A round is commonly 45 to 60 minutes long, but the format is set by each company, so ask your recruiter what to expect. The table below is our own outline of the phases most prompts move through, not a published format.
| Phase | What happens | Your move |
|---|---|---|
| Prompt | You get the question, often one line | Repeat it back in your own words |
| Clarify | You ask about users, devices, scale and scope | Write the answers down so they bind the design |
| Design | You walk from architecture to data to API | Draw one diagram and keep to it |
| Deep dive | You pick the hard parts and go into detail | Choose them from the requirements, not by habit |
| Wrap-up | You summarise trade-offs and take questions | State what you rejected and why |
A public guide for this round, the Front End Interview Handbook, says that in a session of an hour or less you are expected to talk about design trade-offs and possible implementations rather than code them out, and that its steps need not be taken in a fixed order. The practical meaning: a diagram and a few type or API sketches beat pages of code, and you may jump back to an earlier step when a new requirement appears.
The clarify phase is where the design is decided, so it is worth seeing what good questions look like. Each question below changes something you would draw for "design an autocomplete".
Signals that get scored
Most companies do not publish their rubrics, so no one outside can state the exact scoring. The list below is our own summary of the signals a prompt gives you room to show. The same public guide says performance, accessibility and internationalisation are what set senior candidates apart from junior ones, and that candidates should bring these topics up and lead the discussion themselves.
| Signal | Strong looks like | Weak looks like |
|---|---|---|
| Clarifying | Questions that change the design | Questions asked for show, or none |
| Structure | A visible order and time awareness | Jumping between topics |
| Data and API | Types for entities, a stated pagination and error shape | Calls to "the backend" with no contract |
| Depth | Two or three hard parts explored with numbers and trade-offs | Everything touched, nothing explained |
| Cross-cutting care | Performance, accessibility, i18n and security raised unprompted | Raised only when asked |
| Communication | Thinking aloud, checking in, naming trade-offs | Long silences, defending a choice without alternatives |
Notice what is missing: a single correct design. Two strong answers to the same prompt can differ a lot. What is scored is whether the choices follow from the requirements you stated, and whether you can say what each choice costs.
Common ways rounds go wrong
- Starting to draw before asking anything, then finding out the app must work offline.
- Naming a framework as the answer. A framework is a tool; the question is how the data and the screens are organised.
- Spending thirty minutes on one component and never reaching the API.
- Listing every optimisation you know. Pick the ones that fit the requirements.
- Treating accessibility as a closing remark. Keyboard and screen reader use shape the component design from the start.
A candidate spends 25 minutes drawing a component tree for a news feed, then runs out of time before saying how posts are paged. Which signals come out weak?
- Structure and time awareness, because one step took over half the round.
- Data and API, because there is no pagination or error contract. Depth on the hard parts was never reached either.
What does the public guide say about writing code in a round of an hour or less?
- Discuss trade-offs and possible implementations instead of writing out code.
- Steps need not be covered in a fixed order.
Which cross-cutting topics help separate senior from junior answers, and who should raise them?
- Performance, accessibility and internationalisation.
- You raise them yourself, without waiting to be asked.
Part 3 · A method for answering
Seven steps
One well-known public framework for this round is RADIO: requirements exploration, architecture, data model, interface definition and optimisations with a deep dive. This course uses a slightly finer method of seven steps, which is our own. Later chapters follow it, and a full chapter on the method comes after the building-block chapters.
| Step | What you produce |
|---|---|
| 1. Requirements | 3 to 6 user actions, non-functional targets (speed, devices, accessibility, languages, offline), and what is out of scope |
| 2. Architecture | One diagram: views, client state store, data layer and cache, network transport, service worker if any, and the server boundary |
| 3. Data model | Entities as types, and where each piece of state lives: server, client cache, local UI or the URL |
| 4. Interfaces | The client and server API, with pagination and errors, plus the main component props and events |
| 5. Deep dives | Two or three hard parts that the problem names |
| 6. Cross-cutting checks | Performance, accessibility, internationalisation, security, observability, one or two points each |
| 7. Trade-offs | A table of choices made and the alternative rejected |
The mapping to RADIO is direct: steps 1, 2, 3 and 4 match its first four letters, and steps 5 to 7 split its last letter into the deep dive, the checks and the trade-offs.
A time plan for 45 minutes
The split below is our own suggestion, not a figure from any source. It front-loads the steps that decide everything else, and gives the deep dives together the largest share, 13 minutes, because that is where depth is shown.
Whole round: 45 min (for 60 minutes, give the extra time to deep dives)
Read it as steps
Eight blocks of time add up to the full round.
Requirements, architecture and the data model take 20 of the 45 minutes, close to half the round, on purpose. A wrong requirement discovered at minute 30 costs more than a slow start. For a 60-minute round, add the extra 15 minutes to the deep dives and to the interfaces step.
The method on one prompt
Here is the method run quickly over "design an autocomplete for a shopping site", one line per step, to show the size of each answer. In a real round each line becomes a few minutes of talk and drawing.
| Step | What you would say |
|---|---|
| 1. Requirements | Type to see up to 8 suggestions, pick with mouse or keyboard, see recent searches. Mid-range phones, English and Hindi, keyboard and screen reader use. Out of scope: ranking. |
| 2. Architecture | Input component, suggestion list, a small store for the query and results, a data layer with a cache keyed by query, the search API |
| 3. Data model | Suggestion { id, label, kind }; the query lives in the input and the URL, results in the cache, the highlighted row in local state |
| 4. Interfaces | GET /suggest?q=&limit=8 returning a list and an error shape; the component takes onSelect and emits the chosen item |
| 5. Deep dives | Debounce and cancel stale requests; keyboard and ARIA combobox behaviour |
| 6. Checks | Payload size, announcing result counts, scripts in matching, escaping text from the server, logging slow replies |
| 7. Trade-offs | Server filtering over a downloaded list, because the catalogue is large; a short cache lifetime over none |
Notice how step 1 drives the rest. The phone requirement shows up again in the payload check, the keyboard requirement becomes a deep dive, and the large catalogue decides the main trade-off. If a step does not trace back to a requirement, ask whether it belongs in the answer.
Using the method on the fly
Say the step you are on, in a few words: "Now the data model." It tells the listener where you are and gives you a place to return to if you get lost. If a new requirement appears later, say so and go back: "That changes the architecture, let me update the diagram."
Keep one diagram on the board for the whole round and add to it. A diagram that is redrawn for every step wastes time and hides how the pieces connect.
Which public framework does the seven-step method map onto, and what is different?
- RADIO: requirements exploration, architecture, data model, interface definition, optimisations and deep dive.
- The seven steps split the last letter into deep dives, cross-cutting checks and trade-offs.
Which block of the 45-minute plan is the largest, and why?
- Deep dives, 13 minutes in two parts, because that is where depth is shown.
- The time plan itself is our own suggestion, not from a source.
What do you do when a new requirement appears at minute 30?
- Say it changes the design, go back to the affected step and update the one diagram.
Part 4 · Designing AI features in a frontend
A reply that arrives in pieces
Many products now put a model reply on the screen: an assistant chat, a draft suggestion, a summary. The reply is slow and arrives in pieces, so the frontend design is mostly about what the screen shows while waiting.
A model server can send its answer as a stream: small pieces of text as they are produced, instead of one body at the end. Users see the first words in a moment, which feels faster than a blank screen followed by a full paragraph. The cost is more states for the frontend to handle.
| State | What the screen shows | Moves on when |
|---|---|---|
| idle | An empty input | The user sends a message |
| waiting | A typing indicator | The first piece arrives |
| streaming | Text growing, with a Stop button | The stream ends, fails or is stopped |
| done | The full reply, with copy and retry | The user sends another message |
| error | What was received so far and a retry | The user retries |
| stopped | The partial reply, kept | The user sends another message |
Each row is a decision to make out loud. Keeping the partial reply after an error or a Stop is the usual choice, because throwing away words the user already read feels broken.
How streaming works in the browser
Two wire formats are common. Server-sent events (SSE) send a response of type text/event-stream, where each event is one or more lines starting with data: and ended by a blank line. Some model servers send newline-delimited JSON instead: one JSON object per line. The local Ollama server does this by default; its docs say stream: false returns one object instead.
The browser's EventSource reads SSE, but per the HTML standard its constructor takes only a URL and a withCredentials flag. You cannot choose the method, send a body or add a header such as Authorization: it makes a plain GET. A check in Chrome 157 agreed: given an options object with method and headers, it still sent GET /events with no Authorization header. A chat request carries a message in a POST body and usually a token, so fetch is the practical choice. fetch exposes the body as a ReadableStream. You read it with a reader, one { done, value } result at a time. Piping it through TextDecoderStream turns bytes into text. Chunk boundaries do not match event boundaries, so you keep a buffer and split on the blank line.
To cancel, pass an AbortSignal to fetch. Calling abort() on its controller ends the request and makes a pending read reject with an AbortError. The server notices the closed connection and can stop producing, which saves cost.
A stream reader, run
The reader below is written for a stub server that sends eleven words as SSE events, 60 ms apart. The stub runs on a local port, and the page runs in Chrome 157.
// Runs in the page: reads an SSE stream with fetch and can be stopped. export async function ask(url, { onToken, signal }) { const res = await fetch(url, { signal }) if (!res.ok || !res.body) throw new Error('bad status ' + res.status) const stream = res.body.pipeThrough(new TextDecoderStream()) const reader = stream.getReader() let buffer = '' for (;;) { const { done, value } = await reader.read() if (done) return 'finished' buffer += value const events = buffer.split('\n\n') buffer = events.pop() for (const ev of events) { const data = ev.replace(/^data: /, '') if (data === '[DONE]') return 'finished' onToken(JSON.parse(data).token) } } }
A reader for data: events
The page used the reader twice: once to the end, once with a signal that is aborted after the third token.
// 1. full reply const parts = [] const r1 = await ask('/reply', { onToken: (t) => parts.push(t) }) out.push(`full: ${r1}, ${parts.length} chunks`) out.push(`text: ${parts.join('')}`) // 2. stop after three tokens const ctl = new AbortController() const got = [] try { await ask('/reply', { signal: ctl.signal, onToken: (t) => { got.push(t) if (got.length === 3) ctl.abort() }, }) } catch (e) { out.push(`stopped: ${e.name}: ${e.message}`) } out.push(`kept: ${got.join('')}`)
Inside the page: one full read, then a read stopped after three tokens
full: finished, 11 chunks
text: Your order ships on Friday and arrives in Pune by Monday.
stopped: AbortError: signal is aborted without reason
kept: Your order ships Output (Chrome 157)
The abort is an error to catch, and the three tokens already received stay on screen. Against the local Ollama server the same reader idea applies, with JSON.parse per line instead of the data: prefix. In a run against a local model on this machine, every chunk before the last carried a thinking field and an empty response, so a client must handle chunks that add no visible text.
What else to say
- Partial rendering. Append plain text as it arrives. Turn it into rich text only at block boundaries, or after the stream ends, since half a list or half a code fence is not valid markup.
- Scrolling. Follow the new text only while the user is at the bottom. If they scroll up to read, stop following.
- Accessibility. Announcing every token to a screen reader is noise. Announce that a reply started and that it finished, and let the user read the text at their own pace.
- Limits. Disable Send while streaming or queue the next message. Cap input length and show the limit, since long prompts cost money and time.
- Retries. Retry only after an error that is safe to repeat, and say what happens to the partial text.
This lesson covers how to design the feature. It does not claim anything about how companies run their rounds.
Why use fetch rather than EventSource for a chat request?
EventSourceonly sends GET requests and has no option for custom headers.- A chat request sends the message in a POST body and usually carries a token, which
fetchallows.
Why keep a buffer when reading a stream?
- Chunk boundaries do not match event boundaries, so one read may hold half an event or several.
- You split on the blank line and keep the remainder for the next read.
Your reader works on short replies but sometimes throws a SyntaxError from JSON.parse on long ones. What is the likely cause?
- It parses each chunk as if it held whole events. A long reply is more likely to be split mid-event across reads, so half an event reaches
JSON.parse. - Keep a buffer, split on the blank line and parse only complete events, keeping the remainder for the next read.
Part 5 · A study plan for this course
How the course is laid out
The course has four parts. The foundations chapters cover the JavaScript and browser behaviour that the design chapters lean on. The building-block chapters cover requirements, client fundamentals, performance, APIs, patterns and security. The method chapter and the five design problems put the method to work. The last chapter is a timed mock. Reading the whole course takes about 11 and a half hours: the chapters' own estimates add up to 688 minutes, 24 of them in this chapter. They count reading only, not the time you spend running the code or attempting the drills.
| If you have | Do this |
|---|---|
| Three weeks | Week 1 (about 3 hours of reading): the foundations chapters, running each snippet yourself. Week 2 (about 3 and a half hours): requirements, fundamentals, performance, APIs, patterns and security. Week 3 (about 4 and a half hours): the method, then one design problem every two days, then the mock. |
| One week | Read the method chapter first (28 minutes). Attempt the mock prompts cold, note where you stall, and read only the chapters covering those gaps. Repeat the failed prompts. |
Skip the foundations only if you can already explain, without notes, why a promise callback runs before a timer, what this is inside an extracted method and how an event reaches a listener on a parent element.
Practising aloud
Design rounds are spoken, so practise by speaking. Set a timer for 45 minutes, record yourself, and answer a prompt on paper or a whiteboard. Play the recording back and look for four things: whether you asked questions before drawing, whether you held to the time plan, whether you named a trade-off for each choice, and whether you raised performance, accessibility, internationalisation and security without being asked.
- Write the requirements list first, every time. It is the habit most worth building.
- After each practice, write one sentence on what you would change in the design.
- Keep one standard architecture diagram (step 2 of the method) and redraw it from memory until it takes under two minutes.
- Run the code in the chapters. The outputs are real, and you learn more from changing a line and rerunning than from reading.
How to use the quizzes
Each lesson ends with two or three questions. Answer in your own words before opening the answer. If you cannot, the lesson is worth reading again. The answers are short on purpose: in a spoken round you have the same few sentences.
Some questions ask you to recall a fact, and some give you a situation, such as a bug report or a weak answer, and ask what went wrong. The second kind is closer to a real round, where the interviewer changes a requirement and waits to see what you do. When you get one wrong, write down the rule you missed and the situation that tested it.
Track your progress with a short list of things you can explain without notes. A useful set to aim for by the end of each week of the three-week route:
| By the end of | You can explain |
|---|---|
| Week 1 | Why [] == ![] is true, what a closure captures, the four this rules, why a promise callback runs before a timer, and what a long task does to input |
| Week 2 | The Core Web Vitals and one fix for each, when to choose REST, GraphQL or a socket, how cookies, CORS and CSP protect a page |
| Week 3 | Any of the five design problems in 45 minutes, out loud, with a requirements list, one diagram and a trade-offs table |
You have one week. Two cold mock attempts both stalled when the interviewer asked how the page stays fast with thousands of items. What do you read next?
- The performance chapter, for long lists and virtualisation, then retry those two prompts.
- The one-week route reads only the chapters that your stalls point to, after the method chapter.