37
Domain models
largest schema I have shipped
platform · 2025 · client unnamed
Two-sided marketplace for architecture and design work: the platform holds the money until delivery is confirmed, with bidding happening in real-time chat.
37
Domain models
largest schema I have shipped
15.4k
Application code
lines, excluding docs
8
Deal states
escrow state machine
6s to 2s
Response time
after database profiling
The problem
Design work in this market runs on trust and cash. A client hands money over and hopes; a freelancer delivers and hopes. The platform had to hold the money until delivery was confirmed, run the negotiation in real time, and vet freelancers before they could bid, while also carrying a materials catalogue and a course library in the same product.
The approach
Four systems that would normally be separate products, against one 37-collection schema: a marketplace with escrow, a real-time chat where the bidding actually happens, a supplier materials catalogue, and a course platform whose completion records feed freelancer ranking. The spine is an eight-state deal machine where the escrow balance is not a flag but money physically moved out of the client wallet and parked on the deal document.
Architecture
Escrow is the core invariant. Money leaves the client wallet on acceptance and sits on the deal until completion or cancellation, when a narrow transaction splits it between freelancer and platform. Real-time chat drives negotiation, so socket load scales with active deals rather than registered users.
Each with what it cost
A decision without a stated tradeoff is a preference.
01
Why
Only the three writes that must be atomic sit inside the session: freelancer credit, platform commission, deal status. Name lookups and notifications happen outside it.
What it costs
More code than wrapping the whole handler, but the transaction window stays small enough that lock contention never becomes the bottleneck under concurrent completions.
02
Why
A freelancer defaults to pending approval, a client defaults to approved. The vetting requirement lives in the schema rather than being remembered in a controller.
What it costs
Logic in the model layer is unusual, but it makes the invariant impossible to forget at any of the signup paths.
03
Why
A phone number can have many soft-deleted rows and at most one active account, which a unique index cannot express.
What it costs
The invariant depends on the signup paths checking correctly, so those checks are centralised rather than duplicated.
Outcome
Live in production. Money moves between three parties, held and released against confirmed delivery, with the platform commission split out atomically on completion. Response time cut from roughly six seconds to two.