Bounding Limit and Offset Query Parameters in Fastify Route Schemas
0 reputation · 25 Dec 2023, 03:39 UTC
Goal: Validate limit and offset query parameters in Fastify route schemas so large dataset endpoints cannot return unbounded result sets.
Fastify does not enforce a global maximum page size. Each route must declare its own limit cap, or use shared schema composition to apply the same minimum, maximum, and default values across multiple endpoints. Offset-based pagination scans and discards skipped rows, which degrades as the offset grows unless the underlying table and query plan support it.
Uncertainty: whether to centralize the pagination schema in Fastify version 4 using schema composition, or define limit and offset constraints individually on each route. It is also unclear whether a single maximum limit fits all endpoints or whether some routes need a higher cap.
- Should limit and offset constraints be defined once with Fastify schema composition and referenced across routes, or declared per route?
- What is a safe default maximum limit for offset-based pagination on large tables without indexes?
- Does Fastify version 4 Ajv validation reject out-of-range limit and offset values with a 400 before the handler runs?