less ~/notes/escrow-is-not-a-boolean.md

Escrow is not a boolean

14 Jul 2026· 1 min read
Node.jsMongoDBEscrowPaymentsMarketplace

On a marketplace where a client pays and a freelancer delivers, escrow is the entire trust proposition. The naive model is a status field on the deal saying the money is held. That is a claim, not a mechanism.

The version that works moves the money. The balance leaves the client wallet on acceptance and sits on the deal document, which means at any moment you can sum held balances and reconcile them against real wallet totals. A flag cannot be reconciled against anything.

Release is a three-party movement: freelancer credit, platform commission, deal closure. Those three writes have to be atomic and nothing else does, so the transaction wraps exactly those three, with name lookups and notifications outside it. Wrapping the whole handler is easier to write and holds locks across work that has no business being in the critical section.

Eight states, and the ones that are not terminal are named once as a constant and reused wherever the invariant matters. A state machine whose non-terminal set is re-listed by hand in four places will disagree with itself the first time somebody adds a state.