How to design a trading screen (frontend)
The first sections are free. The deep dives, level expectations and quiz are part of Pro.
Episode22 min2 parts
Two hosts talk this question through
One host leads. The other asks what you would ask.
Live practice
Practice this question out loud
Your interviewer asks this question and follows up on each choice, the way the real round goes. You talk it through and sketch it on a whiteboard. The 20 and 45 minute rounds end with a scored report.
- Spoken answers
- Follow-up questions
- Whiteboard
- Scored report
- 5 to 45 min
Your first interview starts free.
You choose 5, 20 or 45 minutes before you start.
On this page
- The problem
- Clarifying questions
- The requirements menu
- Non-functional requirements
- Estimates
- Core entities
- The API
- The high-level design
- What breaks first
- The deep dives
- Entity fields
- An order book that changes many times a second
- Placing an order and knowing it went through
- One screen, many live panels
- When the live feed drops
- Variants
- What each level is expected to show
- The 30-second answer
- Quiz
The problem
A trading screen shows a price chart, a live order book, recent trades, an order form and the person's holdings, all fed by a market that changes faster than anyone can read it. The answer turns on separating what arrives from what is drawn: one connection feeds a store as fast as the exchange sends, the screen redraws from that store once a frame, and anything the exchange hasn't confirmed, a fill, a balance, a price after a silent feed, is shown as unconfirmed. A stale price or a doubled order costs real money, so the design treats staleness and retries as first-class states, not edge cases.
Clarifying questions
| Ask | Why it matters | A typical answer |
|---|---|---|
How does market data arrive: one live feed with several channels, or a request per panel? | It decides whether there is one connection to share or several to manage, and whether book changes come as a snapshot followed by diffs or as whole books. | One live feed. You subscribe for a symbol to the book, trades, ticker and heartbeat channels, and each update carries a sequence number. |
How busy does the book get, and does the feed batch changes or send each one? | Dozens of changes a second against a frame budget of about 10 milliseconds is the core performance problem. A batched feed changes the shape of each message but not the drawing cost. | Dozens of changes a second in a busy market. Public exchange feeds batch at about 50 milliseconds or every 100 or 1,000 milliseconds, so one message can hold many changed price levels. |
What does the exchange tell the client about an order after it's sent? | Whether the client can show sent, open and filled as separate states, and whether a retry is safe, depends on what the order endpoint returns and on a per-person orders feed. |
|
Who is this for: a retail person watching one market, or a professional with many? | A retail screen accepts a price that is a frame old and shows one market; a professional terminal wants many markets, hotkeys and a denser book, which changes the drawing approach. | A retail screen for one market at a time, with 5 live panels: chart, book, trades, form and holdings. Treat several markets or many open tabs as follow-ups. |
How fast must the form react to a tap, and what counts as reacting? | The exchange can take seconds on a slow link, so the budget has to be about what the screen shows at once, not when the order is confirmed. | Within 200 milliseconds the button must flip to a sent state and refuse a second tap. Confirmation comes later from the exchange. |
Does the feed tell us when it is alive, and what happens after a long drop? | Telling a quiet market from a dead connection needs a signal that arrives even when nothing trades, and a recovery path for changes that were missed. | A heartbeat arrives every 1 second with a sequence number. After a gap, the client must rebuild the book from a snapshot. Sign-in and the matching engine are out of scope. |
Non-functional requirements
| Requirement | What it forces |
|---|---|
Each frame's work fits in about 10 milliseconds, leaving the browser time to draw each frame | In this design, no panel redraws directly in response to a message. Changes land in a store at whatever rate they come, and a frame scheduler redraws the visible panels once per repaint at most, with the book drawn as rows whose text is rewritten rather than a list rebuilt each time. |
A tap on buy or sell answers within 200 milliseconds | The tap handler does a local state change and a paint, not a network wait: the button flips to a sent state and locks before the request leaves. Interaction to Next Paint measures this span, from the tap to the next frame, so the network can't be inside it. |
An order is never placed twice, however many times the button is pressed | A client order id created in the browser before the first send and reused on each retry, plus a locked button while an answer is outstanding. The id does the real work: the lock stops the eager tap, the id stops a retry after a timeout from becoming a second order. |
A price on screen is never older than it looks | A stale flag in the store that the book, chart and form all read, set as soon as the heartbeat is late or a sequence number is skipped, and cleared when a fresh snapshot and the live changes agree again. Old prices stay on screen but are drawn as stale. |
Estimates
| Quantity | Working | Result | What it sizes |
|---|---|---|---|
Redraws a second of the book panel | Once per frame on a display refreshing 60 times a second: 60 redraws a second at most. Once per server batch at 50 ms: 1,000 / 50 = 20 a second. | 20 to 60 redraws a second, whichever the design picks | The dial the whole order book answer turns on. Drawing on arrival could run at the message rate; redrawing once a frame caps it at 60; following a 50 ms batch feed caps it at 20 and the screen still reads as live. |
Book changes per frame | A few dozen changes a second spread across 60 frames a second comes to about one change a frame or fewer, so long as the rate stays under 60 a second. Batched feeds deliver them in bursts anyway: one 50 ms message holds all the changed levels from that window. | Under one message a frame on average, many changed levels per message in bursts | Why the message count isn't the problem: a redraw of the whole book on each message costs the same whether it carries one changed level or twenty. The fix targets the cost of a redraw, not the number of messages. |
Time until a silent feed is called dead | A heartbeat every 1 second; call the feed dead after three missed beats, about three seconds. In the scenario's ten-second outage, the stale banner is up for roughly seven seconds before the feed returns. | About three seconds to notice, seven seconds of stale banner in a ten-second outage | How long old prices could be shown as live if nothing checked the heartbeat, and how quick the stale banner needs to be. Waiting one beat risks false alarms from jitter; waiting ten is a long time to trade on dead prices. |
Core entities
| Entity | What it holds |
|---|---|
Market | The symbol being traded and its headline figures, fed by the ticker channel. |
Order book | Bids and asks by price level, kept in the store and rebuilt from a fresh snapshot whenever changes were missed. |
Trade | One match the exchange reports, shown in the recent trades panel and appended to the chart. |
Order | An order the person placed, from the tap through the exchange's statuses. |
Holding | One asset the person owns, from the portfolio call and updated by the orders feed. |
Feed state | What the client knows about its own connection, so panels can show stale and reconnecting states. |
The API
| Endpoint | Notes |
|---|---|
| The snapshot the book is built from, at first load and after any gap. The sequence it carries is the line: buffered changes with a sequence at or below it are dropped, the rest are applied. |
| A single socket serves the screen, subscribed once to each channel. The heartbeat arrives on a schedule even in a quiet market, so silence on it means the link is in trouble rather than the market. |
| The client creates the client order id before the first send and reuses it on every retry, so a repeat is matched to the same order instead of placing a second one. The returned status is the first confirmed state. |
| The source of truth for the orders store and the holdings panel. Nothing beyond the sent state is shown until a status arrives here or in the |
| Loaded once at start and again after a reconnect, so the orders store starts from the exchange's view and the live feed moves it forward. |
The high-level design
Step 1 of 5
Panels on the feed, a form on the exchange
Start with the shortest path that works: each panel listens to the live feed and redraws when a message arrives, and the order form posts to the exchange and waits for the reply. It shows the two data flows, market data in and orders out, and it already has the problems the rest of the design answers: each message is a redraw, the book and the chart can show different prices, and a tap on a slow connection shows nothing until the exchange answers.
What breaks first
The deep dives
An order book that changes many times a second. The market turns busy and the book changes dozens of times a second while the person watches it and the chart. Walk through one change from the socket to the pixels, and say how often the book is drawn.
Placing an order and knowing it went through. Someone taps buy on a slow connection, sees nothing change for a few seconds, and taps again. What does the screen show at each moment, and how many orders exist afterwards?
One screen, many live panels. The chart, the book, the trades, the form and the holdings all need live data. How does one price change reach each of them, and why do they agree?
When the live feed drops. In a busy market the feed goes silent for ten seconds, then returns, and some book changes were never delivered. What does the person see during the silence, and how does the book become right again?
Concepts this guide uses
Sources
- Coinbase Exchange: WebSocket channels
- Coinbase Advanced Trade API: Create Order
- Binance: WebSocket streams for spot
- web.dev: Rendering performance
- web.dev: Web Vitals
- web.dev: Interaction to Next Paint (INP)
- MDN: Page Visibility API
- MDN: Window: requestAnimationFrame() method
- MDN: SharedWorker
- Marc Brooker: Jitter: Making Things Better With Randomness
- FrontendLead Discuss: Coinbase Front End interview