how-i-build

keepalive

A Cloudflare Worker that keeps free-tier services from falling asleep and publishes every ping as a public status page.

2026LivePrivateSole author
TypeScriptTypeScriptCloudflare WorkersCloudflare WorkersReactReactViteVite

Orbit's API runs on Render's free plan, and its databases on Supabase's free plan. Both are free because they sleep: Render after 15 minutes without traffic, Supabase after a stretch of what it calls low activity. A sleeping API means the first person to open the app waits for a cold start, and a paused database means it does not answer at all.

keepalive is the small thing that stops that from happening. It is a Cloudflare Worker with two cron triggers: one pings the API and the sites every 10 minutes, the other calls each database every hour. Whatever it sees is saved in Workers KV and served as a status page at keepalive.byjuliocesa.dev, built with React and Vite and shipped as static assets by the same Worker. When a service goes from up to down, it can post an alert to a webhook.

The repository is private. The page, its JSON and its badge are public.

A Worker that keeps Render awake

The first version did one job: a GET on Orbit's /system/ping every 10 minutes, which is shorter than the 15 Render waits before sleeping, and a daily call to each database. A Worker on Cloudflare's free plan runs crons for nothing, so the cost of keeping the free plans awake is another free plan.

Decision

A Cloudflare Worker with cron triggers, the API pinged every 10 minutes and the databases once a day, each database exposing a public.keepalive() function over its REST endpoint.

Trade-offs

  • The whole setup rests on Cloudflare keeping crons on its free plan.
  • It keeps the services awake; it does not make them fast. A cold start that happens anyway is still a cold start.

One record per cron, because of the write quota

The free KV plan allows 1,000 writes a day. A cron every 10 minutes is 144 runs a day, and writing one key per service multiplied that by every service on the list. The quota ran out on its own.

Decision

Everything one cron learns goes into a single record: the last state of each service, a daily summary for 90 days, the last 288 pings and the open incidents. One run, one write.

Trade-offs

  • The shape of the data is decided by the quota, not by how it would be easiest to read.
  • Every run rewrites the whole record, so it has to stay small.

The same day two other rules went in. A failure only counts after a second attempt, so a single slow answer does not open an incident. And a response has to contain an expected piece of text: an error page served with HTTP 200 is still a failure. The list of targets also left the code and moved into KV, so a service is added or removed with npm run config, without a deploy.

A health route that fails when the work stops

An outside monitor watched the status page, and the page always answered 200. If the cron stopped, the page kept showing the last data it had, looking perfectly healthy, and the monitor saw nothing wrong.

Decision

/api/health returns 500 when a cron is late: more than 30 minutes since the 10-minute cron last ran, more than 3 hours for the database cron. The outside monitor points there instead of at the page.

The question the monitor asks changed from "does the server answer?" to "is the work happening?". Only the second one was worth asking.

Hourly calls, because once a day was not activity

The development database was paused on 27 September even though it received the daily call, and the call did reach it: the latency was the same as the production one. Supabase pauses projects it considers low activity, and asks for a few requests a day. One a day was not enough.

Decision

The database cron runs every hour (0 * * * *). The domain's RDAP check stays once a day, at 03:00 UTC.

Trade-offs

  • Twenty-four calls a day per database instead of one, for a rule Supabase does not state as a number.
  • The health limit for the database cron was 26 hours while the call was daily; it is 3 hours now.

A status page you read at a glance

The page was redesigned from scratch with two design skills: one set the direction, the other built it and had it reviewed. The direction made each service one wide line, with its history strip taking most of the width, so the whole state reads in a glance on a phone. The strongest alternative was a departure board set in monospace; I chose the lines.

Decision

One wide line per service, the history strip as its main element. Geist and Geist Mono, a graphite ground with a cobalt accent, and Phosphor icons. The orange, the Archivo interface type and the square corners left; the logo stayed.

The review asked for six changes in its first round and approved the second. The strip has three windows: 24 hours in 72 slices of 20 minutes, 7 days in 84 slices, and 90 days in one slice per day. A response of 2 seconds or more is marked slow.

Monitoring what does not sleep

LyricsLens and BetoBita run on Vercel, which does not put sites to sleep, so they never needed keeping awake. They went on the list anyway, as monitoring on the public page. Before adding BetoBita, one check took 7.98 seconds; the first keepalive ping measured 587 ms.

The list has seven targets today: Orbit's API and web app, this site, LyricsLens, BetoBita, and the development and production databases.

References