Short answer: keep the watchlist token short-lived, make expiry an explicit state transition, and test that transition with a fake clock and a replayable event log. The client should never infer authorization from whether a socket happens to be open.

In a stock trading watchlist, a live poll is a deceptively small feature. Prices arrive while a user edits symbols, the session token expires, and the UI must say what is still trustworthy. A stale quote is annoying; a stale permission boundary is a ledger problem waiting to happen.

Start with the bill, then decide what to retain

The largest recurring term is usually event delivery, not token issuance. A useful first estimate is subscribers × updates per second × encoded bytes per update; it gives the team a concrete number to measure before debating transports. Token minting and refresh calls are comparatively sparse, while retaining every transient quote event for replay can quietly turn a UX feature into a storage and compliance obligation.

For a watchlist, I retain an append-only audit record of authorization decisions, symbol changes, and the final session state. I do not retain every duplicate price tick by default. That choice reduces replay fidelity, so the recovery path uses a timestamped snapshot plus a sequence number; an operator can prove which quote version was displayed without preserving an unlimited stream of ephemeral values.

The catch is operational. If a regulator or incident responder needs tick-level reconstruction, dropping those events is not suitable. In that case, route the raw feed to a separately governed market-data archive and keep the product's audit log focused on user-visible decisions. Mixing the two retention policies makes deletion, access reviews, and cost attribution harder.

A simple budget worksheet should include fan-out bandwidth, connection counts, refresh traffic, and retained bytes. Cost is a constraint, not a selection criterion: a cheaper transport that makes expiry ambiguous creates more support work and a larger reconciliation surface.

Measure first.

How should token expiry shape a trusted watchlist session?

Treat authorization as a state machine shared by server and client: active, expiring, expired, and reconnecting. The server validates the token on connection and on privileged actions; the client displays quotes as provisional once the lease ends, stops submitting symbol mutations, and offers a deliberate re-authentication action. An open WebRTC data channel, WebSocket, or long poll is only a delivery mechanism. It is not proof that the lease remains valid.

Use an absolute expiry timestamp issued by the server, plus a small safety margin for clock skew. Do not schedule a single browser timer and call the job done. Background tabs throttle timers, laptops sleep, and a reconnect can race with a refresh response. On every message and before every mutation, compare the server-derived deadline with the current monotonic clock.

The UX should make the boundary legible: show “updates paused; sign in to continue,” preserve the last known quote with its age, and never silently re-submit a queued edit after a new token arrives. A fresh token starts a new authorization epoch. The epoch and the last accepted event sequence belong in the audit trail so duplicate callbacks remain harmless.

That is the trust boundary.

Here is the core of a deterministic test harness in Go. The production adapter can use a real clock; tests inject the fake one and advance it explicitly.

package session import "time" type Clock interface { Now() time.Time } type FakeClock struct{ current time.Time } func (c *FakeClock) Now() time.Time { return c.current } func (c *FakeClock) Advance(d time.Duration) { c.current = c.current.Add(d) } type Lease struct { Epoch uint64 ExpiresAt time.Time } type State int const ( Active State = iota Expiring Expired ) func SessionState(clock Clock, lease Lease, margin time.Duration) State { remaining := lease.ExpiresAt.Sub(clock.Now()) if remaining <= 0 { return Expired } if remaining <= margin { return Expiring } return Active } 

The test should assert observable transitions, not sleep for five minutes. Advance to one second before expiry, verify that mutations are blocked in Expiring, then advance one second and verify that delivery is marked stale in Expired. Include a duplicate event with the same sequence number and assert that the audit writer records it once. This is an exactly-once mindset applied at the boundary where it matters; the network itself will not provide exactly-once delivery.

Testing reconnects without flaky timing

Build tests around a scripted event log. Each record contains epoch, sequence, received_at, and kind (quote, authorization, or mutation result). Feed the same log through a state reducer in unit tests, then run a smaller set of browser tests for rendering and focus behavior. The reducer gives you deterministic coverage for races such as “expiry arrives while a quote is buffered” and “refresh completes after reconnect.”

type Event struct { Epoch uint64 Seq uint64 Kind string } type Reducer struct { Epoch uint64 LastSeq uint64 Authorized bool } func (r *Reducer) Apply(e Event) bool { if e.Epoch != r.Epoch || e.Seq <= r.LastSeq { return false } r.LastSeq = e.Seq if e.Kind == "authorized" { r.Authorized = true } if e.Kind == "expired" { r.Authorized = false } return true } 

The important assertion is not “the reconnect finished within 200 ms.” It is “an event from epoch 4 cannot mutate state in epoch 5.” For example, imagine a trader's token expires just after sequence 881 carries a quote for NVDA, while the browser has already sent a symbol-removal request and the refresh endpoint is waiting behind a sleeping mobile radio. When the device wakes, the feed may deliver sequence 882, the refresh may complete, and the old mutation response may arrive in either order; the reducer must reject any record from the old epoch, retain the age of the last quote, and require the user to repeat the edit under the new lease. Add property tests that randomize event order, duplicate delivery, and reconnect count while keeping the clock fixed. Your mileage may vary with browser scheduling, but the authorization and ordering rules should remain invariant.

For integration tests, put the feed behind a controllable test server that can close the channel, delay a refresh response, and replay a sequence. Avoid monkey-patching wall-clock APIs in the browser; it often hides the exact race you are trying to expose. A short end-to-end suite can then verify accessible status text, disabled controls, and focus returning to the sign-in action.

Delivery choices and explicit limits

WebRTC data channels, WebSockets, and server-sent events each solve delivery, not authorization. WebRTC adds ICE and connection-state concerns; WebSockets offer a familiar bidirectional stream but still need application-level sequencing; server-sent events simplify one-way updates and browser reconnection while leaving mutations on ordinary HTTPS. The standards document for WebRTC describes its connection and data-channel states, which are useful signals for transport health, but none of them extend a token's lifetime.

Pick the least complex transport that matches the direction of traffic. For a read-heavy watchlist with separate HTTPS mutations, one-way events may be sufficient. Stay with a bidirectional channel when the session genuinely needs low-latency commands and you can operate its reconnect and backpressure behavior. Do not choose based on a benchmark that omits token refresh, audit writes, and mobile sleep.

I initially treated expiry as a timer concern. That was the wrong boundary. The durable boundary is an authorization epoch recorded beside the user's intent, because that is what reconciliation can explain after a reconnect or a disputed order. Keep transport telemetry (connect, close, retry, buffered bytes) separate from financial audit events, and sample high-volume quote metrics without sampling security decisions.

References