skip to content

Real-Time UI Updates

A live feature picks its transport per need, then reconnects with jittered backoff, resubscribes, orders and dedups events, and batches bursts into frames. Chat and dashboard rounds turn on it.

on this pageshow

questions

6

In an online auction web app, what transport should the bid ladder, watchlist, watch count, bidding and announcements use, and should they share one connection?

level: middleimportance: must knowfreq 62%

answer

  1. direction and rate, feature by feature
  2. one connection per tab, many topics
  3. six event streams per browser and domain
  4. the bid wants a definitive answer
  5. approximate count, not a join log

basics

~20 s

Everything the server pushes - ladder, watchlist prices, watch count, alerts, announcements - shares one live connection per tab, subscribed by topic. Placing a bid stays an HTTP POST with an idempotency key, because it needs a definitive answer.

solid answer

~50 s

I split the features by direction and freshness. The bid ladder, watchlist prices, the watch count, outbid alerts and announcements are all server-to-client, so they share **one live connection per tab** that carries subscribe and unsubscribe messages keyed by topic (`lot:812`, `watchlist`, the user's own alerts). I'd use a WebSocket because the client changes its subscriptions constantly as the bidder moves between lots and scrolls the watchlist; one event stream with subscriptions changed by separate requests is a defensible alternative. **Placing a bid stays an HTTP POST** with an idempotency key: it needs a definitive outcome (accepted, outbid, lot closed), it must work while the live connection is reconnecting, and a retry must never place two bids. The watch count arrives as a server-aggregated number every few seconds, and the watchlist subscribes to a coalesced price summary per lot, not to forty full ladders.

code

json · 13 lines
json
{
  "liveConnection": { "perTab": 1, "carries": "subscribe / unsubscribe by topic" },
  "features": [
    { "feature": "bid ladder",    "topic": "lot:{lotId}",          "delivery": "every accepted bid, per-lot sequence" },
    { "feature": "countdown",     "topic": "lot:{lotId}",          "delivery": "end time from the lot read; extensions pushed" },
    { "feature": "watchlist",     "topic": "lot:{lotId}:summary",  "delivery": "latest price, at most about 1 per second per lot" },
    { "feature": "watch count",   "topic": "lot:{lotId}",          "delivery": "aggregated number every few seconds" },
    { "feature": "outbid alert",  "topic": "user:{userId}",        "delivery": "per user, immediate" },
    { "feature": "announcements", "topic": "auction:{auctionId}",  "delivery": "rare" }
  ],
  "placeBid": { "method": "POST", "path": "/lots/{lotId}/bids", "headers": ["Idempotency-Key"] },
  "fallback": "poll the lot and watchlist reads every few seconds"
}

go deeper

for a junior

Recall that features differ in who sends and how often: most of an auction page is server-to-client, while placing a bid is a request that needs an answer.

for a middle

Explain the per-feature table: direction, rate, freshness and channel, why one shared connection with topic subscriptions beats one per feature, and why the bid stays on HTTP with an idempotency key.

for a senior

Show the operational cost: the six-stream cap across tabs without HTTP/2, a reconnect storm multiplied by connections per tab, a polling fallback for blocked connections, and a bid path that survives the live connection being down.

for a principal

Treat the shared connection as owned infrastructure: who owns the topic protocol, when a feature may justify its own channel, and how the choice scales from one lot to fifty thousand watchers.

## Why this is a per-feature decision An online auction's live surface is not one feature but several, and they differ in **direction** (who sends), **rate** (how often it changes near closing) and **freshness** (how stale a value may be before the user is misled). A **transport** here means how updates reach the browser: **polling** (the page asks again every few seconds), a **server-sent event stream** (one long HTTP response the server keeps writing events into; the browser's `EventSource` reopens it by itself after a drop) or a **WebSocket** (a two-way connection where either side may send at any time; nothing in the browser API reopens it after a drop). The design round is graded on whether you map each feature to what it needs, then decide how many connections the page holds. ## What each feature needs | Feature | Direction | Rate near closing | Freshness | Carried by | |---|---|---|---|---| | Bid ladder | server to client | dozens of bids a second on a hot lot | under a second | lot topic on the live connection | | Closing countdown | server to client | rare (end time, extensions) | exact | end time from the lot read; extensions on the lot topic | | Watchlist, up to 40 lots | server to client | price changes per lot | seconds | one coalesced price-summary topic per lot | | Watch count | server to client | changes constantly | approximate | aggregated number on the lot topic every few seconds | | Outbid alert | server to one user | rare | immediate | the user's own topic | | Announcements | server to client | rare | seconds | the auction topic | | Placing a bid | client to server | rare per user | a definitive answer | HTTP POST with an idempotency key | Two rows deserve a note. The **watchlist** could be polled every few seconds while nothing on it is closing soon; that is a fair choice. It stops being fair in a lot's last minutes, which is exactly when a bidder watches it, so a coalesced summary topic (at most one price per lot per second or so) is the steadier design. The **watch count** is presence shown as a number: the server aggregates it and the client renders it approximately ("about 50,000 watching"); streaming every join and leave could cost more than the bids themselves. ## One connection, many subscriptions Every server-to-client feature shares **one connection per tab**, and features **subscribe to topics** through a small client-side registry instead of opening their own connections. 1. **Browser limits.** Without HTTP/2, event streams share a limit of six open connections per browser and domain, across all tabs. A page with three streams, opened in two tabs, has already used them all, and the seventh request waits. 2. **One failure path.** One connection means one heartbeat, one reconnect loop and one resubscribe step. Five connections fail at slightly different moments and show five different "reconnecting" states on one screen. 3. **Scale.** At 50,000 browsers on a hot lot, every extra connection per tab is another 50,000 held connections, and a deploy that drops them all produces that many more reconnects at once. Which transport carries the shared connection? A **WebSocket** fits because the client must send subscribe and unsubscribe messages whenever the bidder opens a lot or scrolls the watchlist. One **event stream** whose subscriptions are changed by separate requests also works, especially over HTTP/2, where the six-connection cap does not apply. Either way, the cost is the same: the team owns a topic protocol, a heartbeat and a reconnect policy, because the shared connection is now infrastructure. ## Why the bid is not a live-channel message - **It needs a definitive answer.** Accepted, outbid, below the increment, lot closed, session expired: a status code and body carry that cleanly, tied to the request that caused it. - **It must be retry-safe.** On a timeout the client retries with the same **idempotency key**, so the server can recognise the repeat instead of placing a second bid. - **It must not depend on the live connection.** The last seconds of a lot are when connections are most stressed; a bid that waits for a reconnect is a lost bid. - **It reconciles through the ladder.** The accepted bid then appears in the ladder like everyone else's, and the client recognises it by its sequence number rather than painting it twice. ## The fallback and the cost If the live connection cannot be established at all (some corporate proxies refuse it), the page falls back to polling the same reads the page loads with, every few seconds, and says so ("updates may lag"). The design costs a client subscription registry and a topic protocol; it buys one predictable connection per tab and a bid path that works whatever state that connection is in.

  • Would you ever give a feature its own connection?
    Yes, when its traffic profile differs enough to hurt the others: a large binary payload, or a feed whose bursts would delay outbid alerts behind it. Then I'd measure first and isolate only that feature, accepting a second reconnect path. Separate connections by default buy isolation the auction does not need and multiply connections and reconnects per tab.
  • The bidder has the same lot open in three tabs. What changes?
    Each tab holds its own connection, so the server sees three subscribers, and over HTTP/1.1 event streams the six-per-domain cap gets close. If that matters, one tab or a shared worker, where the browser supports one, can own the connection and relay events to the others, at the cost of a leader-election and hand-over path when that tab closes.
  • Why not let the watchlist subscribe to each lot's full bid topic?
    Forty hot lots near closing could push hundreds of bids a second into a page that shows one price per row. A summary topic the server coalesces to the latest price per lot, at most about once a second, carries what the row renders and keeps the watchlist's cost flat however busy the lots are.

  • Every live feature opens its own socket, since connections are cheap.
  • Send the bid on the socket and treat the next broadcast as its confirmation.
  • The watchlist subscribes to the full bid stream of all forty lots.
  • The watch count streams every individual join and leave event.
  • Pick one protocol for the whole page without asking each feature's direction and rate.
open as a page

On an online auction's lot page, the live connection drops for twenty seconds near closing; how should the browser client detect it, reconnect, resubscribe and catch up, and what should the bidder see meanwhile?

level: seniorimportance: must knowfreq 48%

basics

~20 s

Treat missed heartbeats as a dead connection and label the price stale. Reconnect with capped, jittered backoff, resubscribe only the lots on screen, read each lot's current state with its sequence number, then apply buffered events newer than it.

open as a page

When bids on an online auction's lot page burst to dozens a second, how should the page paint the ladder, price and watch count?

level: middleimportance: should knowfreq 45%

basics

~20 s

Fold events into pending state where the latest value per field wins and the ladder keeps its top entries, then paint once per animation frame. Show watchers as a throttled, rounded number; announce only what the bidder must act on.

open as a page

When an online auction's watchlist page sits in a hidden browser tab for an hour, what should its live connection do, and what must happen when the user returns?

level: seniorimportance: should knowfreq 40%

basics

~20 s

Keep the connection through a short grace period, then close it: hidden pages are throttled and may be frozen or discarded. On return, mark rows updating, reconnect, resubscribe the visible lots and read their state in one request.

open as a page

On an online auction's lot page, bid events arrive duplicated, out of order or with a sequence number missing; how should the browser client handle each case?

level: seniorimportance: should knowfreq 42%

basics

~20 s

Track the last applied sequence per lot: drop events at or below it, apply the next one and drain held successors, hold later ones briefly, and if the gap persists, resync from a state read.

open as a page

As frontend lead of an online auction web app where four teams ship live features, what shared live-update policy would you set, and how would you enforce it?

level: principalimportance: should knowfreq 30%

basics

~20 s

A platform-owned connection module every feature subscribes through, one event envelope with per-topic sequence numbers, shared reconnect, hidden-tab and staleness defaults, a catch-up read per topic, enforced by a build dependency rule and staleness metrics.

open as a page