The brief
A real-time auction product: multiple auction houses, each running scheduled events with live bidding, chat and a countdown. The commercial requirement — “one active lot at a time” — sounds like a UI rule. It is a data invariant, and treating it as a UI rule is how double-sold lots happen.
The design
- Shared schema, org_id everywhere. Tenancy is a data boundary, not a deployment boundary: one migration path, one connection pool, cross-tenant reporting without a second system.
- Composite foreign keys. A lot cannot point at another org’s auction; a bid cannot point at another org’s lot. Postgres rejects the reference, not a service.
- A partial unique index enforcing one open lot per auction:
create unique index … where status in ('open','closing'). Two open lots become physically impossible, even with a buggy service or a manual SQL fix. - RPC discipline. Clients never send
org_id; server functions derive it from the resource id and never trust a body field. - pgTAP isolation tests in CI that create two orgs and assert every table returns zero rows across the boundary.
The delivery plan
A 12-week pilot: marketplace shell, auction mechanics, buy-it-now and pre-bids, moderation, and a full rehearsal before the first real sale. The plan was staged so the current product kept running while the new engine was built.
Why it matters
Most “we’ll add security later” decisions are architecture decisions made early and paid for late. A schema with tenancy and invariants built in costs a little more in week one and removes an entire class of incident later.
Status: architecture and delivery plan. Stack: PostgreSQL, Supabase, Next.js, realtime.
Send me the shape of it.
Stack, team size, what hurts. I'll tell you honestly whether I'm the right fit and what I'd do first.