Skip to content

perf(api): slow pg-boss polling to cut Vercel Fluid CPU use - #62

Merged
CodeWithEugene merged 1 commit into
mainfrom
perf/reduce-queue-polling
Nov 3, 2026
Merged

CodeWithEugene merged 1 commit into
mainfrom
perf/reduce-queue-polling

Conversation

@CodeWithEugene

Copy link
Copy Markdown
Owner

Why

Production hit the Hobby fair-use limit for Fluid Active CPU (hack-village was ~53% of the team's ~3h50m over 30 days) with almost no traffic. instrumentation.ts starts pg-boss on every serverless boot. It registers about 10 workers at the default 2s poll, so each warm instance runs roughly 5 queries per second and burns CPU while idle.

What

  • Job workers poll every 30s (was 2s).
  • Cron workers poll every 60s.
  • pg-boss cronMonitorIntervalSeconds and cronWorkerIntervalSeconds are 45s (the maximum) and maintenanceIntervalSeconds is 600s.

Impact

  • About 15x fewer polling queries per warm instance.
  • Jobs may start up to 30s late and cron sweeps up to 60s late. That is well inside the 1-hour payout KPI.
  • Timing only: no change to payout, escrow or rollback logic.

Notes

  • This touches the payout.* and escrow.* worker registrations (timing only), so the escrow/payout review rules apply.
  • tsc --noEmit passes. Integration tests not run locally (need Postgres); CI will run them.
  • If CPU is still high, the next step is moving the worker off Vercel.

Workers polled Postgres every 2s each, so every warm instance burned
Active CPU even with no traffic and the Hobby limit was exceeded.
Job workers now poll every 30s, cron workers every 60s, and the
scheduler and maintenance loops run less often.
@CodeWithEugene
CodeWithEugene changed the base branch from dev to main November 3, 2026 07:31
@CodeWithEugene
CodeWithEugene merged commit 458420b into main Nov 3, 2026
6 of 7 checks passed

This branch was successfully deployed

1 active deployment
Preview — ac9f46c7 Deployed Nov 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant