System Design: Real-Time Analytics & Live Dashboard
System design architecture for high-frequency live dashboards (e.g. Robinhood trading, Datadog metrics, Uber driver tracker) handling 1,000+ updates/sec without frame drops, state bloat, or memory leaks.
Why it matters in interviews
Visual & Interactive Explanation
Real-Time High-Throughput Streaming Architecture
Sequence & Data Exchange Flow
1. HTTP GET /api/snapshot -> Initial table state
2. Returns initial 10,000 records (SSR/JSON)
3. Opens WS wss://stream.example.com (500 msgs/sec)
4. Continuous binary Protobuf tick stream
5. Batched rAF postMessage payload every 16ms (60 FPS)
Zero main-thread JSON parsing lag!
Code Examples & Implementation
import { create } from 'zustand';
interface StockStore {
prices: Record<string, number>;
updatePrices: (batch: Record<string, number>) => void;
}
export const useStockStore = create<StockStore>((set) => ({
prices: {},
updatePrices: (batch) =>
set((state) => ({ prices: { ...state.prices, ...batch } })),
}));
// High-frequency WebSocket listener with 16ms rAF batching
let pendingBatch: Record<string, number> = {};
let rafScheduled = false;
export function connectStockSocket() {
const ws = new WebSocket('wss://stream.marketdata.com');
ws.onmessage = (event) => {
const { symbol, price } = JSON.parse(event.data);
pendingBatch[symbol] = price; // Enqueue tick into buffer
if (!rafScheduled) {
rafScheduled = true;
requestAnimationFrame(() => {
// Flush all ticks accumulated during this 16ms frame in ONE single React update!
useStockStore.getState().updatePrices(pendingBatch);
pendingBatch = {};
rafScheduled = false;
});
}
};
}Interview-Ready Answers
A real-time dashboard uses WebSocket (bi-directional) or SSE (uni-directional stream). High-frequency ticks are batched in an in-memory ring buffer and flushed at 60fps via requestAnimationFrame to a normalized store to avoid re-rendering parent containers.
Official Documentation & Specifications
Follow-up Questions & Deep Dives
Common Mistakes & Anti-Patterns
- Calling `setState` directly on every single WebSocket packet, crashing React with 500 re-renders/sec
- Storing unstructured arrays requiring O(N) searches instead of normalized key-value maps (`byId`)
- Not implementing heartbeats (ping/pong) to detect silent network drops
Real-World Architectural Scenario
Design the live driver tracking screen for Uber during high-volume rush hour. 10,000 drivers move on the map simultaneously. How do you ensure smooth 60fps rendering?
Rate Your Readiness
Rate how comfortably you can explain this in an interview to update your global readiness gauge: