Skip to content

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
Practice it live

Your first interview starts free.

You choose 5, 20 or 45 minutes before you start.

See the question brief and its sources
On this page
Asked at

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

AskWhy it mattersA 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. GET /markets/{symbol}/book gives a snapshot with its own sequence.

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.

POST /orders takes a client order id and returns an order id and a status. A live orders feed per person then reports each status change: pending, open, filled, failed, or cancelled.

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.

The requirements menu

RequirementScopeWhy

Show a price chart, a live order book and recent trades for one market

Core

The market data half of the screen, and where the performance problem lives.

Place a market or limit order and see it go from sent to open to filled

Core

The money half: a tap that must feel immediate while the truth comes from the exchange.

Show the person's open orders and holdings, kept up to date

Core

Fills change holdings in steps, and the person decides their next order from this panel.

Show clearly when prices are stale or the live feed is down

Core

A price shown as live when the feed is dead invites an order at the wrong price.

Cancel an open order from the open orders panel

Optional

Take it if there's time: it reuses the same sent-then-confirmed flow as placing, and a cancel that races a fill is a good follow-up. Leave it if the core flow isn't finished.

Switch between markets without reloading the page

Optional

Take it for a real product: it forces you to unsubscribe, clear the store and resubscribe without showing the old market's prices under the new symbol. Leave it in a short round.

Stay usable on a phone with a weak connection

Optional

Take it if asked: fewer price levels, a slower redraw and a louder stale state. Leave it as a variant otherwise, since the desktop design is the base it builds on.

Keyboard entry and screen reader support for the order form

Optional

Take it if the interviewer cares about access: the form is a standard form, but a live book that announces each change would be unusable. Leave it if the round is about data flow.

Several markets open in one screen, or in several tabs

Optional

Take it as a follow-up to the shared store: a shared worker lets a second tab ride on the socket the first one opened. Leave it out of the first pass.

Sign-in and identity checks

Out of scope

Assume a signed-in person; the orders feed and portfolio call are already scoped to them.

How the exchange matches orders

Out of scope

The client reads statuses the exchange reports and doesn't decide a fill itself.

Deposits and withdrawals

Out of scope

Another screen with its own confirmation flow; the holdings panel just shows the result.

Drawing tools on the chart

Out of scope

A charting product of its own. The chart here appends the last price and nothing more.

Order history and exports

Out of scope

A separate list of past orders; it needs none of the live-feed work this round is about, so leave it.

Non-functional requirements

RequirementWhat 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

QuantityWorkingResultWhat 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

EntityWhat 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

EndpointNotes

GET /markets/{symbol}/book → { bids, asks, sequence }

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.

Live market feed: subscribe { symbol, channels: book, trades, ticker, heartbeat } → updates with a sequence

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.

POST /orders { client_order_id, side, type, price, size } → { order_id, status }

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.

Live orders feed per person: status changes (pending, open, filled, canceled, failed)

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 POST response.

GET /portfolio → { holdings, open_orders }

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

order idmessagesLive feedBook, chart,tradesOrder formExchange

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.

book, trades,ticker,heartbeatchanges insequenceafter a gapdirty slicesonce a frameonce a framegap or silencewarnsclient order idaccepted orrefusedorders feedLive feedFeed clientMarket data storeBook snapshotFrame schedulerOrder book rowsChart and tradesStale bannerOrder formExchangeOrders storeHoldings and openorders
The whole design

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.

A concept that helps here: Batching UI updatesA concept that helps here: Canvas or the DOMA concept that helps here: Core Web Vitals

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?

A concept that helps here: Sync queues and client idempotencyA concept that helps here: Optimistic updates and rollbackA concept that helps here: Idempotency keys

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?

A concept that helps here: Where state livesA concept that helps here: Client caching and normalized storesA concept that helps here: Coordinating across tabs

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?

A concept that helps here: Reconnect and resumeA concept that helps here: Heartbeats and presenceA concept that helps here: Partial failure in the UI

Concepts this guide uses

Sources

  1. Coinbase Exchange: WebSocket channels
  2. Coinbase Advanced Trade API: Create Order
  3. Binance: WebSocket streams for spot
  4. web.dev: Rendering performance
  5. web.dev: Web Vitals
  6. web.dev: Interaction to Next Paint (INP)
  7. MDN: Page Visibility API
  8. MDN: Window: requestAnimationFrame() method
  9. MDN: SharedWorker
  10. Marc Brooker: Jitter: Making Things Better With Randomness
  11. FrontendLead Discuss: Coinbase Front End interview
Sign in to report a mistake