A reverse proxy may buffer request bodies, stream them upstream, impose size and time limits, or retry a failed upstream. Each choice changes how much work the application sees and when a caller receives a response. Buffering can protect an origin from very slow senders but consumes edge memory or disk; streaming can reduce buffering while tying up an origin connection for longer. A read timeout is often measured between successful reads, not necessarily across the whole request, so a slow trickle can survive unless total time and rate are also bounded. Retries are dangerous for side-effecting requests when the proxy cannot know whether the origin committed before a connection failed. The retry owner and idempotency contract must be explicit.
Proxy Body Budgets, Timeouts, and Retry Ownership
Working case
A field tablet uploads a 63-megabyte inspection file through the ingress. One route accepts only 47 megabytes, but the limit exists only in the app, so the proxy buffers the entire request before the app rejects it. Another client sends a few bytes every second and occupies an origin slot. During approval, an upstream connection breaks after the database commits but before the proxy receives the response; an automatic retry creates a second notification. The revised path rejects oversized uploads at ingress, assigns a bounded streaming or buffering policy to each route, sets total deadlines, and does not replay the approval without the server's stable operation identity.
Implementation boundary
function mayRetryUpstream(requestKind, bodyReplayable, responseStarted) {
return requestKind === "pure-read" && bodyReplayable && !responseStarted;
}
console.log(mayRetryUpstream("case-approval", true, false));
// Output: falseClassify routes by maximum body size, content type, buffering choice, upload duration, and whether a body can be replayed. Enforce coarse limits at ingress and detailed validation at the app; neither layer should assume the other is enough. For large uploads, use a private staging path and explicit integrity checks rather than sending unlimited bytes through an ordinary API transaction. Give connection, header, body, upstream, and total request phases budgets that fit inside the caller's deadline. Decide whether the proxy may retry each route before deployment. A safe informational read can often retry within a small attempt and time budget if no response bytes reached the client. A mutation needs a stable idempotency key and server-owned result; proxy retries alone cannot prove one effect. Record whether the origin received the body and whether a response had begun before failover.
Cost and boundaries
Buffering uses edge memory or disk proportional to simultaneous body volume; streaming shifts duration and backpressure to origin connections. Lower size and time limits conserve resources but can reject legitimate slow field uploads. Higher limits invite resource exhaustion and make rollout drains longer. Retries add upstream work and can worsen an incident if the fleet is overloaded. Track rejected body size, slow-upload duration, buffer utilization, origin slots held, timeout phase, retry attempts, and duplicate-effect suppression. The important measure is the full user task, including a successful recovery path when a transfer is interrupted. A 502 count by itself cannot show whether the origin committed a write.
Failure trace
Send a 63-megabyte file to a route capped at 47 megabytes and confirm ingress rejects early without storing the full body. Trickle bytes slowly while keeping the socket technically active; a total deadline must end the request. Stop an upload halfway through and verify private staging cleanup. Commit an approval, then drop the origin connection before response; the proxy must not blindly replay it as a new operation. Return a partial streamed response and fail upstream: once bytes reach the client, switching servers cannot invisibly repair the stream. Load-test a retry burst while one node drains to ensure the remaining pool has capacity.
Verification
- Ingress and app both enforce route-specific body limits.
- Total deadlines stop slow trickle requests.
- Mutations cannot gain duplicate effects from automatic proxy retries.
Practice drill
Make a route matrix for case reads, approval writes, and inspection uploads. Give each a body cap, header deadline, body deadline, total deadline, buffering mode, and retry policy. Use a 47-megabyte upload cap and simulate a 63-megabyte request, a slow sender, and a dropped upstream after a committed approval. Record edge bytes buffered, origin work, client response, operation identity, and cleanup. Prove that retries never produce two approval audit entries and that partial responses report failure rather than fabricated completeness.
Decision note
A proxy cannot infer mutation safety from a broken connection; budget bodies and own retries explicitly.
Common Mistakes
- Assuming a per-read timeout bounds the entire upload.
- Buffering an oversized body before rejecting it.
- Retrying a failed connection as proof that the origin did not commit.
Related lessons
Ingress Proxy and Upstream Contracts; Trusted Proxy Hops and Forwarded Client Identity; Host Authority Routing and Default Deny; Ingress Health, Readiness, and Connection Drain; Request Deadlines, Retries, and Backoff; File Ingestion and Private Asset Lifecycle.
Apply and check
Build Project: permit ingress cutover and safe retry and review Web Development: ingress and upstream contracts quiz.
