{"success":true,"name":"never-return-unbounded-lists-paginate-every-backend-list-end","description":"Writing a backend endpoint that returns a list of records","category":"ai-brimind","path":"ai-brimind/never-return-unbounded-lists-paginate-every-backend-list-end/SKILL.md","file":"SKILL.md","content":"---\nname: never-return-unbounded-lists-paginate-every-backend-list-end\ndescription: \"Writing a backend endpoint that returns a list of records\"\n---\n\n# Never Return Unbounded Lists: Paginate Every Backend List Endpoint\n\n## When to use\nProject has a backend with a database, and you are about to write an endpoint or query that returns 'all' of something with no limit.\n\n## Example request\nGET /users returning every user → fine with 50 rows in dev, a 30-second response with 100,000 in production; the missing piece is pagination (limit + page or cursor). loading all chat messages to show the last 20 → the database does the work and the server throws most of it away; the LIMIT belongs in the query, not in JS after fetching. an admin export endpoint with no cap → one click can freeze the whole backend for everyone; big exports are a job, not a request. the frontend 'filters it anyway' → shipping 10,000 rows to filter down to 10 wastes everyone's bandwidth; filtering is the database's job.\n\n## Instructions\nAct like a backend engineer who never trusts a table to stay small — every list grows, and today's instant query is next year's timeout. For any endpoint or query returning multiple records, ask: how many rows could this be at worst, in a year? If the answer is 'unbounded', add pagination now: a limit with a sane default and maximum, plus a page number or cursor, and put the LIMIT and filtering inside the database query — never fetch everything and slice it in code. Check how other list endpoints in this project already paginate and copy that exact convention (parameter names, response shape with total/hasMore) so the API stays consistent. Sorting must be defined too, or pages will overlap. For genuinely huge outputs (exports, reports), say that it needs a background job, not a bigger limit. If you are unsure what page size the screen needs, ask or read the frontend. Only ship the endpoint once its worst-case response size is capped and known, and explain why the endpoint now stays fast at any table size instead of only at demo size.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #525\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}