Skip to content

Real-time Push (SSE) ​

The admin dashboard and user portal subscribe to events via SSE (Server-Sent Events) without polling.

Endpoints ​

Admin ​

bash
curl -N -H "Authorization: Bearer $TOKEN" \
  "http://YOUR_HOST:8080/v1/admin/sse?topics=hosts,tasks,image-status"

User ​

bash
curl -N -H "Authorization: Bearer $TOKEN" \
  "http://YOUR_HOST:8080/v1/user/sse?topics=hosts,tasks"

Parameters ​

ParameterDescription
topicsComma-separated topic list: hosts, tasks, image-status

Event Format ​

Each event is a line of JSON:

json
event: message
data: {"topic":"tasks","action":"update","id":"task-uuid"}
FieldDescription
topicEvent topic
actionupdate, create, or delete
idAssociated resource ID (optional)
payloadAdditional payload (optional)

Frontend Integration ​

typescript
const eventSource = new EventSource(
  '/v1/admin/sse?topics=hosts,tasks',
  { headers: { Authorization: `Bearer ${token}` } }
);

eventSource.onmessage = (event) => {
  const data = JSON.parse(event.data);
  queryClient.invalidateQueries({ queryKey: [data.topic] });
};

Implementation ​

The SSE broadcast system lives in internal/broadcast/sse.go and uses a topic-based pub/sub model. The control plane publishes events to topics when resources change. Each connection maintains an independent subscription channel and is cleaned up automatically on disconnect.

SSE vs Polling ​

ApproachLatencyLoadBest For
SSEReal-timeLow (event-driven)Host status, task progress
PollingSecondsHigh (fixed frequency)Dashboard stats

Use SSE for admin list pages and on-demand refresh for dashboard statistics.