Finding · affects your cloud bill

List and aggregate queries on hot routes

A list, search or aggregate query on your busiest route gets slower as data grows, and it's slowest exactly when traffic peaks.

Why it matters

Queries that scan a list or compute a count are fast on a thousand rows and slow on ten million. When they sit on the most-requested route (a dashboard, a public page, a tracking endpoint), data growth and traffic growth multiply.

The usual response is a bigger database, which is the most expensive way to fix it.

What it looks like

An unbounded list on a high-traffic route:

Before
export async function GET(req: Request) {
  const events = await db.event.findMany({ where: { siteId } }); // all of them
  return Response.json(summarize(events));
}

How to fix it

  1. Paginate, and add an index for the exact filter and sort the route uses.
  2. Cache or precompute aggregates (Redis, a materialized view, or a worker that updates totals).

A real example: Umami

Computed by Skeram’s engine from the published teardown of Umami, at 100,000 monthly users (critical):

5 hot routes run list/aggregate queries per hit. /api/realtime/[websiteId], /api/websites/[websiteId]/active, /api/websites/[websiteId]/metrics… — list and aggregate scans grow with data size on your most-hit paths. What returns in 20ms with 1K rows returns in seconds at 10M rows, at exactly the moment traffic peaks.

Suggested fix: Paginate + index the hot queries; cache aggregates (the Redis node here) or precompute them in the worker.

Evidence: src/app/api/realtime/[websiteId]/route.ts, src/app/api/websites/[websiteId]/active/route.ts, src/app/api/websites/[websiteId]/metrics/route.ts.

How Skeram detects it

Skeram marks routes as hot from their role in the app and records the shape of each read. Hot routes with list, search or aggregate reads are flagged.

When it starts to hurt: A warning from about 10,000 monthly users, critical around 100,000.

Every finding cites the file and line it came from, and scanning again after a fix shows it resolved in History. How the analysis works.

Related findings

  • Requests held open on LLM calls: A request that waits on a model holds a connection for seconds; when the provider slows down, those held connections multiply until other requests can't get in.

Find it in your code

Skeram reads your repo, prices every model call from 100 to 100,000 users, and flags these patterns with the file and line.