{"success":true,"name":"design-every-list-for-ten-thousand-rows-not-the-ten-you-test","description":"Building a feature that fetches or displays a list of records from the DB","category":"ai-brimind","path":"ai-brimind/design-every-list-for-ten-thousand-rows-not-the-ten-you-test/SKILL.md","file":"SKILL.md","content":"---\nname: design-every-list-for-ten-thousand-rows-not-the-ten-you-test\ndescription: \"Building a feature that fetches or displays a list of records from the DB\"\n---\n\n# Design Every List for Ten Thousand Rows, Not the Ten You Test With\n\n## When to use\nBuilding a feature that fetches or displays a list of records from the DB\n\n## Example request\nEndpoint returns all orders with no limit → works with 20 test rows, freezes the browser at 50,000 real ones; the missing idea is pagination. Frontend loads every user then filters in JavaScript → search feels instant in dev, takes 30 seconds in production; filtering belongs in the DB query, not in memory. A dashboard counts records by fetching them all and reading .length → the DB already knows how to COUNT; shipping the data just to count it wastes everything. Chat screen loads full history on open → old rows nobody reads slow every open; 'load recent first, fetch older on scroll' is the standard pattern.\n\n## Instructions\nAct as an architect who assumes every table will be a thousand times bigger than the test data — because successful apps grow, and the ones that break at growth were designed on ten rows. Before finishing any feature that reads a collection, do this: (1) Name the table and honestly estimate its size in one year of real use. If the answer is 'could be thousands or more', an unlimited fetch is already a bug, even if it works today. (2) Decide where the shrinking happens — filtering, searching, sorting, counting, and limiting must run in the database (WHERE, ORDER BY, LIMIT/skip, COUNT), never by pulling everything into backend or frontend memory and looping. The DB is built for this; your for-loop is not. (3) Design the endpoint with pagination from day one: a page or cursor parameter, a page size limit, and a response that tells the client if more exists. Adding pagination later means changing the API contract and every screen using it — far more expensive than starting with it. (4) On the frontend, plan what the user sees for page 2: a 'load more' button, infinite scroll, or page numbers — pick one on purpose. If you are unsure the data will ever grow, check what the table represents: anything users create daily WILL grow. Only proceed once the query has an explicit limit and you can explain why the feature behaves the same at 10 rows and at 100,000 — not just at the size of your test data.\n\n## Metadata\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #189\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}