Not everything behind an AI product is AI. The operator console — where creditors
run collection campaigns — is a plain full-stack product: a React SPA, a NestJS
BFF and a Prisma/Postgres data layer. This case is one vertical slice through all
three, fixing a listing that was silently losing data.
Each campaign has a follow-up listing of its subjects: filterable, sortable,
paginated. The screen loaded the records, then filtered, sorted and paginated
them in the browser. It worked while campaigns were small. It stopped being
correct the moment they weren't.
The listing was capped client-side. New campaigns — the ones
with the highest IDs, i.e. the most recent work — quietly fell outside that
window and disappeared from the "All" view. Nobody saw an error; the data was
just missing. A cap that behaves like a bug is worse than a crash: it looks like
it works.
Doing filter, sort and pagination in the browser also meant every view pulled the
whole set over the wire before showing one page of it.
One change, three layers, shipped in order so the contract never broke:
- Postgres / Prisma. Moved filtering, ordering and windowing into the query:
where / orderBy / skip / take, plus a count for the total. The hot
status-filter columns are indexed so the window is cheap instead of a scan.
- NestJS BFF. A tenant-scoped, paginated endpoint returning a stable
{ items, total, page, pageSize } contract — so the client never has to know
how many rows exist to render a page.
- React / Vite. Server-driven fetch: page and filter state drive the request,
filter input is debounced, and a stale-response guard discards out-of-order
responses so a slow request can't overwrite a newer page.
While in the dashboard I also fixed a data-contract bug in the same spirit: the
"Valor em Recuperação" KPI read the wrong funnel field, so I corrected the reading
and the shared FunnelMetrics type together — front-end and its contract in one
change, not a patch on one side.
- The silent listing cap is gone. The listing returns the complete set,
one page at a time.
- Filter, sort and pagination run server-side against indexed columns instead
of in the browser over the full result set.
- A stable
{ items, total, page, pageSize } contract between BFF and SPA,
with the front-end guarded against out-of-order responses.
- Dashboard KPI reads the correct funnel field, front-end and type in sync.
The most dangerous production bugs don't throw — they under-report. This one
never errored; it just stopped showing the newest campaigns. Fixing it well meant
touching all three layers at once, because a pagination contract that only half
the stack agrees on is how you get back here.