The serverless cost-trap checklist (what never to run on a serverless DB)
The short version
Four lines of code existed to keep the app warm so users never hit a slow first load. The bill is calculated by how long the thing stays awake, so keeping it awake constantly burned a month of allowance in three days and everything stopped working.
Two lessons. Anything that runs on a timer forever is a running cost, not a one off. And a health check that only ever reports on itself will happily tell you everything is fine while the app is down.
Copy these prompts
Paste them into Claude Code (or any AI that can see your project), in this order. Each one answers a different question, and the first is usually the one that matters.
1. List everything that runs on a timer
List everything in my app that runs automatically on a schedule, including anything whose job is to keep something warm, awake or alive. For each one tell me how often it actually runs and what it exists to solve.
2. Price each one as if it never stops
For every scheduled thing in my app, tell me what it costs me per month if it runs forever at that frequency. Rank them by cost, and tell me honestly which ones I could delete today without any real user noticing.
3. Check the alarm can see a real outage
Check whether my health check would still report everything as fine if the database were completely unreachable. If it only reports on itself, show me how to make it actually test the things my app depends on.
A 4-line keepalive cron pinged my database every 4 minutes to keep it "warm." It kept serverless Postgres awake 24/7, burned the whole Neon compute quota, and every request started failing. Except the health check, which kept saying "all good." The fix was deleting code: four lines gone, outage over.
Why this happens
Serverless databases (Neon, Aurora Serverless, PlanetScale) bill on compute-hours awake, and their whole economic model is auto-suspend. Anything that touches the DB on a schedule defeats the suspend and converts your free tier into a 24/7 bill.
The checklist: never run these against a serverless DB
- Keepalive / warm-up crons. The exact thing I did. If cold starts hurt, fix them at the connection layer, not by keeping the server hot.
- Health checks that query the database. Mine returned 200 while the DB was dead. Worst of both worlds: it burns quota when things are fine AND lies when they're not. Health should check the process; a separate, low-frequency deep check can touch the DB.
- High-frequency dashboard polling. An internal dashboard of mine polled every 60s; I moved it to 5 minutes
- skip when the tab is hidden:
if (document.hidden) return; // background tabs don't poll
setInterval(refresh, 5 * 60_000); // was 60_000
- Schedulers that "check if anything is due" every minute. Batch them: run the cron hourly, process everything due since last run.
- Connection pools with long idle timeouts. Idle connections can hold compute awake. Close
idle connections client-side quickly (I use
idleTimeoutMillis: 10_000). - Fire-and-forget writes on every request (e.g.
UPDATE users SET last_seen_at). Defer, sample, or batch them.
Before you ship anything scheduled
- Ask: "does this wake the database?" If yes, ask "what breaks if it runs 10× less often?" Usually: nothing.
- Set a billing/quota alert on day one. I found out from an outage; an alert would have told me at 50%.
- Know your provider's suspend window and quota cliff numerically. Free tiers fail loudly and all at once.
Steal this for your app
- Audit every
cron.schedule(...)/ scheduled function in your repo right now and label each one "wakes DB: yes/no." - The instinct "keep it warm" comes from VPS-era habits. On serverless, the always-on habit is the bug.
- When a fix is deleting code, celebrate it in the commit message. You'll want the receipt later.
Run this on your codebase
Paste this into Claude Code in your repo:
Audit this repo for scheduled work that touches the database.
Find every cron job, scheduler, keepalive, interval poll, and health check that opens a DB connection or runs a query.
For each one, record its frequency and whether it defeats serverless auto-suspend (Neon, Aurora Serverless, PlanetScale).
Flag health endpoints that query the DB instead of checking only the process.
Flag connection pools with idle timeouts over 30 seconds and fire-and-forget writes on every request.
Propose fixes: deploy-time migrations, process-only health checks, hourly batched schedulers, and reduced polling.
Report findings as a checklist before changing anything.