Book 6 · Lesson 6.2
TanStack Query and live metrics
- Read createQuery in Dashboard.tsx
- Contrast 5s poll vs SSE live feed
- Handle analyzer unreachable state
Prerequisites: 6.1 · 1.14
Dashboard uses two channels for “live” data:
| Channel | API | Updates |
|---|---|---|
| TanStack Query | GET /api/metrics/summary | Stat cards every 5s |
| EventSource SSE | /api/events/stream | Activity table rows |
TanStack Query
GET /api/metrics/summary · 5s poll
total_events: 42
Polls: 0SSE live feed
EventSource team_event · Redis pub/sub
Live rows: 0createQuery(() => ({
queryKey: ["metrics-summary"],
queryFn: fetchMetricsSummary,
refetchInterval: 5000,
}));
See apps/radar/src/api/client.ts.
Teach-back prompt
Why not poll SSE every 5 seconds instead?
Radar metrics poll
Lab complete — nice work.