Design a Real-Time Analytics Dashboard
The Prompt
Design a real-time analytics dashboard for a SaaS product. It shows metrics, charts, and tables with data that updates every 5 seconds. The dataset contains 100K+ rows.
Key Challenges
- Volume â rendering thousands of data points performantly
- Real-time â data updates without full page refreshes
- Interaction â filtering, sorting, date ranges, drill-down
- Responsiveness â works on desktop and tablet
Architecture
Data Layer
WebSocket connection â Normalized store â Derived views â UI- WebSocket for real-time updates (fall back to polling)
- Normalized store keyed by metric ID for O(1) updates
- Derived views computed via selectors (memoized)
Rendering Strategy
For charts with 100K+ points:
- Canvas rendering â D3 + Canvas for large datasets (not SVG)
- Data windowing â only render visible time range
- Aggregation â server-side pre-aggregation for zoomed-out views
- Progressive loading â show summary first, load details on zoom
For tables:
- Virtualization â only render visible rows (react-window or TanStack Virtual)
- Pagination â server-side for datasets > 10K
- Sticky headers â always visible column headers
Update Strategy
function useDashboardSocket(dashboardId) {
const queryClient = useQueryClient();
useEffect(() => {
const ws = new WebSocket(`wss://api/dashboards/${dashboardId}/stream`);
ws.onmessage = (event) => {
const update = JSON.parse(event.data);
queryClient.setQueryData(
['metrics', update.metricId],
(old) => mergeMetricUpdate(old, update)
);
};
return () => ws.close();
}, [dashboardId, queryClient]);
}Performance Budget
| Metric | Target |
|---|---|
| Initial load | < 2s |
| Chart re-render | < 16ms (60fps) |
| Filter response | < 100ms |
| Memory usage | < 200MB |
Trade-offs to Discuss
- WebSocket vs SSE vs Polling â WebSocket for bidirectional, SSE for one-way, polling for simplicity
- Canvas vs SVG â Canvas for performance, SVG for interactivity and accessibility
- Client vs server aggregation â server for scale, client for flexibility
The senior insight: a dashboard is a data pipeline with a UI layer. Design the data flow first, then the rendering.