In a mobile wallet app, why do the transfer call, the balance read and an avatar prefetch need different timeouts, priorities and deduplication?
answer
- classify calls by what the user waits for
- connect fast, finish by class
- a timed-out write is unknown, not failed
- identical reads share one flight
- prefetch yields to the user
basics
~20 sTheir failure costs differ. The transfer gets a generous deadline and is never deduplicated; the balance read gets a short deadline and shares one in-flight call; the prefetch is short, lowest priority and dropped on failure, so it never delays the user.
solid answer
~50 sA phone shares one radio, one connection pool and a bounded number of concurrent calls, so the pipeline sorts calls into classes. The transfer is a user-blocking write: it gets a generous whole-call deadline, because a timeout leaves its outcome unknown and forces a reconcile, top priority, and no deduplication beyond its idempotency key. The balance is a user-blocking read: a short deadline and one retry, and identical in-flight requests share one network call, keyed by method, URL and signed-in user. The avatar prefetch is speculative: short deadline, lowest priority, held back while user-blocking calls wait, cancelled with its screen and simply dropped on failure. Across classes the connect timeout stays short, since a dead path should fail fast whatever the call. An HTTP priority signal can tell the server the same thing, but servers may ignore it, so the client still orders its own queue.
go deeper
Recall that not all calls are equal: a payment, a screen's data and a speculative prefetch deserve different patience and priority.
Explain the difference between a connect timeout and a whole-call deadline, and how in-flight deduplication merges identical reads.
Show why a short transfer deadline creates unknown outcomes, why dedup keys include the user, and how a client queue keeps prefetches out of the user's way.
Define the call classes as a shared contract of the networking module, with per-class budgets reviewed against field latency data, so features pick a class rather than raw numbers.
## One policy for every call is the bug A pipeline with a single timeout, a single retry rule and a first-come queue treats a money transfer like a thumbnail. On a strong connection nobody notices. On a weak one the user waits for the balance behind forty avatar downloads, and a slow transfer times out at the same short limit as an image, leaving its outcome unknown. The fix is to give each **call class** its own policy, chosen by what a failure costs the user. ## Three classes in a wallet app | | Transfer | Balance read | Avatar prefetch | |---|---|---|---| | Class | user-blocking write | user-blocking read | speculative read | | Whole-call deadline | generous | short | short | | Retries | same idempotency key, capped | one quick retry | none, drop it | | Deduplication | never merged with other calls | identical in-flight calls share one | identical in-flight calls share one | | Priority | highest | high | lowest, yields to the others | | Leaves with the screen? | no | yes | yes | Concrete numbers are a team's choice, tuned against field data; no standard value exists. What is fixed is the ordering between classes. ## Timeouts: connect versus whole call Two different budgets do different jobs (the mechanics of each kind of timeout belong to the HTTP connection layer): - **Connect timeout**: how long to wait for a connection at all. Keep it short for every class: a dead path, a captive portal or a network switch should fail fast so the client can try again or report offline. - **Whole-call deadline**: how long the user-facing operation may take, across all its attempts. This is where classes differ. For the transfer, a short deadline is actively harmful. Expiring early does not stop the server; it only converts a slow success into an **unknown outcome** that the app must reconcile with the same idempotency key while the user stares at *pending*. A longer deadline with a clear "still sending" state is kinder. For a prefetch the opposite holds: if it is slow, it is no longer worth having. ## Deduplicating identical reads On launch the wallet's header, home card and a widget may all ask for the balance at once. **Request deduplication** gives the second and third callers the first one's in-flight result instead of three network calls: - key it on everything that changes the answer: method, URL, query, and the **signed-in user**, or an account switch could serve one person's balance to another; - deduplicate **reads only**; two transfers with the same body are two intents unless they carry the same idempotency key; - **count references** for cancellation: a shared call is cancelled only when every caller has gone; - merge only calls that are **in flight**; reusing completed responses is caching, a separate decision about freshness. ## Priority on a shared link A phone typically holds a small number of connections and caps concurrent calls, so order matters: 1. user-blocking writes and reads go first; 2. prefetches wait while any user-blocking call is queued, and are cancelled when their screen goes; 3. a burst of speculative work never consumes the concurrency the next tap needs. The client can also tell the server its view. The HTTP **priority signal** expresses urgency from 0 (most urgent) to 7, default 3, with 7 reserved for background work, but it is a hint: servers may ignore it and still serve the responses. So it complements the client's own queue; it does not replace it. ## A worked moment The user opens the wallet on a weak signal and taps *Send* within a second. Twelve avatar prefetches, one balance read from the header and one from a widget are already queued. With class-based policy the two balance calls merge into one flight, the avatars wait behind it, and when the transfer is confirmed it jumps the queue with its long deadline. If the signal drops, the avatars are simply dropped, the balance retries once, and the transfer either completes or shows *pending* for reconciliation. With one global policy, all fourteen calls share the same short timeout and the same queue, and the transfer is the call most likely to end in an unknown state. ## Where this leaf stops Grouping requests to save radio wake-ups, and choosing when to prefetch at all, are energy-budget decisions. The pause between retries is a backoff policy. This leaf owns the assignment: which class a call belongs to, and the deadline, retry rule, deduplication and priority that class implies.
- In a mobile app, why must an in-flight request deduplication key include the signed-in user?Because the same URL can mean different data per user. If one person signs out and another signs in while a balance read is still in flight, a key of method and URL alone hands the new user the previous user's result. Including the user, or clearing in-flight entries at sign-out, keeps responses with the identity that requested them.
- Does sending an HTTP priority signal remove the need for a mobile app to order its own requests?No. The priority signal states the client's view of urgency, 0 to 7 with 3 as default, but servers may ignore it and still respond correctly. It also cannot help with requests the client has not sent yet. The client's own queue and concurrency limit decide what leaves the device first.
- One global timeout for every call keeps the networking layer simple and fair.
- A short deadline on the transfer is safer because it fails fast.
- Deduplicate identical POST requests the same way as identical GET requests.
- Setting an HTTP priority signal guarantees the server answers urgent calls first.
- Retry a failed prefetch just as hard as a user-blocking read.