Product knowledge · Advanced · Realtime sessions

Realtime does not make long sessions unlimited.

Choose a response stream for sequential bytes, SSE for one-way events and WebSocket for a bidirectional session. All three still require admission, authorization, pressure, cancellation and finite shutdown.

01 · Choose the interaction

Choose by data direction and lifecycle

ShapeContractUse when
Response streamOne HTTP response, server → client, bounded chunks and optional trailers.Sequential bytes, export or incremental generation that ends.
SSEOne HTTP event stream, server → client, typed event fields.A notification/feed where the client need not send messages on the channel.
WebSocketHTTP handshake, then an upgraded bidirectional session with typed frames.Client and server both need to send messages in one session.

API presence does not prove a provider is active. Read effective capability from the exact loaded package before advertising a realtime endpoint.

02 · SSE lifecycle

SSE is a typed event stream, not concatenated text

1

Admit + authorize

The request crosses routing, limits and application authorization before the feed starts.

2

Start the SSE response

Use the connector helper/value; Core owns HTTP framing and transport state.

3

Produce events

Submit bounded events only when writable; producer and source queue remain application-owned.

4

Finish/cancel

Normal end, disconnect, timeout and drain all stop the producer and release retained state.

03 · SSE event fields

Every field has a meaning; none creates replay by itself

data
Event payload; multiline data remains one typed event under the helper contract. Application chooses codec and schema.
event
Optional event type for client dispatch; it does not replace authorization or payload versioning.
id
Optional application cursor/identity usable by a resume protocol; Core does not retain event history merely because an ID exists.
retry
Optional client reconnect-delay hint; not a server retry, delivery guarantee or unlimited reconnect loop.

04 · WebSocket lifecycle

Authorize before upgrade; ownership and terminals remain afterward

1

Handshake request

Validate route, origin/credentials under application policy and requested subprotocol. A plain GET is not a WebSocket client.

2

Accept upgrade

A session exists only after accepted upgrade. Transport authentication still does not replace business authorization.

3

Read/write frames

Consume or copy borrowed payloads within connector lifetime; bound pending output, handler tasks and app queues.

4

Close/abort

Close handshake, peer abort, cancel and service drain converge on one idempotent cleanup owner.

05 · Frames and messages

Frame kind does not replace the business contract

Text

Treat decoded text as untrusted application input; text is not automatically JSON or a valid schema.

Binary

Application defines byte media/schema; copy borrowed payload before retaining it.

Ping / pong

Session control/progress evidence; not fresh business liveness or authorization.

Close

Protocol close intent/reason; application still cleans its tasks, subscriptions and retained state.

06 · Bounds and pressure

A long session still has a finite budget

BoundaryWhen full or slow
Concurrent sessionsRefuse or shed admission; never create unlimited owners/subscriptions.
Frame/message bytesReject or close with a typed limit outcome; never collect past the ceiling.
Pending outputWait for bounded writability, coalesce/drop only when business semantics allow, or close.
Application source queueApplication chooses finite capacity and overflow law; Core pressure cannot bound this queue for it.
Progress/idle/drain timeUse a finite monotonic deadline; timeout proves neither peer processing nor completed cleanup.

07 · Reconnect and resume

A new connection does not automatically continue the old one

SSE reconnect

Client reconnects under bounded policy. Application may use an event ID/cursor with its own replay store; without one, the feed follows current policy.

WebSocket reconnect

A new handshake creates a new session. Resume token, sequence, dedupe and subscription restore are application protocol.

Ambiguous delivery

Disconnect does not prove the last event/message did not arrive. Side-effecting commands need idempotency or reconciliation before retry.

Backoff

Bound attempts, total time and jitter in client/application policy; server admission must withstand reconnect storms.

08 · Finite drain

Graceful never means waiting forever for realtime sessions

remove instance from new-traffic selection
  → stop new realtime admission
  → stop or quiesce application producers
  → request bounded SSE finish / WebSocket close
  → wait for terminals within a monotonic drain deadline
  → close only after owned readers/tasks converge

deadline/refusal → report failure → keep owner reachable → operator escalation

Load-balancer removal stops new selection only; existing keep-alive, SSE and WebSocket sessions may remain. Deployment needs spare capacity, reconnect policy and an outer stop budget.

09 · Failure law

Keep handshake, session and lifecycle failures distinct

FailureOwner action
Capability unavailableFail closed or disable the route for that target; never silently substitute another contract.
Handshake/auth/subprotocol refusalApplication returns a public-safe HTTP refusal before upgrade; never create a fake session.
Session/frame/output limitRefuse, shed or close with typed evidence; never mask it with a hidden queue.
Peer disconnect/abortCancel producers/subscriptions and release borrowed/retained state; business delivery may be ambiguous.
Drain/close timeoutKeep service and application ownership reachable; timeout never permits freeing live state.

10 · Integration checklist

Before choosing a language API