Complete guide to building real-time dashboards with streaming data.
npx clawhub@latest install realtime-dashboard
┌─────────────────────────────────────────────────────────────┐
│ Data Sources │
│ APIs, Databases, Message Queues │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Backend Services │
├─────────────────────────────────────────────────────────────┤
│ Kafka (durable) │ Redis Pub/Sub (real-time) │
│ See: dual-stream-architecture │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ WebSocket/SSE Gateway │
│ See: websocket-hub-patterns │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ React Application │
├─────────────────────────────────────────────────────────────┤
│ Real-time Hooks │ Data Visualization │
│ See: realtime-react-hooks│ See: financial-data-visualization
├─────────────────────────────────────────────────────────────┤
│ Animated Displays │ Connection Handling │
│ See: animated-financial │ See: resilient-connections │
└─────────────────────────────────────────────────────────────┘
Set up dual-stream publishing for durability + real-time.
Read: ai/skills/realtime/dual-stream-architecture
func (p *DualPublisher) Publish(ctx context.Context, event Event) error {
// 1. Kafka: Must succeed (durable)
err := p.kafka.WriteMessages(ctx, kafka.Message{...})
if err != nil {
return err
}
// 2. Redis: Best-effort (real-time)
p.publishToRedis(ctx, event)
return nil
}
Create horizontally-scalable WebSocket connections.
Read: ai/skills/realtime/websocket-hub-patterns
type Hub struct {
connections map[*Connection]bool
subscriptions map[string]map[*Connection]bool
redisClient *redis.Client
}
// Lazy Redis subscriptions
func (h *Hub) subscribeToChannel(conn *Connection, channel string) {
// Only subscribe to Redis on first local subscriber
}
Connect React to real-time data.
Read: ai/skills/realtime/realtime-react-hooks
const { data, isConnected } = useSSE({
url: '/api/events',
onMessage: (data) => updateState(data),
});
// Or with SWR integration
const { data } = useRealtimeData('metrics', fetchMetrics);
Handle connection failures gracefully.
Read: ai/skills/realtime/resilient-connections
const { isConnected, send } = useWebSocket({
url: 'wss://api/ws',
reconnect: true,
maxRetries: 5,
onMessage: handleMessage,
});
Build dark-themed financial charts.
Read: ai/skills/design-systems/financial-data-visualization
<PriceChart
data={priceHistory}
isPositive={change >= 0}
/>
Add smooth number animations.
Read: ai/skills/design-systems/animated-financial-display
<AnimatedNumber value={price} prefix="$" decimals={2} />
<FlashingValue value={value} formatter={formatCurrency} />
| Skill | Purpose |
|---|---|
| ------- | --------- |
dual-stream-architecture | Kafka + Redis publishing |
websocket-hub-patterns | Scalable WebSocket server |
realtime-react-hooks | SSE/WebSocket React hooks |
resilient-connections | Retry, circuit breaker |
financial-data-visualization | Chart theming |
animated-financial-display | Number animations |
Never wait for all data. Show immediately, improve progressively:
Phase 1: Initial data + hints → Immediate display
Phase 2: Background refinement → Prices update in place
Phase 3: Historical data → Charts populate
Never zero out data when refinement fails. Only update when you have better data.
Always show users their connection state:
<ConnectionStatus isConnected={isConnected} />
共 1 个版本