The diff is green. The tests pass. Somewhere in the middle, a line now updates a row that used to be write-once. You scroll past it. You approve.
Review is a person reading, and people get tired. An agent can produce the next diff as quickly as the first. Which rules can you make the database check on every write?
Give retries a durable key
Try this in a disposable Postgres database:
CREATE TABLE sends ( id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY , idempotency_key text NOT NULL UNIQUE , recipient text NOT NULL , status text NOT NULL CHECK ( status IN ( 'queued' , 'sent' , 'failed' ) ) ) ;
INSERT INTO sends ( idempotency_key , recipient , status ) VALUES ( 'order-42-receipt' , '[email protected]' , 'queued' ) ;
INSERT INTO sends ( idempotency_key , recipient , status ) VALUES ( 'order-42-receipt' , '[email protected]' , 'queued' ) ON CONFLICT ( idempotency_key ) DO NOTHING ;
SELECT count (*) FROM sends;
Enter fullscreen mode
Exit fullscreen mode
The count is one.…