Learning pathsPricingChecking sign-in…
Patterns

Real-time Updates

Real-time is a freshness requirement, not a transport name.

What, why, when and how

What is it?

Real-time updates deliver changes to a client within a stated freshness target, using polling, server-sent events or bidirectional connections.

Why is it needed?

Repeated manual refreshes or slow polling can leave users unaware of important state changes.

When should I use it?

Use it for live comments, collaborative state or job progress when the latency requirement justifies the connection and recovery cost.

When should I choose something else?

Use ordinary requests or modest polling when updates are infrequent. A WebSocket does not by itself provide durable delivery or replay.

How do I use it?

Choose transport from direction and latency requirements; give events IDs, retain a replay window, resume from a cursor, recheck authorization and bound each connection buffer.

Can you show a concrete example?

A client disconnects after event 41 and reconnects with cursor 41. Replay starts after that cursor, duplicates are harmless, and an expired cursor triggers a fresh snapshot instead of silently missing events.

Client last applied event 41, then disconnects; Resume cursor 41: replay later retained events; Cursor too old? Refresh snapshot; do not skip
Real-time Updates: one concrete example
Read the diagram

Client last applied event 41, then disconnects; Resume cursor 41: replay later retained events; Cursor too old? Refresh snapshot; do not skip

Open original
Real-time Updates: worked example
Client last applied event 41, then disconnects; Resume cursor 41: replay later retained events; Cursor too old? Refresh snapshot; do not skip

Real-time Updates: one concrete example

Follow the detailed diagrams below to trace the additional state changes and failure cases behind these answers.

Real-time is a freshness requirement, not a transport name. A job-status page may tolerate a few seconds, while a collaborative cursor needs much faster feedback. First define how quickly a change must become visible and what happens after disconnection. Then select a transport and recovery protocol that can meet that contract.

Learning goals

Polling; long polling; SSE; WebSockets; connection lifecycle; event IDs; resumption; heartbeat; backpressure; authentication expiry.

Recover a real event cursor

Suppose a client has applied comments 41 and 42. It disconnects while the authority commits 43 and 44. The client resumes from 42; the server authorizes the stream and reads durable history after 42. A duplicate 42 is harmless because the client compares stable event IDs. Connecting a socket and subscribing to ephemeral pub/sub alone cannot recover the missing records.

Contract / pseudocode
client cursor: 42
retained history: 41,42,43,44
resume(after=42): 43,44
after applying 44: durable client cursor=44
expired cursor: explicit snapshot/resync, not an empty successful page
client cursor: 42; retained history: 41,42,43,44; resume(after=42): 43,44; after applying 44: durable client cursor=44; expired cursor: explicit snapshot/resync, not an empty successful page
Recover a real event cursor
Read the diagram

client cursor: 42; retained history: 41,42,43,44; resume(after=42): 43,44; after applying 44: durable client cursor=44; expired cursor: explicit snapshot/resync, not an empty successful page

Open original
Recover a real event cursor
client cursor: 42; retained history: 41,42,43,44; resume(after=42): 43,44; after applying 44: durable client cursor=44; expired cursor: explicit snapshot/resync, not an empty successful page

Recover a real event cursor

Simple polling repeatedly asks for changes and trades delay for request volume. Long polling holds a request until a change or timeout, then reconnects. SSE provides one-way server events over HTTP; WebSockets support two-way application messages. WebRTC suits media or appropriate peer communication and adds signaling/connectivity concerns. Choose with a traffic calculation: 100,000 clients polling every five seconds generate about 20,000 requests/s even when nothing changes. Persistent connections reduce empty polling but consume memory, descriptors and reconnect capacity.

On the server, either poll shared history, route a user's connection to an owner, or distribute notifications through scoped pub/sub. Specify ordering per chat/stream rather than across all users. A slow client's queue needs a byte/event limit: drop optional updates, coalesce state, or disconnect with a resync instruction according to the contract. A reconnect wave needs jitter and admission; it must not occupy every history-store connection.

Show answer and explanation

Answer: Resume returns 43 and 44, not “whatever arrived since this new socket opened.” If cursor 42 predates retention, declare the gap and rebuild from a snapshot. A global event sequence is unnecessary if the product only requires per-stream order.

Step-by-step reasoning

1. Choose the simplest transport

Polling asks for current state at intervals and is easy to operate for infrequent changes. Long polling holds a request until data or a timeout is available. SSE provides a server-to-client event stream over HTTP. WebSockets support bidirectional messages. The transport does not decide durability, ordering, or whether an application event was applied.

2. Give events identity and scope

Attach stable event IDs and a cursor in the ordering scope the product needs. A cursor might be per room, user, or job. Store enough history to support the intended reconnect horizon. If a client needs only the latest status, a snapshot plus version can be simpler than replaying every intermediate update.

3. Make reconnection ordinary

Networks change, proxies close idle connections, and deployments restart gateways. Send heartbeats where useful, reconnect with backoff and jitter, and resume after the last applied cursor. Deduplicate overlap between replay and live events. If the cursor is too old, request a fresh snapshot and establish a new baseline.

4. Bound every connection

Cap buffers and message size, enforce authentication and authorization, and define behavior when credentials expire. A slow consumer should not grow unbounded server memory. Drop replaceable updates such as cursor positions if the product permits it, but do not silently drop durable chat messages. Monitor reconnect rate, buffer pressure, and end-to-end event age.

Contracts and state

The following sketch makes the decision boundary concrete. Field names and capacity assumptions are illustrative; adapt them to the stated product contract.

Contract / pseudocode
Event envelope
{ id: "e_901", stream: "job_42", version: 17,
  type: "progress", payload: {percent: 60} }
Resume request: after=e_901
Expired cursor response: reset_required + snapshot_version

Worked example

For an export job, polling every five seconds may satisfy the product. For live comments, SSE plus cursor replay can deliver server-originated updates without a bidirectional protocol. For collaborative editing, bidirectional transport is useful, but conflict resolution still needs an application protocol. Do not claim WebSockets solve concurrent editing merely because both sides can send messages.

Failure walkthrough

A gateway sends an update and the connection drops before an application acknowledgment. The server cannot infer that the user saw it. Retain or reconstruct the event, replay on reconnect, and let the client deduplicate. A TCP acknowledgment confirms transport progress, not that application state was rendered or durably recorded.

Apply event 17 → Persist cursor 17 → Connection drops → Resume after 17 → Replay or reset explicitly
Real-time Updates · scenario walkthrough
Read the diagram

Apply event 17 → Persist cursor 17 → Connection drops → Resume after 17 → Replay or reset explicitly

Open original
Real-time Updates · scenario walkthrough
Apply event 17 → Persist cursor 17 → Connection drops → Resume after 17 → Replay or reset explicitly

Real-time Updates · scenario walkthrough

Decisions and trade-offs

TransportUseful forStill required
PollingOccasional status changesInterval and load budget
SSEServer-pushed updatesReplay and authorization
WebSocketBidirectional interactionFlow control and recovery

Check your understanding

Which events can a collaborative UI safely replace with only their newest value?

Show answer and explanation

Answer: Ephemeral cursor positions may be replaceable if the product accepts it. Durable document edits are not interchangeable snapshots without a proper merge/version protocol. Classify events by semantics before choosing a buffer-dropping policy.

Transfer to a new scenario

Compare transport choices for job status, live comments, and collaborative edits.

Does an open socket prove that a particular event reached the user?

Continue the connection

Study Networking Essentials and explain which guarantee from this lesson carries into that topic.

Reconnect without a gap

Choose polling for infrequent updates, SSE for a server-to-browser stream, and WebSockets for bidirectional exchange. Transport selection does not define durability or ordering. Persist important events with a monotonic position in the relevant stream and let a client resume from the last durable position it processed.

To bridge history and live updates, obtain a high-water mark or subscribe while fetching history, then deduplicate the overlap. Fetching old events and only afterward subscribing can miss events published between those operations. A retained-history limit requires a full snapshot reset path when the cursor is too old.

Each client needs a bounded output buffer. Slow clients can receive coalesced state, a reset instruction or a disconnect according to the product contract. Never let one browser retain unbounded server memory. Presence and typing indicators can be ephemeral while messages or financial status updates use durable replay.

A decision worksheet for Real-time Updates: read the mechanism and its guarantee together.
A decision worksheet for Real-time Updates: read the mechanism and its guarantee together.
Read the diagram

Transport / Useful for / Still required; Polling / Occasional status changes / Interval and load budget; SSE / Server-pushed updates / Replay and authorization; WebSocket / Bidirectional interaction / Flow control and recovery

Open original
Real-time Updates choices for this workload
A decision worksheet for Real-time Updates: read the mechanism and its guarantee together.

A decision worksheet for Real-time Updates: read the mechanism and its guarantee together.

Operational sketch

Contract / pseudocode
client resumes after sequence 120
server establishes high-water mark 150
replay 121..150; buffer newer events
then stream 151 onward; dedup by event ID

A tempting mistake

A load balancer reconnecting a socket to another host must not lose the user’s durable cursor. Sticky sessions improve locality but are not a recovery strategy.

Transfer exercise

What happens when the requested cursor predates retained history?

Show answer and explanation

Answer: Return a reset-required result, fetch a current snapshot tied to a stream position, then resume from that position. Do not silently skip the missing interval.

Your study notes