Reliability
A canary that runs real billing in production without touching a customer
Billing automation can only be proven by running it. Here is how it runs in production, several times a day, inside a tenant that can never reach live Stripe.
The problem
Billing automation is easy to test locally and hard to trust in production. It depends on Stripe webhooks, background jobs, email delivery and who holds which role. Any of those can differ in the real environment.
I had just shipped the emails that chase payment after a contract is signed. No incident prompted what came next. The problem was structural: production sends every real tenant through live Stripe, so a production test needed a tenant that could never do that.
A tenant that cannot go live
The canary is a dedicated tenant in the production database, forced to Stripe test mode. It creates a company, a person and a contract, then runs real scenarios: a signed contract with payment switched off, test-mode Stripe checkouts in a headless browser, and a failed payment driven by Stripe's test clock.
It is deliberately not a demo tenant. The demo reset would wipe it.
The guard chain
Nothing in a request can choose the organization, the recipient or the time. The tenant comes from configuration, and it has to appear on an allowlist as well.
function loadCanaryConfig(): CanaryConfig {
const tenantId = readConfiguredTenant();
const allowed = readAllowedTenants();
// The tenant comes from configuration, never from the request,
// and it must also appear on a separate allowlist.
if (!allowed.includes(tenantId)) throw forbidden('Tenant is not allowlisted');
return { enabled: readKillSwitch(), tenantId };
}Configuration alone was not enough. With only an environment setting, a runtime that was missing it would treat the canary as an ordinary tenant and offer it live Stripe. So the tenant also carries a marker in the database, and every operation checks it again.
// Configuration alone is not trusted. The tenant must also be marked
// in the database, and must not be a tenant the demo reset can touch.
if (!tenant.isDedicatedCanary || tenant.isDemo) {
throw forbidden('Not a dedicated canary tenant');
}
// A live payment connection is always a hard stop, never a warning.
if (paymentConnection.mode !== 'test') {
throw forbidden('Canary tenant is not in test mode');
}
// ...further checks on recipients and roles run before anything is written.Emails are real, but they only go to the canary's own mailbox, with a fresh address for each run. A check on the sender configuration runs first and sends nothing.
Asserting that nothing happened
For each scenario the canary reads the result from the database: which emails were rendered, which alerts fired, which tasks were created, and whether a webhook delivered twice was handled once. I chose durable records over the screen or an inbox.
One scenario checks for nothing. A signed contract with checkout disabled must create no email sequence, no outbound send, no task, no Stripe customer and no billing row.
// The scenario where checkout is switched off expects nothing at all.
const expected =
scenario === 'checkout-disabled'
? { emails: 0, alerts: 0, tasks: 0, paymentRecords: 0 }
: expectedFor(scenario);
const actual = await countWhatTheRunCreated(run);
if (!sameCounts(actual, expected)) {
throw new CanaryAssertionFailed(scenario, { expected, actual });
}Automation that fires when it should not is the failure that reaches a customer. A test that only checks the happy path never looks for it.
Dry run by default
There is a kill switch, and the workflow does nothing until it is explicitly enabled. The command-line tool prints what it would do and stops. Running against production takes two separate flags.
const confirmed = args.includes(CONFIRM_FLAG);
const acknowledgedProduction = args.includes(PRODUCTION_FLAG);
if (!confirmed) {
print({ dryRun: true, wouldRun: scenario });
return; // the default is to describe the run and stop
}
if (!acknowledgedProduction) {
throw new Error('Running against production needs a second, explicit flag.');
}Two lanes, and silence is failure
- The fast lane uses Stripe's test clock. It runs after every production deploy and on a daily schedule.
- The rolling lane follows a real fourteen-day cycle and never fast-forwards production time. It checks in at thirty minutes, day three, day seven and day fourteen.
- A ledger allows one active run per lane and expires runs after a day. Cleanup verifies a record belongs to the run before deleting it.
If the canary is enabled and no runs appear, it alerts. The health check itself fails if that alert cannot be delivered. The dashboard is read-only, with no controls to run, disable or clean up.
What it found
- On its first production run, an internal notification that would have gone to the company's normal distribution lists.
- A real webhook bug. When two deliveries raced, the loser waited thirty to sixty minutes for Stripe to redeliver, leaving billing records stale. I fixed it with a retry inside the request.
- Organizations created before a certain date were missing a starter template, which led to a backfill. It also caught a tenant with no sender configured.
It was wrong about itself too. It raised false alarms several times, and I found its health report had been saying every scenario passed while it was failing three times a day. I fixed both.
What I can't tell you from the record: how many runs it has made, or its pass rate. The repo does not record either.