Skip to content

How to design a dashboard of widgets (frontend)

The first sections are free. The deep dives, level expectations and quiz are part of Pro.

On this page
Asked at
Practice this question

The problem

The web client for a monitoring dashboard: a grid of widgets, each with its own query, that people add, drag and resize while the data refreshes on its own. The answer turns on one fact: with up to 100 widgets on a board, each one wants its data and its share of the main thread at the same moment, so the page needs a scheduler that decides which widgets fetch and which draw first, and the widgets on screen come first.

Clarifying questions

AskWhy it mattersA typical answer

How large can a dashboard get, and who decides?

A fixed cap of a dozen widgets needs no scheduling at all. A board that people grow to a hundred widgets makes the loading order the whole story.

People control the size of their own boards and the complexity of their queries, so plan for up to 100 widgets, each with its own query.

How fresh does the data have to be?

Seconds of lag allow polling on a timer. Sub-second freshness pushes toward an open connection per widget and far more work per frame.

Data may arrive up to 10 seconds late. That makes polling on a timer of a few seconds the default and a pushed stream the exception.

What kinds of widgets are there, and does each own its data?

A chart taking points several times a second is a different problem from a single number, and widgets that share data would call for a shared store.

Charts, single numbers and tables, each with its own query and its own result. In this design widgets don't share data.

Does the query server aggregate, and can the client ask for fewer points?

If the server returns raw points, the client has to thin them on the main thread. If it aggregates to a requested count, a chart can ask for as many points as it has pixels.

Yes. POST /queries takes max_points, and the server aggregates down to it.

Is there one time range for the page, or can a widget have its own?

A page-wide range means one change refetches the whole board at once, which is the loading problem again. A per-widget range adds state to each widget.

Both. The page sets a range, and a widget may override it.

Who edits the layout, and can two people edit at once?

Concurrent editing needs merging. A single editor lets the last save win.

Assume one person edits at a time; sharing dashboards is out of scope. Two tabs of the same person are worth a sentence later.

Which devices?

A laptop has a wide grid and a main thread to protect. A phone changes the grid's columns and the budget per frame.

Desktop and laptop browsers. Mobile apps are out of scope; a narrow window is a variant worth naming.

The requirements menu

RequirementScopeWhy

Show a page of widgets, each a chart, a number or a table drawing its own data

Core

The product. Each widget owning its query and result is what makes the rest of the design per widget.

Add, remove, move and resize widgets, and keep the layout

Core

A dashboard nobody can arrange is a report. The layout is also where the drag performance questions live.

Refresh each widget's data by itself, with a time range for the page or for one widget

Core

A monitoring page is read for what is happening now. Refresh per widget keeps a slow query from holding up the rest.

Show each widget's loading, empty and error state on its own

Core

With a hundred queries on a page, plan for one of them failing. A page-wide error would hide the working widgets.

Template variables or filters that apply to the whole page

Optional

Take it if the interviewer asks about changing the page's time range: it is the same mechanism, one change that refetches a hundred widgets through the scheduler. Leave it in a short round.

A full-screen view of a single widget

Optional

Take it to show how a chart refetches at its new pixel width. Leave it if the drag and resize story is already covered.

Let anyone build and add their own kind of widget

Optional

If it comes up, it needs a contract for what a widget receives and an error boundary around code you don't own. Wait until asked.

Rearranging with the keyboard as well as the mouse

Optional

Take it if accessibility comes up: a grid of x, y, w and h moves one cell at a time with arrow keys. Leave it otherwise.

Undo for a layout change

Optional

Cheap once the layout is one saved object, since the previous one can be kept in memory. Mention it; don't design it.

Pushed updates faster than once a second

Out of scope

People accept data up to 10 seconds late here, so an open connection per widget adds reconnection and ordering work for freshness nobody asked for.

Alerts and their rules

Out of scope

Another product surface. The dashboard shows data; it does not decide what is wrong.

How the server stores and queries metrics

Out of scope

A backend question. The client needs a query endpoint that honors a point cap.

Sharing dashboards with other people

Out of scope

Permissions and collaborative editing would take the round. Say that the last layout save wins and move on.

Mobile apps

Out of scope

A native app has its own rendering budget and layout. The web client in a narrow window is as far as this round goes.

Non-functional requirements

RequirementWhat it forces

A click answers within 200 milliseconds while widgets load

No long run of renders on the main thread while results pour in. Each render is its own task, ordered by priority, so a click's handler gets a turn between them. This is what Interaction to Next Paint measures, and a good score is 200 milliseconds or less at the 75th percentile.

A chart's update fits in a frame: about 10 milliseconds of work at 60 frames a second

Incoming points are buffered and drawn once per frame, appended rather than rebuilt, and a chart holds no more points than it has pixels across, so the work per frame is bounded by the chart's width rather than by how long it has been open.

A dashboard of 100 widgets stays usable

A query scheduler that gives visible widgets their requests immediately and meters out the others in small batches, and a render scheduler that keeps off-screen drawing out of the way of what the person is looking at.

Data may arrive up to 10 seconds late

Polling on a timer is acceptable, off-screen widgets may wait their turn, a widget can keep showing its last result labeled with when it was fetched, and polling can stop when the tab is in the background.

Core entities

EntityWhat it holds

Dashboard

One page: its title, the time range it applies to its widgets, and the grid they sit in.

Widget

One box on the grid: what kind it is, what it asks the server, where it sits and how big it is.

Widget data

What one widget last got back, when, and what state its box is in.

Layout

The grid positions and sizes of all the widgets, saved as one object per dashboard.

Scheduled task

One unit of work the page has queued: a fetch or a render for one widget, with its priority.

The API

EndpointNotes

GET /dashboards/{id} → { dashboard, widgets, layout }

One call for what the page needs to lay itself out. In this design the response holds no series data, so the grid can draw its boxes in loading states before the first query runs.

POST /queries { query, from, to, max_points } → { series }

One call per widget per refresh, sent through the query scheduler. max_points is set from the chart's pixel width and the server aggregates beyond it. An HTTP 429 answer throttles the entire queue rather than this one widget.

PUT /dashboards/{id}/layout { widgets: [{ id, x, y, w, h }] } → layout

The whole layout at once, sent on drop, not during the drag. Last write wins; the response is the layout as saved, which the client adopts.

POST /dashboards/{id}/widgets { kind, query } → widget

Returns the created widget. Our advice: have the client read the widget's id from that response, pick a spot for it in the grid, save the layout, and queue its first fetch like any other widget.

The high-level design

queriesseriesDashboard pageQuery serverWidget

Step 1 of 4

Widgets that fetch and draw themselves

Start with the simplest page that works: GET /dashboards/{id} returns the dashboard, its widgets and the layout, the page mounts a widget per entry, and each widget posts its query to the query server and draws when the series lands. It shows the data flow end to end, and it already fails at size: a hundred widgets send a hundred requests the moment the page opens, and they draw in whatever order the answers return, off-screen boxes included.

GET dashboardpauseregistersduevisible now,others meteredseriesHTTP 429 ortimeoutonce a framevisible first, idlefor the restretry withbackoffrender errorduring a draghold renderson dropPUT layoutnew widthDashboard pageDashboard serverWidgetLayout gridTab hiddenRefresh timerQuery schedulerQuery serverPoint bufferRender schedulerError boundaryPlaceholderLayout state
The whole design

What breaks first

The deep dives

A hundred widgets asking for data at once. Someone opens a dashboard of 100 widgets, each with its own query, on a laptop. What does the page do in the first seconds, and in what order do the widgets get their data and their pixels?

A concept that helps here: Backpressure and load sheddingA concept that helps here: List virtualization

Charts that keep up with live data. A latency chart receives new points several times a second while someone watches it, and three other charts on the page update too. How does a point get from the network to a pixel, and what happens to the work per frame as points keep coming?

A concept that helps here: Canvas or the DOMA concept that helps here: Batching UI updates

Arranging and resizing widgets. Someone drags a chart across a full dashboard and resizes another while the widgets keep refreshing. What does the page do on each pointer move, what does it draw, and when does the layout reach the server?

A concept that helps here: Drag and drop, and keeping orderA concept that helps here: Where state livesA concept that helps here: Conflict resolution on the client

One widget failing. One widget's query times out each time while the rest load, and a few minutes later the server starts answering HTTP 429. What does the person see in that widget and in the other widgets, and what does the page do next?

A concept that helps here: Partial failure in the UIA concept that helps here: Retries and dead-letter queuesA concept that helps here: Backpressure and load shedding

Concepts this guide uses

Sources

  1. Datadog engineering blog: Making fetch happen, building a general-purpose query and render scheduler
  2. Grafana docs: Query and transform data
  3. web.dev: Rendering performance
  4. web.dev: Optimize long tasks
  5. web.dev: Web Vitals
  6. MDN: Page Visibility API
  7. MDN: Prioritized Task Scheduling API
  8. MDN: Window: requestAnimationFrame() method
  9. MDN: Intersection Observer API
  10. MDN: ResizeObserver
  11. MDN: 429 Too Many Requests
  12. TradingView Lightweight Charts docs: Getting started
  13. react-grid-layout: README
  14. React docs: Catching rendering errors with an error boundary
  15. AWS Architecture Blog: Exponential Backoff And Jitter
Sign in to report a mistake