A mobile auction app's live prices never arrive for some bidders on hotel and office Wi-Fi; what transport fallback should the client take?
answer
- the network, not the server
- upgrade refused, or bytes held back
- a deadline for the first event
- step down to long polling
- carry the last event id across
basics
~20 sDetect a refused socket upgrade or a stream whose first event misses a deadline, step down to long polling, which buffering proxies pass, resume from the last event id, and retry the better transport on the next network.
solid answer
~40 sSome networks break long-lived connections: a proxy that refuses or strips the socket upgrade, or one that buffers a streamed response and forwards it only when it ends, so the stream 'connects' and nothing arrives. The client cannot fix the network, so it needs a ladder. Start with the socket or stream over TLS on port 443, which gets through far more often; if the upgrade fails, or no event - not even the comment the server writes into an idle stream - arrives before a deadline, step down to long polling, whose complete responses pass buffering proxies. Every rung resumes from the last event id, so the switch loses nothing. Remember the working rung for that network, start from the top again after a network change, and count fallbacks in telemetry.
code
pseudocode · 16 linesrungs = ["socket_443", "stream", "long_poll", "poll"]
function connect_live(network_id, last_event_id):
rung = remembered_rung(network_id) # 0, the top, when nothing is remembered
while rung < length(rungs):
result = try_transport(rungs[rung], resume_after = last_event_id, first_event_deadline = 30 seconds)
if result.status == "receiving":
remember_rung(network_id, rung)
return result.connection
if result.status == "captive_portal":
show_notice("sign in to this network")
return none
record_fallback(network_id, rungs[rung], result.status)
rung = rung + 1
show_banner("prices may be delayed")
return nonego deeper
Recall that some Wi-Fi networks block or hold back long-lived connections, and that the app needs a slower transport it can fall back to.
Explain why a buffering proxy stalls a stream but passes long polling, and why every rung must resume from the last event id.
Show the detection: a first-event deadline longer than the server's idle gap, a captive portal told apart from a proxy, a rung remembered per network and retried after a change.
Weigh how many rungs the team should support and test against how many bidders need them, using fallback telemetry rather than guesses to decide.
## Why some networks break live connections A long-lived connection depends on every box between the phone and the server cooperating, and on some networks - hotel and conference Wi-Fi, corporate networks with inspecting proxies, guest networks behind a sign-in page - they do not. The common failures: - **The upgrade is refused or stripped.** A socket starts life as an HTTP request asking to upgrade the connection; an intermediary that does not understand or allow that answers with an error or drops it. - **The response is buffered.** HTTP does not require an intermediary to forward a partial response straight away, and a buffering proxy holds a streamed response until it ends. The stream "connects", the server writes events, and the phone receives nothing. - **Idle connections are cut short.** Some middleboxes drop a connection after a short quiet period; sending traffic before that happens is the connection's heartbeat design, not the transport choice. - **A captive portal answers instead.** Until the guest signs in to the network, every request gets the portal's login page. The client cannot fix the network. It can notice, and adapt. ## Telling the failures apart | Symptom on the phone | Likely cause | Next step | |---|---|---| | The socket upgrade fails with an error or a reset | the network blocks or strips upgrades | try the one-way stream | | The stream opens with a 200 but nothing arrives before the deadline | a buffering proxy | step down to long polling | | An HTML page comes back instead of the expected content type | a captive portal | stop retrying; ask the user to sign in to the network | | Connections die after a fixed quiet period | a short idle timeout | keep the transport; the heartbeat must beat the timeout | ## The fallback ladder 1. **Socket or stream over TLS on port 443.** Encryption keeps the upgrade and the event stream away from proxies that only inspect plain HTTP (one that intercepts TLS can still interfere), and the WebSocket specification itself notes that connections on port 443 succeed markedly more often than on port 80. 2. **One-way stream**, if the socket's upgrade is what fails and the room needs no phone-to-server traffic on the connection - in this design bids go as ordinary requests, so it does not. 3. **Long polling.** Each held request ends in a **complete response** - on an event, or when the server's hold expires - and most proxies handle that well, so it gets through where a stream stalls. It costs a request per batch of events and slightly more latency. 4. **Polling at a stated interval**, with the screen honest that prices may lag. The client judges each rung against a **deadline**: if neither the first event nor the comment the server writes into an idle stream has arrived in time, it moves down. The deadline must exceed the longest silence the server allows itself, or a quiet lot looks like a broken network. ## Losing nothing across a switch Every rung must resume from the same position. The client keeps the **last event id** (or sequence number) it has applied and sends it with the first request on the new transport, so the server returns everything after it. Without that, the step down silently skips the bids and end-time changes that arrived during the failed attempt. If the position is too old for the server to replay, the client fetches the lot fresh instead. ## Remembering and recovering - Remember the rung that worked **per network** for the session, so every screen does not repeat a failing upgrade. - When the phone changes networks - leaving the hotel Wi-Fi for cellular - start again from the top. - Record each fallback with its rung and reason in telemetry; a rising rate points at networks or proxies worth investigating. - Bids stay ordinary requests on every rung, so the bidder always gets a definite answer about their own bid. ## What not to do - Retry the refused socket with backoff for ever: patience does not change a proxy's rules. - Fall back to push as a feed: it is best effort, and it exists to reach an app that is not running. - Fall back to one-second polling to match the socket's freshness: it multiplies radio wake-ups for little gain.
- How long should the client wait for the first event before stepping down?Longer than the longest silence the server allows itself on an idle stream. The event-stream specification suggests a comment line every 15 seconds or so against legacy proxies that drop idle connections; if the server follows that, a client deadline of about twice it is a reasonable assumption. Too short a deadline turns a quiet lot into a false fallback.
- Should the app fall back to push when every live transport fails?No - push is not a feed. It is best effort, can be delayed or collapsed, and exists to reach an app that is not running. If even polling fails, the network is effectively blocking the app: show a clear 'prices delayed' state, refresh on each user action, and keep bids as ordinary requests, which tell the bidder the truth about each bid.
- A stream that opened with a 200 must be receiving events.
- Polling every second costs the phone no more than a held stream.
- After switching transports, the new one picks up where the old left off by itself.
- A fallback chosen on one network should apply on every network.
- Retrying the refused socket harder will eventually get it through.