Question
bodyLimit: Adjusting maximum request body size for cost‑effective Fastify deployments
Dev Maple
0 reputation · 09 Nov 2022, 09:06 UTC
115.3K views0
Goal
Reduce memory overhead on a low‑traffic Fastify server by limiting the size of incoming request bodies. A stricter bodyLimit can prevent large payloads from consuming RAM, but it must be tuned to avoid breaking legitimate traffic.
Constraints and Uncertainty
- The
bodyLimitoption is evaluated after decompression whenfastify-compressis enabled, so the effective limit may differ for gzipped requests. - When a request exceeds the limit, Fastify returns a 413 response before any application‑level
onErrorhooks run, which may affect custom error handling or caching strategies. - Streaming uploads or chunked bodies can be prematurely terminated by
bodyLimit, potentially causing client errors that are hard to diagnose.
Questions
- What is the recommended
bodyLimitvalue for a typical low‑traffic Fastify deployment that still accommodates occasional larger payloads? - How does
bodyLimitinteract withfastify-compresswhen clients send gzip‑compressed bodies, and should the limit be adjusted accordingly? - Does the 413 response generated by
bodyLimitbypass applicationonErrorhooks, and how might this affect caching or logging of oversized requests?