Skip to content

    Frontend System Design

    Front-End Case Study: Real-Time Analytics Dashboard

    Design a live metrics dashboard front end: event-time windows, late data, one update per frame, long series that stay fast and a pause control, with a lab.

    By Published 22 min read

    • frontend-system-design
    • case-study
    • dashboard
    • real-time
    Share

    What you'll learn: By the end of this case study you will be able to design the client side of a live metrics dashboard: group a stream of points into windows by the time they were measured, decide when a window is final and what to do with a point that arrives after that, keep memory bounded, update the screen once per frame instead of once per message, reduce a long series to what a chart can draw without losing a spike, and let the user pause a view that moves by itself.

    Think of the scoreboard at a marathon finish line. Timing mats send each runner's time to the operator, and the messages do not arrive in the order the runners crossed: one mat is on a slower cable. The operator does not repaint the board for every runner. They collect what came in, update the board every few seconds, and keep a rule for a time that shows up long after the race moved on. A dashboard is that board: a stream that arrives out of order, a rule for when a number is final, and a screen that must not repaint for every message.

    This is an educational reference design, not the verified internal architecture of any analytics product or company. The title names the shape of the product (a screen of charts that update by themselves); nothing here is claimed about how any vendor builds it. Every number is illustrative, and the lab at the end is a model with no network.

    The method (requirements, estimates, layers, deep dives, failure modes, a decision record) follows Front-End Case Study Method. The transport is treated in WebSockets in Depth and Server-Sent Events in Depth, and the way a stream enters React state in Real-Time Data in React State. This lesson is about what sits between the stream and the pixels when the data is numeric, ordered by time and endless.

    The core idea

    1. Time has two meanings. The time a value was measured (event time) and the time it reached the browser (arrival time) differ, and they differ by a different amount for every point. Windows, charts and "the last minute" are defined on event time; arrival order only tells you whether you missed something.
    2. A number is final when the clock of the data says so. Keep a window open for a short, fixed allowance after its end; after that, a point for it is counted and dropped, not folded in. The user sees a number change only when you decided it could.
    3. The screen is a function of a bounded summary, not of the stream. Points are folded into a limited number of windows, windows are reduced to about one bucket per few pixels, and the view updates once per frame. Cost then follows the screen, not the data rate.

    Three illustrations run through the lesson: a minimal example (a handful of points folded into windows), a realistic example (a wall monitor with eight panels showing the latency of a service) and a failure example (a producer whose clock jumps ahead).

    Requirements and scope

    Functional. A page of panels, each a line chart of one metric with a minimum-to-maximum band, a headline number for the latest window and a short table of the latest windows. A time range (the last 15 minutes by default, longer on request). A pause control. A visible state for "live", "paused" and "catching up".

    Non-functional. The page must stay responsive for hours on a wall monitor: memory must not grow without limit and a burst of messages must not freeze the tab. A spike lasting one window must be visible. The numbers must agree with the server's after a reconnect. The chart must be usable without sight and without a mouse.

    Out of scope here. Building queries, saving dashboards, alert rules, authentication and tenants, and everything on the server side: ingestion, storage and rollups (see Stream Processing Basics, Time-Series Databases and Analytics Pipelines, Lambda and Kappa). The client's job begins when points arrive. A different dashboard case, with sessions and money, is the banking dashboard.

    Illustrative sizing

    The numbers below are assumptions for reasoning, not measurements.

    Quantity Assumed value Why it matters
    Panels on screen 8 Each panel is its own subscriber of the same store
    Points per second per panel 20 160 messages a second across the page
    Window length 1 second One bucket of raw data on the chart
    Default range 15 minutes 900 windows per panel
    Longest range 24 hours 86,400 one-second windows: not something to hold or draw raw
    Chart width 800 CSS pixels At one bucket per 4 pixels, 200 buckets
    Frame rate 60 frames a second About 16 ms to do everything for a frame

    With these assumptions the page receives about 160 messages a second but needs to repaint at most 60 times, and a day of one-second windows is about 430 times more windows than the chart has buckets. Updates and drawing are decided by the screen; memory by how many windows you keep.

    The architecture: a bounded core between the stream and the panels

    Figure 1. The layers of a live dashboard client

    A live dashboard client: a stream feeds a queue, a pure core folds points into windows, panels read bucketsStream to Frame queue (points); Frame queue to Dashboard core (batch); Dashboard core to Panels (state); Dashboard core to Snapshot API (resync effect); Snapshot API to Dashboard core (snapshot)Stream: SSE or socketStreamSSE or socketFrame queue: one flush per frameFrame queueone flush perframeDashboard core: pure reducerDashboard corepure reducerPanels: thin ReactPanelsthin ReactSnapshot API: windows, rollupsSnapshot APIwindows, rollupspointsbatchstateresync effectsnapshot

    How to read this: the middle box is the only place with rules. The queue exists so that 160 messages a second become at most 60 updates a second. The snapshot API exists so that the core never has to guess what it missed: when it sees a gap it emits an effect, and the answer replaces its windows.

    The shape is the one used in the earlier chat case, for the same reason: a reducer that takes an event and returns the next state plus effects can be driven in a test with no socket, timer or DOM, including every awkward order of events. What differs is the data: a dashboard holds an aggregate of a stream, a bounded set of windows, and its hard questions are about time.

    Which transport

    A dashboard mostly listens, which fits a one-way channel such as Server-Sent Events; a WebSocket is justified when the client also sends a lot (subscribing to panels, changing filters). One cost of the WebSocket matters here. MDN states that the WebSocket interface "doesn't support backpressure", so when messages arrive faster than the application can process them it will either fill the device's memory by buffering them, become unresponsive at 100% CPU, or both. That is a reason to put your own queue and your own limits in front of the core, not to trust the socket to slow down. Heartbeats, Backpressure and Delivery Guarantees works through what a client can and cannot do about it.

    The data model

    The core keeps a small state. A point has three fields, a window has five, and everything else is a counter or a flag.

    Piece Meaning Rule
    Point seq (arrival order on this connection), t (event time), v (value) seq finds gaps; t chooses the window
    Window start, count, sum, min, max, revisions Aggregates, never the raw points; mean is derived as sum / count
    windows Ascending by start, at most maxWindows The oldest are evicted and counted
    maxEventTime Newest t seen Only ever moves forward; defines the watermark
    Counters duplicates, late, gaps, evicted They are the dashboard's own health numbers
    paused, frozen The view's mode and a copy of the windows at the moment of pausing The chart draws frozen while paused

    Storing aggregates, not points, bounds memory: a window with a million points costs the same as one with one. The price is that you cannot compute a different statistic later (a percentile needs another summary or the server's rollup), so choose the statistics before you discard the points.

    Figure 2. What the core does with an incoming point

    flowchart TD accTitle: Decision for an incoming point accDescr: Compare the sequence number with the last applied one. If it is not higher, drop the point as a duplicate. If it jumps ahead, record a gap and ask for a snapshot once. Then place the point by event time: if its window is already closed by the watermark, count it as late and drop it; otherwise fold it into the window and evict the oldest windows beyond the limit. A[Point arrives] --> B{seq compared with last applied} B -->|seq at most last| C[Drop, count as duplicate] B -->|seq jumps ahead| D[Count a gap, ask for a snapshot once] B -->|seq is next| E[Continue] D --> E E --> F{Window already closed by the watermark?} F -->|yes| G[Count as late, drop] F -->|no| H[Fold into its window] H --> I[Evict the oldest windows beyond the limit]

    How to read this: two different clocks are used on purpose. The sequence number answers "did I miss something", the event time answers "where does this belong, and is that place still open". A point can be perfectly in order on the connection and still be late.

    Windows, watermarks and late points

    A tumbling window of one second covers event times from a multiple of 1,000 ms up to the next. A point at 1,999 ms and one at 2,000 ms are in different windows even if they arrive together. That is the minimal example: group points by floor(t / windowMs), keep count, sum, min and max.

    When is a window final? The stream-processing literature has a name for the answer. Apache Flink's documentation distinguishes processing time, which is "the system time of the machine that is executing the respective operation", from event time, "the time that each individual event occurred on its producing device", and defines a watermark as a declaration that event time has reached time t, meaning there should be no more elements with a timestamp older than or equal to t. Elements that arrive after that are late. The lab uses the same idea in its simplest form: the watermark is the newest event time seen minus a fixed allowed lateness. A window whose end is at or before the watermark is closed.

    The allowed lateness is a product decision with a visible price.

    • Short (for example 500 ms). Numbers settle quickly, the headline number rarely changes after it was shown, and more points count as late and are dropped.
    • Long (for example 5 seconds). Fewer points are lost, but the newest windows are provisional for longer, and a headline number can change under the user's eyes.

    The state diagram shows what a window goes through.

    Figure 3. The life of one window

    stateDiagram-v2 accTitle: Lifecycle of a time window accDescr: A window is created by the first point that falls in it and stays open. While open, later points for it are folded in, and a point that arrives after a newer window already exists counts as a revision. When the watermark passes its end it is closed and later points for it are dropped and counted as late. It is evicted when the number of windows exceeds the limit. [*] --> Open: first point in this window Open --> Open: more points, revisions counted Open --> Closed: watermark passes the window end Closed --> Closed: late point, dropped and counted Closed --> Evicted: more than maxWindows kept Evicted --> [*]

    How to read this: only "Open" accepts points. Closed windows never change, which is the property the UI relies on: a number the user has read for a closed window will not move.

    The demo makes the rule concrete. It feeds seven points with one-second windows and two seconds of allowed lateness. The point numbered 5, measured at 1,700 ms, arrives after a point at 3,300 ms but while the watermark (1,300 ms) has not yet passed the end of window 1,000, so it is folded in and counted as a revision. The point numbered 7, measured at 1,800 ms, arrives after a point at 5,200 ms has moved the watermark to 3,200 ms, so window 1,000 is closed and the point is dropped and counted.

    Expected output, captured from a real run (Node 26.13.1; section 1):

    === 1. Windows by event time (1000 ms windows, 2000 ms allowed lateness)
      seq 1: t=1100 v=120
      seq 2: t=1400 v=80
      seq 3: t=2200 v=95
      seq 4: t=3300 v=110
      seq 5: t=1700 v=400 (late, but window 1000 is still open)
      seq 6: t=5200 v=100
      seq 7: t=1800 v=999 (window 1000 is closed by now)
          watermark 3200, late dropped 1, duplicates 0
          window 1000  n=3  mean= 200.0  max=400  revisions=1  closed
          window 2000  n=1  mean=  95.0  max= 95  revisions=0  closed
          window 3000  n=1  mean= 110.0  max=110  revisions=0  open
          window 5000  n=1  mean= 100.0  max=100  revisions=0  open

    A dropped late point still advances lastSeq, because it was received in order; only its aggregate is refused. The revision counter lets a panel mark a window "revised" instead of silently changing it.

    Gaps, duplicates and snapshots

    The sequence number is for the connection's order. A repeated or older number is a duplicate: drop it and count it. A jump is a gap: some points never arrived (a reconnect, a dropped frame, a server restart), so the aggregates may be too low. A client cannot fill the hole by guessing, and it should not stop drawing either. The reference rule: mark needsResync, emit one resync effect (not one per later point), keep drawing the best data you have with a visible notice, and when a snapshot arrives replace the windows with the server's. The server's aggregates are the truth; the client's are a running estimate between snapshots.

    This is the same snapshot-plus-replay rule as in the lab of Real-Time Data in React State (realtime-react-state), which also covers events that arrive before the first snapshot and the order in which to replay them. That lab shows the rule for keyed records; this lesson applies it to aggregates. Section 2 of the demo shows the numbers: six points were sent, four arrived, one was a repeat, and after the snapshot the count is six again.

    Figure 4. A gap and its repair

    sequenceDiagram accTitle: Gap detection and snapshot repair accDescr: The server sends points 1 and 2. Points 3 and 4 are lost. Point 5 arrives, so the core records a gap and emits one resync effect. Point 6 arrives and no second request is made. The snapshot API returns the server's windows and last sequence number, which replace the client's windows and clear the resync flag. participant S as Stream participant C as Dashboard core participant A as Snapshot API S->>C: point seq 1, 2 S--xC: seq 3, 4 lost S->>C: point seq 5 C->>A: resync after seq 2 (once) S->>C: point seq 6 (no second request) A-->>C: windows and lastSeq 6 C->>C: replace windows, clear needsResync

    How to read this: the core never waits. It keeps folding points and shows a notice while the snapshot is in flight; the snapshot then replaces the estimate. Points that arrive with a sequence number at or below the snapshot's lastSeq are duplicates by construction.

    One update per frame

    At 160 messages a second, one state change and one render per message means up to 160 renders a second for a screen that can show 60. The fix is to separate receiving from applying. receive puts the point in a queue and asks for one flush; the flush applies everything queued with the pure reducer and notifies subscribers once. MDN describes requestAnimationFrame as asking the browser to call a callback before the next repaint, at a frequency that "will generally match the display refresh rate", and says it is one-shot, so the callback must ask again for the next frame. The lab injects the scheduler (a real app passes requestAnimationFrame; the test passes a function it calls by hand), which keeps the logic free of the browser.

    On the React side the store is read with useSyncExternalStore. Its documentation requires that, while the store has not changed, repeated calls to getSnapshot return the same value, and that the snapshot is immutable. That is why the reducer returns the same state object when an event changes nothing, and a new object, with new window objects only for the windows that changed, when it does. A panel that reads only one window can then skip a render when other windows change.

    The demo feeds 1,200 points, 20 per frame, through two stores. They end with identical windows; what differs is the number of times subscribers are told.

    Expected output, captured from a real run (Node 26.13.1; section 3):

    === 3. 1200 points, 20 per frame, 60 frames
      one flush per frame:  applied 1200, subscribers notified 60 times
      one flush per point:  applied 1200, subscribers notified 1200 times
      same windows either way: true (61 windows)

    Sixty notifications instead of 1,200 for the same data is the argument; renders and layout are what a real page pays for, and the lab does not measure them.

    What about a hidden tab? MDN notes that requestAnimationFrame() calls are paused in most browsers in background tabs and hidden iframes, to improve performance and battery life. So the queue stops draining while the tab is hidden, and a naive design lets it grow. The reference rule is to keep folding points into the bounded windows (that is cheap and bounded) and to skip the repaint; when the page becomes visible, one flush shows the current state. If the queue itself could grow, bound it too, and when it overflows, prefer a snapshot to a long replay.

    Drawing a long series

    A chart that is 800 pixels wide cannot show 86,400 points; it can show a few hundred. The reduction has to be chosen, because the obvious one is wrong. Taking every tenth value is cheap and loses any spike that falls between samples, and for a latency or error dashboard the spike is the reason the dashboard exists.

    The reference reduction is an envelope. Group consecutive windows into at most one bucket per few pixels; for each bucket keep the lowest minimum, the highest maximum and a mean weighted by point count (not an average of window means, which overweights sparse windows). Draw the mean as a line and the minimum-to-maximum range as a band. A one-window spike is then the top of its bucket's band whatever the zoom. The bucket count follows the width of the chart, not the amount of data.

    Figure 5. From windows to pixels

    From windows to pixels: bounded windows are bucketed by chart width, turned into a path and a tableWindows to Envelope (buckets); Envelope to Path data (scale); Path data to Chart (draw); Windows to Text table (latest rows)Windows: bounded, ascendingWindowsbounded,ascendingEnvelope: min, max, meanEnvelopemin, max, meanPath data: one point per bucketPath dataone point perbucketText table: latest windowsText tablelatest windowsChart: SVG or canvasChartSVG or canvasbucketsscaledrawlatest rows

    How to read this: the only wide arrow is the first one. After the envelope the data is as small as the screen, so the cost of the rest does not depend on how long the dashboard has been open. The table is not decoration: it is the text alternative of the chart.

    The demo builds 600 one-second windows with one spike, reduces them to 60 buckets for a 240-pixel chart, and compares the two reductions. The envelope keeps the highest value in the data; every tenth window's mean misses it.

    Expected output, captured from a real run (Node 26.13.1; section 4):

    === 4. 600 windows, one spike, drawn in a 240 px wide chart (60 buckets)
      windows kept: 600, buckets drawn: 60, windows per bucket: 10
      highest value in the data:           950
      highest max drawn by the envelope:   950
      highest value drawn by every 10th:   112
      path coordinates, one per window:    600
      path coordinates, one per bucket:    60

    SVG or canvas is a real choice and the lab does not make it for you. An SVG path with a few hundred coordinates is cheap, accessible by attribute and easy to test as a string, which is why the lab returns path data. Thousands of marks, or several redraws a second, are where a canvas pays off; MDN's canvas optimization notes recommend, among other things, batching calls (drawing a polyline instead of many separate lines) and rounding coordinates to integers to avoid sub-pixel rendering.

    For long ranges the cheaper answer is not to reduce on the client at all. A 24-hour view should ask the server for rollups at a coarser window (one-minute windows give 1,440 for a day) and then bucket those. If aggregation does become heavy on the client, Web Workers and Offloading covers moving it off the main thread, and The Event Loop and the Main Thread explains why it matters.

    Pausing a view that moves by itself

    A chart that updates by itself is an accessibility and usability problem. WCAG 2.2 success criterion 2.2.2 requires, for auto-updating information that starts automatically and is presented in parallel with other content, a mechanism for the user to pause, stop or hide it or to control the frequency of the update, unless the updating is essential. The Understanding document adds a caution that fits this design: pausing is misleading if the content shows old information when it restarts.

    The reference behaviour has three parts. Pause freezes the view, not the collection: the chart draws a copy of the windows taken at the moment of pausing, while the core keeps folding points into the live windows. Resume jumps to the present, so nothing stale is shown after a restart. The page says which mode it is in ("Paused: the chart is frozen, new data is still being collected") in a status region, so the state is not carried by colour or by the shape of a button alone. Section 5 of the demo prints the drawn and collected window counts to make the difference visible; the React test clicks Pause and Resume and checks the table.

    Accessibility of a chart

    A chart drawn as an SVG is an image to a screen reader, so it needs a name and a description. The Understanding document for success criterion 1.1.1 recommends, for a chart, a short text alternative that identifies the content, a longer description with a summary of the data and, where possible, the data in a table. The lab does both: the SVG has role="img" and an aria-label that says how many windows and buckets it shows, and a real table with a caption lists the latest windows, with row headers.

    One caution: do not announce every update. A live region that speaks 60 times a second is unusable; announce changes of mode (live, paused, catching up) and at most a headline number that changed enough to matter. Pause, Resume and the range picker are ordinary buttons in the tab order. More on live regions is in Accessible Forms and Dynamic Content and Keyboard, Focus and Screen Readers.

    Build it: the dashboard core and a thin React layer

    Goal. Drive the core through windows and lateness, a gap and its snapshot, batched flushes, a long series with a spike, and a pause, and read what it returns.

    Setup. The lab realtime-analytics-dashboard is in the course's example workspace (Node 26). It does not duplicate the others: realtime-react-state handles keyed records, snapshot and replay; list-virtualization windows DOM rows; heartbeat-backpressure models a connection and a sender that must slow down. Here the data is a numeric series. The logic is one pure function, step(state, event), with pure helpers for buckets and path data; a small store batches input; the React component Dashboard reads it with useSyncExternalStore. Nothing runs against a network or a real browser.

    cd examples/frontend
    pnpm install
    cd labs/realtime-analytics-dashboard
    pnpm test           # 33 tests: 23 for the core, 5 for the store, 5 React (jsdom)
    node src/demo.ts

    Steps.

    1. Run the tests, then the demo, and compare section 1 above with your output: window 1,000 has three points and one revision, and exactly one point was dropped as late.
    2. Read section 2: a gap produced one resync effect, the repeat was counted, and after the snapshot six points are counted.
    3. Compare sections 3 and 4 with the blocks above: the windows are identical whether you flush per frame or per point, and the envelope's maximum equals the data's.
    4. Read section 5: after Pause the chart shows 2 windows while 4 are collected; after Resume it shows 4.

    What the lab does not show. No real socket, no real timing, no real rendering (jsdom does no layout or painting, so nothing says how fast a chart draws), no server and no persistence. The seq, snapshot and resync protocol is this lab's own, not any product's. A single metric is modelled; percentiles, multiple metrics with different watermarks and zoom are not.

    Break it. In src/series.ts, in downsampleEnvelope, replace max = Math.max(max, w.max); with max = group[0]!.max;. Each bucket then reports only its first window's maximum; two tests fail and section 4 prints 112 as the highest maximum drawn instead of 950. Restore the line and run the tests again.

    Trade-offs

    Decision Option A Option B Reference choice
    Which time defines a window Arrival time Event time Event time; arrival order only finds gaps
    When a window is final Never (always accept) Watermark with allowed lateness Watermark; late points counted, not applied
    Allowed lateness Short Long Product decision; show revisions when long
    Keep Raw points Aggregates per window Aggregates; raw points stay on the server
    Update cadence Per message Once per frame Once per frame, with a bounded queue
    Long ranges Reduce a day of windows in the browser Ask the server for rollups Rollups from the server, then bucket
    Reduction Every k-th value Min, max and mean per bucket Envelope: spikes survive
    Drawing SVG path Canvas SVG for hundreds of marks; canvas for thousands
    Gap Ignore Resync from a snapshot Resync once, with a visible notice
    Auto-updating view Always live Pause freezes the view, collection continues Pause plus resume to live

    In practice: a wall dashboard that froze every Monday

    NOTE

    This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.

    The situation

    An operations team keeps a wall monitor of eight latency charts open all week. By Monday morning the page is slow and sometimes the tab crashes. After a network blip the headline numbers jump for a few seconds. Someone also noticed that the number for the previous minute sometimes changes after it was read out in a meeting.

    Starting architecture

    Figure 6. Starting point: every message is a render, every point is kept

    Starting architecture: every message calls setState on the page, and every raw point is kept in an arraySocket to Page state (every message); Page state to Charts (full redraw)Socket: one message per pointSocketone message perpointPage state: array of raw pointsPage statearray of rawpointsCharts: draw every pointChartsdraw every pointevery messagefull redraw

    How to read this: nothing in the path bounds memory, batches work or says when a number is final, so cost grows with the time the tab has been open.

    Options considered

    Option What it fixes What it costs Risk
    Cap the array and slice the last N points Memory Cheap Still one render per message; the chart still draws every kept point
    Throttle chart updates to once a second CPU Cheap Hides cost, does not bound memory, and a spike between updates can be lost
    Windows, watermark, per-frame flush and envelope buckets in a pure core Memory, CPU, jumps and revisions A small core with tests, and a snapshot endpoint The server must provide a snapshot and a stable seq

    The decision

    Field Decision record
    Context A wall dashboard degrades over days, numbers move after being read, and reconnects cause jumps.
    Decision Fold points into one-second windows keyed by event time, close a window two seconds after its end, keep at most 900 windows, flush once per frame, draw bucketed envelopes, and resync from a server snapshot after a gap.
    Consequences, good Memory and per-frame work no longer grow with uptime; a spike stays visible; a read number does not change once closed.
    Consequences, bad Points later than the allowance are dropped (and counted); the server contract grows (seq, snapshot); there is a core to maintain.
    Revisit when The product needs percentiles (a different summary) or ranges longer than the server's rollups can serve.

    Rollout and verification

    1. Replay recorded streams through the reducer in a test, including a reconnect with a gap, a duplicate burst and late points, and compare its windows with the server's aggregates for the same period.
    2. Ship the snapshot endpoint first, so old clients keep working and the new client has something to resync from.
    3. Watch four counters per panel: late points dropped (a few are normal, a rise means the allowance is too short or a producer is slow), gaps and resyncs, windows kept (must stay at the limit, not above) and flush time.

    The 2 a.m. failure

    A producer host is restarted with its clock an hour ahead (illustrative). Its points carry event times in the future, so the newest event time jumps and the watermark follows: every window of the real present is now "closed", and every following point from healthy hosts is counted as late and dropped. The charts go flat and the late counter climbs at the full message rate.

    First three checks: (1) is the late-point counter rising on every panel at once; (2) is maxEventTime far ahead of the current time; (3) did a single source start sending timestamps in the future. Mitigation: discard points whose event time is more than a small tolerance ahead of the receive time, and replace the windows with a snapshot, which resets the position. Follow-up: the watermark should be advanced only by sources that are trusted to have sane clocks, or be derived from receive time with a bounded skew; treating "newest timestamp wins" as safe is the bug.

    The other side of this topic

    On the back end the same questions are asked of a pipeline: how events are windowed and when state is emitted, how late data is handled, what is stored as rollups and how long. See Stream Processing Basics, Time-Series Databases and Ad Click Aggregation. The client's windows are only as good as the server's promises about sequence numbers, snapshots and the clocks of the sources.

    Architect's notes

    • Decide the clock first. Which time defines a window, who sets it, how late a point may be and what the user sees when one is dropped.
    • Bound everything. Windows, queue, buckets and path size each need a limit and a counter that says when it is hit.
    • Prefer a snapshot to a long replay after a gap or an overflow.
    • Show uncertainty. A revised window, a paused view and a missed gap are states; say so on the page.
    • Test event orders, not components: a late point after a newer window, a repeat after a snapshot, a gap during a pause.

    Common mistakes

    • Using arrival time for windows, so a slow link reshuffles history.
    • Letting the newest timestamp define "now" unchecked: one bad clock closes every window.
    • Keeping raw points forever, so memory grows with uptime.
    • One render per message, when the screen shows at most 60 states a second.
    • Taking every k-th value for the chart, which loses the spike.
    • Averaging window means instead of weighting by count.
    • Changing a closed number silently.
    • A live region that announces every update.
    • Pausing the data instead of the view, or resuming into stale numbers.

    Key takeaways

    • Windows are keyed by event time; the sequence number only finds gaps.
    • A watermark, the newest event time minus an allowance, decides when a window is final; later points are counted, not applied.
    • Keep aggregates in a bounded set of windows; ask the server for rollups for long ranges.
    • Receive and apply are separate: queue the stream, flush once per frame, return the same state when nothing changed.
    • Reduce a series with a min, max and mean envelope tied to chart width, so spikes survive and cost follows the screen.
    • Pause the view, not the collection, and resume to the present.
    • Put the rules in a pure core with effects, so the awkward orderings are unit tests.

    Practice exercises

    1. Future timestamps. Add a guard to the reducer: a point whose t is more than a configured tolerance ahead of a receivedAt carried by the event is dropped and counted. Write the test first, using the 2 a.m. scenario.
    2. Lateness trade-off. Run the same recorded stream with allowances of 0.5 and 5 seconds and compare the late count with the number of revisions. Which would you ship to a wall monitor, and which to a page people read in meetings?
    3. Percentiles. sum and count cannot give a 95th percentile. Describe two other summaries a window could hold and what each costs in memory and accuracy.
    4. Hidden tab. Replace the scheduler with one that skips flushes while the page is hidden and bound the queue. What should happen on overflow?
    5. Accessibility pass. Write what a screen reader announces on load, on a mode change and on a headline change, and decide which must be silent.

    Official documentation

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments