My staging app had zero users. Its Postgres instance was awake for 720 hours that month. Every test was green.
Tests verify behavior. They don't verify what the system does when nobody is looking: what it costs, what it stores, what it does when a provider misbehaves. Five gaps like that kept turning up in a multi-tenant commerce backend (Node, Postgres, Redis). Each has a small, mechanical fix.
1. Idle cost: the database that never sleeps
Neon suspends compute after 5 minutes without a query. Anything that touches the database inside that window resets the timer. Four things were doing it:
- A health check running
SELECT 1, probed every 15 to 30 seconds - A queue sweeper firing every 5 minutes, with zero orders to sweep
- A landing page that pinged
/healthon mount - A forgotten browser tab polling every 3.5 seconds overnight
The rule: nothing that can happen while nobody is using the app may touch Postgres.
// Liveness answers from memory
app.get("/health", (_req, res) => res.status(200).json({ ok: true }));
// Writes that create sweepable work set a 1-hour flag
await redis.set("app:has_active_work", "1", "EX", 3600);
// The sweeper checks Redis before any SQL, and fails open
let hasWork = true;
try {
hasWork = (await redis.exists("app:has_active_work")) === 1;
} catch {}
if (!hasWork) return { skipped: true };
Failing open matters: a skipped sweep silently loses work, while an extra wake-up costs a little compute. Result: about 720 compute-hours a month down to about 40. Full write-up: The Phantom Heartbeat.
2. Stored credentials: the plaintext column
Any product that acts on a customer's behalf stores their provider keys. The naive schema is one text column, so a single leaked dump exposes every customer's key.
export function encrypt(plaintext: string): string {
const iv = crypto.randomBytes(12);
const cipher = crypto.createCipheriv("aes-256-gcm", getMasterKey(), iv);
let out = cipher.update(plaintext, "utf8", "hex");
out += cipher.final("hex");
return `${iv.toString("hex")}:${cipher.getAuthTag().toString("hex")}:${out}`;
}
GCM's auth tag makes tampering or a wrong key throw instead of returning garbage. Beyond the cipher: mask at write time (••••3f2a) so no code path can send plaintext to the browser, verify keys with a real provider handshake (pending → verified | failed), restrict writes to owners, and keep the master key in an environment variable, never next to the data.
3. Payment callbacks: twice, late, or never
Providers retry, reorder and time out. A handler that assumes one clean callback double-credits orders. The pattern is two statements:
-- Record the raw event once. A replay inserts nothing and we stop.
INSERT INTO payment_events (provider, event_id, payload)
VALUES ($1, $2, $3)
ON CONFLICT (provider, event_id) DO NOTHING
RETURNING id;
-- Guarded transition: only a pending order with the exact amount becomes paid.
UPDATE orders SET status = 'paid', paid_at = now()
WHERE id = $1 AND status = 'pending' AND total_minor = $2
RETURNING id;
Zero rows from the second statement means a mismatch or an already-settled order: log it for reconciliation, don't credit it. Around that: integer minor units, amounts computed server-side, states that can't move backwards, and a daily job that reconciles against the provider's records.
4. Design drift
Without a system, each screen invents its own colors, radii and spacing, and the product converges on the generic card grid. Treat design like code: define the tokens once and lint against them.
:root {
--space-1: 4px; --space-2: 8px; --space-3: 16px; --space-4: 24px;
--radius: 10px;
--ink: #1b1b18; --paper: #f6f3ee; --accent: #1f6f5c;
}
A linter then counts distinct colors, fonts, radii and off-grid spacing values, and flags transition: all, tap targets under 44px, and missing focus and reduced-motion styles.
5. Undefined "done"
Happy paths pass review. Empty states, error states and permission checks get skipped because nobody wrote them down. A short contract before code fixes it:
Feature: refund request
States: empty, loading, error, success, forbidden
Edge cases: partial refund, double submit, provider timeout
Done = a test per state + an audit citing file and line
Reusable versions
Each fix is packaged so you can drop it in:
| Code kits | Standards packs | |
|---|---|---|
| Contents | Tested building blocks | Skills, recipes and scripts for Claude Code, Cursor and AGENTS.md
|
| Examples | Scale-to-Zero Jobs ($24.99), Encrypted Credentials Vault ($39), Demo Sandbox ($59), SaaS Starter API | Ship-It Audit ($19), Anti-Slop Design ($29), Payments Correctness ($29), Full Library ($59) |
Packs install in one command and include a 3-minute first win and a doctor.sh that verifies the install. A free Anti-Generic Design skill is available too.
All of it: whop.com/saasplate/products
Status: each listing states what was tested and what wasn't. A/B scores for the standards packs are still to come, and I'll publish them when the evals are done.
Which of these five has cost you the most?
Written by Ludwig Maingi. More on GitHub.
Top comments (0)