DEV Community

The Phantom Heartbeat: How an App With Zero Users Kept Neon Awake for 720 Hours

My app had no users. My database was awake 720 hours that month.

It was a staging environment for a multi-tenant commerce platform. No campaigns, no shoppers, no traffic. Then, on a quiet afternoon, every request started failing: Error: compute allocation limit reached (100 hours). Database suspended until next billing reset in 3 days.

Neon's free tier gives you a monthly compute allowance, and serverless Postgres is supposed to auto-suspend after 5 minutes of inactivity. Mine had been awake 24 hours a day for 30 days, with nobody using it.

Nothing was broken. No 500s, no memory leaks, no frozen event loop. Tests passed, endpoints returned 200. The app wasn't broken, it was too diligent. It kept tapping the database on the shoulder to ask "are you awake?", and every tap reset the 5-minute suspend timer.

Here are the five culprits

  1. The health check that ran a query
  2. The unconditional background sweeper
  3. The landing page probe
  4. The dashboard that re-fetched everything on navigation
  5. Forgotten tabs polling forever

Render was probing /api/v1/health every 15 to 30 seconds. My handler did this:

apiRouter.get("/health", async (_req, res) => {
  await pool.query("SELECT 1"); // wakes Postgres 2,880+ times a day
  res.json({ ok: true });
});

To check whether the Node server was alive, I woke the database. Even with the whole world asleep, the load balancer kept Postgres running.

A BullMQ repeatable job ran every 5 minutes to expire stale orders. Orders only time out after 30 minutes, yet the worker queried Postgres every 300 seconds around the clock, even with zero orders in the system.

A well-intentioned pre-flight check in the landing page called /health on mount. Every refresh, and every search bot crawl, sent traffic through to the database.

The app shell called fetchFull() on every mount. Each click between Products, Customers, Expenses and Settings fired 10 parallel analytical queries, just to render two badge numbers.

Order confirmation and payment status views used setInterval to poll every 3.5 seconds. A test tab left open overnight meant 12 hours of continuous queries.

The fix: engineer for idle sleep

The rule is simple: nothing that can happen while nobody is using the app may touch Postgres.

Health checks answer from memory:

apiRouter.get("/health", (_req, res) => {
  res.status(200).json({ ok: true }); // no database call
});

Gate background work behind a 1-byte Redis flag

State coordination has to live outside Postgres, in a cheap store that can stay awake. Checking a table to see if work exists is itself the thing that wakes the database.

Whenever a write path creates work that will need sweeping later (checkout, signup, bulk import), it sets a flag with a 1-hour TTL:

await redis.set("app:has_active_work", "1", "EX", 3600);

Before the worker touches SQL, it checks Redis:

const hasWork = await redis.exists("app:has_active_work");
if (!hasWork) {
  return { skipped: true, reason: "IDLE_PRESERVED" }; // Postgres stays asleep
}
await sweepAbandonedOrders();

If your app has no traffic between 10 PM and 8 AM, the flag expires. For those 10 hours the worker pings Redis, finds nothing, and skips. Postgres sleeps at $0 compute.

Fail open, never lose work

If Redis is unreachable, the worker must run the sweep anyway, so tasks are never silently dropped:

let hasActiveWork = true;
try {
  hasActiveWork = (await redis.exists("app:has_active_work")) === 1;
} catch {
  hasActiveWork = true; // fail open
}

Keep Redis inside the free tier

Free Redis instances (Upstash, 25 MB) fill up if job history piles up. Cap it:

removeOnComplete: 10, removeOnFail: 25,

Fix the frontend too

  • Landing page: no API call on mount.
  • Dashboard: fetch once, cache, and refetch only on an explicit action, not on every navigation.
  • Polling views: stop when the tab is hidden and cap the number of attempts.

The bonus: recovery in under 90 seconds

With the database suspended and three days until reset, development could have stalled. Instead, all 51 schema files were versioned, idempotent, and tracked in a schema_migrations table.

Recovery:

  • Create a fresh Neon project in the same region (clean free allowance).
  • Swap DATABASE_URL locally and on Render.
  • Run npm run migrate. All 51 migrations applied inside atomic transactions.
  • Seed the admin account.

When the original project unlocked, switching back was one connection string and one npm run migrate: it skipped the applied files and ran only what was new.

The result

| Before | After |
|---|---|
| Compute | ~720 hrs/mo, awake 24/7 | ~40 hrs/mo |
| Idle behavior | Never suspends | Suspends after 5 minutes |
| Shoppers during the burn | 0 | 0 |

Get the production version

I packaged the exact implementation into a standalone kit: a compiling BullMQ v6 gated worker, a timing-safe Express tick endpoint (crypto.timingSafeEqual) for GitHub Actions or any external cron, retention settings that fit free 25 MB Redis instances, and a failure-mode matrix with a before/after verification checklist.

👉 Scale-to-Zero Jobs on Whop. 20% off launch pricing for the first 24 hours. No code needed, the discount is already on the page.

If you're building a full multi-tenant backend that feeds these queues, there's also the raw-SQL SaaS Starter API.

What's the quietest thing that has ever kept your database awake?

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.