The database, not the code, refuses the overspend.

Two CHECK constraints keep every budget between zero and its cap, and the app's role can't rewrite the ledger or change the schema. Press the button and read what production answers.

Try to break it

The button connects as stub_app, the same least-privilege role the app runs as, and sends the six statements below. Each runs inside its own BEGIN and ROLLBACK, so nothing persists. The codes come straight from the database.

  1. 1
    Drive a budget balance below zero
    UPDATE accounts SET balance_micro = -1 WHERE id = (SELECT id FROM accounts WHERE type = 'agent' ORDER BY id LIMIT 1)
    expects 23514
  2. 2
    Raise a budget above its cap
    UPDATE accounts SET balance_micro = cap_micro + 1 WHERE id = (SELECT id FROM accounts WHERE type = 'agent' AND cap_micro IS NOT NULL ORDER BY id LIMIT 1)
    expects 23514
  3. 3
    Rewrite a ledger entry
    UPDATE entries SET amount_micro = 0 WHERE id = (SELECT id FROM entries ORDER BY id LIMIT 1)
    expects 42501
  4. 4
    Delete a ledger entry
    DELETE FROM entries WHERE id = (SELECT id FROM entries ORDER BY id LIMIT 1)
    expects 42501
  5. 5
    Create a table
    CREATE TABLE stub_proof_probe (id INT PRIMARY KEY)
    expects 42501
  6. 6
    Drop the entries table
    DROP TABLE entries
    expects 42501

Ten writers, one $3.00 budget

Each writer spends $1.00 with a raw UPDATE that skips the app's check, the way a script or a hotfix would. On the old schema the same ten writes took a $3.00 budget to -$7.00 in every run (20 of 20 runs, $140.00 accepted that was not there). Now the database refuses seven of them with 23514, and the balance stops at $0.00 in all 20 runs.

  • Before: no CHECK, 10 of 10 committed
  • After: CHECK validated, 3 committed, 7 refused
  • Refused write, balance unchanged
-$8-$6-$4-$2$0$2$4Start12345678910Writes, in the order they finishedBefore-$7.00After$0.00
Refused23514writes 4 to 10
Show the numbers
WriteBeforeAfter
Start$3.00 budget$3.00 budget
1$2.00, committed$2.00, committed
2$1.00, committed$1.00, committed
3$0.00, committed$0.00, committed
4-$1.00, committed$0.00, refused 23514
5-$2.00, committed$0.00, refused 23514
6-$3.00, committed$0.00, refused 23514
7-$4.00, committed$0.00, refused 23514
8-$5.00, committed$0.00, refused 23514
9-$6.00, committed$0.00, refused 23514
10-$7.00, committed$0.00, refused 23514
Measured on Aurora DSQL, connected as admin, the role the old app used, 20 runs before and 20 after. The only change between them is the schema. Each run's per-writer timeline is in dsql-race-before.json and dsql-race-after.json.

These checks came out of an AWS Well-Architected review. Every before and after number, from the database role to backups and Region failover, is on the security review page.

Read the security review

Reproduce it yourself

The guardrail tests run offline, with no database. Against Aurora DSQL, map an IAM role to the app's database role and run the probe script, which prints the SQLSTATE for each statement it sends. On local Postgres, the local test suite sends the six statements above as stub_app, and CI runs it on every push to main and every pull request.

npm test
npm run migrate && npm run db:app-role
npm run db:app-role -- grant <iam-role-arn>
DSQL_USER=stub_app npx tsx scripts/wa-probe.ts