Developer moves Next.js dashboard aggregation to Postgres, simplifying React frontend
A developer building a Pokémon TCG collection tracker found their React dashboard was fetching entire card and ownership datasets to the browser, then performing all aggregation logic client-side using multiple hooks and useMemo calls. As the data grew, the approach became slower and harder to maintain, with each new metric requiring additional client state and recomputation on every render. The developer moved all counting, grouping, and ratio calculations into a Postgres function called via Supabase's rpc() method, so the database returns pre-aggregated rows instead of raw data. The result was a significantly simpler frontend with fewer hooks, less state, and a smaller network payload. The author argues this reflects a broader principle: aggregation is a database responsibility, and misplacing it in the UI layer forces the same work to be done twice — once to transfer data, and again to process it in JavaScript.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in