← Docs
Recipe

Server-Sent Events design

Unidirectional real-time streaming from Meridian backend to dashboard clients over a single long-lived HTTP connection.

Connection lifecycle

Client opens GET /api/sse/events withAccept: text/event-stream. Server holds the connection open and writes framed messages.

Event framing

Each event carries an event: type, an id: for Last-Event-ID replay, and a JSON data: payload. Double newline terminates each message.

Reconnection

Browser EventSource auto-reconnects with exponential backoff. Server sendsretry: 3000to override the default 3-second interval.

Vercel edge caveats

Edge functions enforce a 30-second max duration. Use a Node.js runtime route with streaming Responseand a keep-alive heartbeat every 15 seconds.

Auth guard

Validate the session cookie or bearer token before upgrading to the SSE stream. Return 401 immediately for unauthenticated requests — do not hold the connection.