product image

Scale-to-Zero Jobs — Serverless Postgres Cron Gating (BullMQ + Redis)

$24.99$19.99Save 20%

Background job architecture for serverless PostgreSQL (Neon, Supabase, Railway).

Stop paying cloud compute bills for idle apps. A cron running every 30 minutes wakes your serverless database 48 times a day just to query empty tables. This pattern keeps Postgres asleep until real work arrives.

CORE CAPABILITIES:

  • 1-byte Redis coordination: Write paths set a temporary flag (TTL 1h) indicating sweepable work exists, costing ~1 byte of memory
  • Gated worker execution: BullMQ workers check the Redis flag before querying PostgreSQL; no flag means the sweep skips and Postgres stays asleep
  • Timing-safe HTTP tick endpoint: Express route (POST /internal/jobs/tick) verified via crypto.timingSafeEqual for external crons (GitHub Actions, cron-job.org)
  • Free-tier Redis hygiene: Strict retention caps (removeOnComplete: 10, removeOnFail: 25) prevent memory exhaustion on free 25MB Redis tiers
  • Fail-open safety: Automatically falls back to safe query execution if Redis becomes unreachable, preventing stuck records

STACK:
TypeScript, BullMQ v6, Redis (IORedis / Upstash), Express, Node.js Crypto

INCLUDES:
Architecture guide (README.md), compiling BullMQ v6 queue template, timing-safe HTTP tick router, writer-side tracking helper, and GitHub Actions cron workflow.

TERMS:
Single commercial project license. Full refund within 7 days if the templates fail to compile under TypeScript strict mode as documented.