In a mobile auction app's bidding room, why might bids go as ordinary HTTP requests while prices arrive over a one-way server stream?
answer
- does it need two-way at all?
- one definite answer per bid
- a key makes the retry safe
- the stream resumes from its last id
- a socket means building request-reply
basics
~20 sBids are occasional and each needs a definite answer and a safe retry, which an HTTP request with an idempotency key provides; prices are a continuous server-to-phone flow that a one-way stream carries with built-in resume. Neither needs a socket.
solid answer
~40 sFirst I'd ask whether the room needs two-way traffic at all. Prices, the bid history and the end time flow from server to phone continuously; bids flow the other way a few times per lot. A bid needs a definite outcome - accepted, too low, lot closed - which a request's status code and body give directly, plus an idempotency key so a retry after a lost response cannot place the bid twice. The feed fits a one-way server stream, whose specification gives the client a reconnection delay and a `Last-Event-ID` header to resume from. Over a socket I'd rebuild request-reply matching, acknowledgements and resume myself. A socket earns its place when the phone sends often - chat or typing signals in the room - not for a tap now and then.
go deeper
Recall that prices flow one way and bids rarely flow the other, so not every live screen needs a two-way socket.
Explain what a request gives a bid - a definite answer, a status code, a safe retry with a key - and what the stream's built-in resume gives the feed.
Show how the bid's response and the stream stay consistent through a shared sequence, and name the traffic pattern that would make a socket the simpler design.
Argue the default for the whole app: actions as requests, feeds as streams, a socket only where the phone sends often - and what that saves the team in custom protocol.
## Start by asking whether the feature is two-way When a design calls something **real-time**, the reflex is a **WebSocket**: one connection that both sides can write to at any time. The better first question is which way the data actually flows, and how often. In an auction's **bidding room**: - **Server to phone, continuously**: the current price, each new bid in the history, the number of bidders, and any change to the lot's end time. - **Phone to server, occasionally**: a bid, a few times per lot at most, and perhaps a maximum for automatic bidding. That shape - a steady feed one way, rare actions the other - splits naturally into a **one-way server stream** for the feed and **ordinary HTTP requests** for the actions. ## What a bid needs A bid is an action with consequences, and the bidder must learn its outcome: - **A definite answer per bid.** Accepted; rejected because someone bid higher a moment ago; rejected because the lot has closed. A request and its response, with a status code and a body, give that answer directly. On a socket the app has to attach its own id to each bid and match each reply to it. - **A safe retry.** On a phone the response is often lost - the train enters a tunnel after the request has left. Retrying must not place the bid twice, so each bid carries an **idempotency key** that the server deduplicates on (how one call is made safe to retry is a question of its own). - **Independence from the feed.** If the stream is mid-reconnect after a network switch, the bid still goes out as its own request; it does not wait for the feed to come back. - **Ordinary plumbing.** Authentication, rate limiting, logging and error handling already exist for requests. ## What the price feed needs The feed is many small events, server to phone, while the screen is open. A **one-way server stream** - a held HTTP response the server keeps writing events into, as server-sent events define - fits it. Its specification gives the client a **reconnection time** to wait before reconnecting (the server can change it with a `retry` field) and has the client send the last event id it received in a `Last-Event-ID` header, so the server can resume from there. A socket gives the application nothing of the kind: it must track and send its own position. ## Keeping the screen consistent Two channels raise a fair worry: can the bid's response and the stream disagree? Give both the same numbering. 1. Every change to a lot gets a **sequence number** on the server. 2. The bid's response returns the lot's state and the sequence at which the bid was recorded. 3. The client applies the response at once, so the bidder sees the result without waiting for the stream. 4. Stream events at or below a sequence the client has already applied are ignored; a gap tells it to fetch the lot again. ## When a socket earns its place | Situation | Requests plus a one-way stream | One two-way socket | |---|---|---| | Occasional actions, steady feed | fits: an answer per action, built-in resume | works, but request-reply and resume are rebuilt by hand | | Many small messages per second from the phone (room chat, typing signals) | a full request and response per message | fits: one connection both ways | | One strict order across both directions | needs shared sequence numbers | one ordered connection | | Proxies that buffer or block held connections | the stream may stall, so a fallback is needed | the upgrade may be refused, so a fallback is needed | The rule of thumb: the decision follows the **phone-to-server traffic**, not the word "real-time". If the room later gains chat with typing indicators, the socket becomes the simpler design. ## What it costs the phone Neither choice is free. The stream is a held connection with keepalive traffic, so it lives only while the room is on screen. Each bid is a request, but bids are rare, and a request on an HTTP connection that is already open adds little. What the split mostly saves is engineering: no hand-built request-reply protocol, no custom resume, and one fewer kind of long-lived connection to keep honest.
- The price stream is reconnecting when the bidder taps Bid. What happens?The bid goes as its own request whatever the stream is doing, so it is not lost in a half-dead connection. The response states the outcome and the lot's current price and sequence, which the screen shows at once. When the stream returns it resumes after its last event id, and the client ignores events it already applied from the bid's response.
- When would you move the bidding room to a socket?When phone-to-server traffic becomes frequent or latency-critical: chat inside the room, typing signals, or rapid in-room actions. Then a request per message costs a full round trip of headers each, and one socket carrying both directions, with the app's own message ids and acknowledgements, pays off. The decision follows the traffic, not the label 'real-time'.
- Anything real-time needs a WebSocket.
- A one-way stream can also carry bids if you add a field.
- A bid request can be retried blindly after a timeout.
- A socket gives you reconnection and resume for free.
- Requests plus a stream can never show a consistent screen.