Admit + authorize
The request crosses routing, limits and application authorization before the feed starts.
Product knowledge · Advanced · Realtime sessions
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
| Shape | Contract | Use when |
|---|---|---|
| Response stream | One HTTP response, server → client, bounded chunks and optional trailers. | Sequential bytes, export or incremental generation that ends. |
| SSE | One HTTP event stream, server → client, typed event fields. | A notification/feed where the client need not send messages on the channel. |
| WebSocket | HTTP 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
The request crosses routing, limits and application authorization before the feed starts.
Use the connector helper/value; Core owns HTTP framing and transport state.
Submit bounded events only when writable; producer and source queue remain application-owned.
Normal end, disconnect, timeout and drain all stop the producer and release retained state.
03 · SSE event fields
04 · WebSocket lifecycle
Validate route, origin/credentials under application policy and requested subprotocol. A plain GET is not a WebSocket client.
A session exists only after accepted upgrade. Transport authentication still does not replace business authorization.
Consume or copy borrowed payloads within connector lifetime; bound pending output, handler tasks and app queues.
Close handshake, peer abort, cancel and service drain converge on one idempotent cleanup owner.
05 · Frames and messages
Treat decoded text as untrusted application input; text is not automatically JSON or a valid schema.
Application defines byte media/schema; copy borrowed payload before retaining it.
Session control/progress evidence; not fresh business liveness or authorization.
Protocol close intent/reason; application still cleans its tasks, subscriptions and retained state.
06 · Bounds and pressure
| Boundary | When full or slow |
|---|---|
| Concurrent sessions | Refuse or shed admission; never create unlimited owners/subscriptions. |
| Frame/message bytes | Reject or close with a typed limit outcome; never collect past the ceiling. |
| Pending output | Wait for bounded writability, coalesce/drop only when business semantics allow, or close. |
| Application source queue | Application chooses finite capacity and overflow law; Core pressure cannot bound this queue for it. |
| Progress/idle/drain time | Use a finite monotonic deadline; timeout proves neither peer processing nor completed cleanup. |
07 · Reconnect and resume
Client reconnects under bounded policy. Application may use an event ID/cursor with its own replay store; without one, the feed follows current policy.
A new handshake creates a new session. Resume token, sequence, dedupe and subscription restore are application protocol.
Disconnect does not prove the last event/message did not arrive. Side-effecting commands need idempotency or reconciliation before retry.
Bound attempts, total time and jitter in client/application policy; server admission must withstand reconnect storms.
08 · Finite drain
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 escalationLoad-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
| Failure | Owner action |
|---|---|
| Capability unavailable | Fail closed or disable the route for that target; never silently substitute another contract. |
| Handshake/auth/subprotocol refusal | Application returns a public-safe HTTP refusal before upgrade; never create a fake session. |
| Session/frame/output limit | Refuse, shed or close with typed evidence; never mask it with a hidden queue. |
| Peer disconnect/abort | Cancel producers/subscriptions and release borrowed/retained state; business delivery may be ambiguous. |
| Drain/close timeout | Keep service and application ownership reachable; timeout never permits freeing live state. |
10 · Integration checklist