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
- The problem
- Clarifying questions
- The requirements menu
- Non-functional requirements
- Core entities
- The API
- The high-level design
- What breaks first
- The deep dives
- Entity fields
- A hundred widgets asking for data at once
- Charts that keep up with live data
- Arranging and resizing widgets
- One widget failing
- Variants
- What each level is expected to show
- The 30-second answer
- Quiz
- Datadog
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
| Ask | Why it matters | A 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. |
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. |
Non-functional requirements
| Requirement | What 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
| Entity | What 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
| Endpoint | Notes |
|---|---|
| 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. |
| One call per widget per refresh, sent through the query scheduler. |
| 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. |
| 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
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.
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: Scheduling work on the main thread
A concept that helps here: Backpressure and load sheddingA concept that helps here: List virtualizationCharts 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: Downsampling and rollups
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?
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?
Concepts this guide uses
- Scheduling work on the main thread
- Backpressure and load shedding
- List virtualization
- Canvas or the DOM
- Batching UI updates
- Downsampling and rollups
- Drag and drop, and keeping order
- Where state lives
- Conflict resolution on the client
- Partial failure in the UI
- Retries and dead-letter queues
Sources
- Datadog engineering blog: Making fetch happen, building a general-purpose query and render scheduler
- Grafana docs: Query and transform data
- web.dev: Rendering performance
- web.dev: Optimize long tasks
- web.dev: Web Vitals
- MDN: Page Visibility API
- MDN: Prioritized Task Scheduling API
- MDN: Window: requestAnimationFrame() method
- MDN: Intersection Observer API
- MDN: ResizeObserver
- MDN: 429 Too Many Requests
- TradingView Lightweight Charts docs: Getting started
- react-grid-layout: README
- React docs: Catching rendering errors with an error boundary
- AWS Architecture Blog: Exponential Backoff And Jitter