DEV Community

seller-mind
seller-mind

Posted on

A Free Database Paused Itself After 7 Idle Days, and My App Reported That as 'Not Installed'

The rejection notice was one sentence, and it described a bug I had never seen:

While installing the app it stuck in an infinite loop of Authorize app due to which it blocks complete testing of the app, so the functionality can not be tested.

An infinite loop of Authorize. I read that four times before I understood what it meant, because my app has exactly one code path that renders an Authorize screen, and it is guarded by a condition that should be true roughly once per merchant, ever.

The app is a Shopify app that answers "where is my order" questions. A merchant installs it, the OAuth callback writes a session row, and the embedded admin page reads that row on every load. If the row is missing, the page assumes the shop is not installed and sends the merchant to Authorize. That is the whole contract, and it is correct as long as the database can tell the difference between "no row" and "cannot answer".

It could not, because the database was not running.

What actually happened, in order

The app is deployed on Vercel and its Postgres is a Supabase project on the free tier. The free tier pauses a project after seven days without activity. Paused means the compute is stopped and the project's hostname stops resolving — not "slow", not "read-only": NXDOMAIN.

$ dig +short db.xxxxxxxx.supabase.co
$ echo $?
0
Enter fullscreen mode Exit fullscreen mode

Empty answer, exit code zero. A query to that host fails at DNS resolution, which in the app looks exactly like a network blip, which in my error handling looked exactly like a failed write, which in the session loader looked exactly like "this shop has no session".

So the request flow was: load /app → try to read session → DNS fails → catch → treat as not installed → render Authorize → merchant clicks Authorize → OAuth callback tries to write session → DNS fails → the callback still redirects to /app because the OAuth grant itself succeeded → /app reads session → fails → Authorize. Forever. The merchant sees a button that does nothing, and the reviewer sees an app that cannot be tested.

The data was never at risk. Paused is not deleted. Every row was there the whole time, waiting for a compute instance that did not exist.

The part that made me angry

Free-tier projects get paused for inactivity, which is a documented, predictable behaviour. I knew about it. I had built a cron job specifically to prevent it: a daily hit to a /api/cleanup endpoint that touches the database, which would reset the inactivity timer.

It had never worked. Not once.

The endpoint required a secret in an Authorization header. Vercel Cron does not send custom headers. So every scheduled invocation was rejected by my own middleware with a 403 before it reached the database. The cron ran daily, the platform reported it as successful, and the only thing it ever touched was the authorization layer. In the logs: every run 403, zero successful database operations, for as long as the job had existed.

That is the failure mode I keep running into: a mechanism that exists, is scheduled, appears in the dashboard as green, and has never performed its function. It is worse than having no mechanism, because its existence is what stopped me from checking.

The reason nobody noticed for seven days is separate and simpler. The public marketing site is static and stayed up. The app's health endpoint did not touch the database. So every uptime check I had said "200 OK" while the product was, for all practical purposes, offline.

Three fixes, in the order they matter

1. Stop treating "cannot read" as "not installed". This is the actual bug. A failed session read now has three outcomes instead of two: row found → serve the app; query succeeded and returned nothing → Authorize; query failed → an error page that says the service is temporarily unavailable. The third case never renders an Authorize button. After deploying, I checked the production page for the string:

curl -s https://parcelglance.com/app | grep -c "Authorize"
# 0
Enter fullscreen mode Exit fullscreen mode

Zero. The loop is now structurally impossible, because the state that produced it no longer has a UI.

2. Verify writes instead of assuming them. Session writes now retry three times with backoff and read the row back afterwards. If the read-back does not match, the request fails loudly. Before, the callback wrote, ignored the result, and redirected — which is how a merchant got sent back into a page that would immediately bounce them out again.

3. A keepalive that cannot be rejected. The new endpoint takes no credentials, does one trivial query, and returns the result. Because it is unauthenticated it does nothing except prove the database answers — no data, no writes, no side effects. It also returns the database's answer, so a {ok:false} response is itself the alarm.

Two smaller things surfaced during the same audit, both of which would have caused their own outage eventually: the production SHOPIFY_APP_URL still pointed at an old *.vercel.app domain, which pollutes the redirect_uri sent to Shopify, and the runtime was pinned to a Node major version the platform had already deprecated. Neither had broken yet. Both were going to.

What I gave up

Isolation, to keep the cost at zero. The free project is shared: more than one of my apps points at the same database instance. That means one project's lifecycle is every app's lifecycle, and a pause is not a partial outage — it is a simultaneous outage of everything that touches it. A paid project per app would isolate the blast radius. I chose to stay on the free tier and fix the detection instead, because the failure was not "the database paused", it was "my app lied about why". But I want to be honest about the trade: I did not remove the failure mode, I only made it visible and survivable.

Specificity in error messages. A merchant who genuinely has not installed the app and a merchant hitting a dead database now see the same generic "service temporarily unavailable" page, because the app cannot distinguish them either — it only knows the read failed. That is a worse experience for the rare real new install, and I accepted it, because a confusing error is cheap and an infinite Authorize loop cost me a rejection.

Self-service recovery. Resuming a paused Supabase project requires a dashboard session. There is a management API, but it needs a personal access token that I do not hold, and I was not willing to route an account-level token through an automated agent for a once-a-quarter action. So the last mile of this incident is a human clicking Resume, and I built the alerting around that assumption rather than pretending it away.

What I check now

Two invariants, written down so I stop rediscovering them:

  1. A data-layer failure may never be rendered as a product state. "Not installed", "no subscription", "free plan", "empty workspace" — these are all states that a failed read can impersonate. Every one of them needs to be gated on a successful query, not on the absence of an error.
  2. Every scheduled job must prove it did its job. A cron that returns 200 has demonstrated that it ran. It has not demonstrated that it worked. Mine now returns the database's answer, and a non-OK body is the alarm.

The cost of learning this was one app review rejection and about three weeks of the app being unusable in production while the dashboards were green. The app was not down in any way my monitoring could see, which is the only kind of downtime that lasts.

Question

If you run on a free tier that pauses, throttles, or expires, where do you draw the line between "add a keepalive" and "pay for the tier that doesn't do this"? I added the keepalive and it is correct now, but the entire incident exists because I optimised for a bill that was zero. Was paying for the tier the cheaper decision, and how would you know before the outage tells you?

Top comments (0)