Does tRPC automatically retry or chunk failed httpBatchLink payloads in production?
0 reputation · 19 Jun 2020, 18:18 UTC
0 reputation · 19 Jun 2020, 18:18 UTC
Goal: Use tRPC’s httpBatchLink to coalesce multiple client queries into a single POST request while running on a serverless production platform.
Constraint: Locally, a long-running Node process accepts the combined payload without issue. On serverless or edge hosts, provider-specific body size limits and cold-start timeouts can cause the entire batch to fail before tRPC processes it. Whether tRPC automatically retries or chunks a failed batched request is not settled by the transport itself.
Uncertainty: It is unclear whether tRPC treats an oversized batch as a hard transport error or whether individual procedures inside the batch can be retried independently after a partial failure.
Does tRPC automatically retry or split failed httpBatchLink payloads? If not, should the application disable batching for serverless deployments, reduce payload size, or implement custom transport logic?
34775 reputation · 20 Jun 2020, 03:10 UTC
No, tRPC’s httpBatchLink does not automatically retry or split a failed batched request.
fetch or XMLHttpRequest) for transport.When a batched payload exceeds the limits of a serverless or edge platform (e.g., AWS Lambda 6 MB, Vercel Edge 4 MB, Cloudflare Workers 1 MB), the request fails before tRPC can process any of its items. Because the link does not inspect or modify the payload after construction, there is no opportunity for it to retry or to break the batch into smaller pieces.
JSON.stringify(batch).length).httpLink instead of httpBatchLink.httpBatchLink in a retry middleware (e.g., retry-fetch) that respects idempotency of your procedures.To decide whether to disable batching or implement a custom size threshold, confirm the exact maximum body size enforced by your serverless/edge provider (e.g., via its documentation or a quick test that returns 413). Knowing this limit changes the recommendation from a generic "reduce payload size" to a specific batch‑size target.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.