Prisma·
Race conditions in serverless apps: fix them in Postgres
TL;DR
Concurrent serverless requests can oversell stock, double-book seats, or overwrite changes because checking data before writing leaves a race window—even inside a default transaction. The post shows how to enforce correctness in Postgres using conditional updates, row locks, version checks, and constraints, with Prisma examples. In one test, a conditional update let exactly one of 20 buyers purchase the last ticket, safely rejecting the other 19.
Relevant links
- Kiril Urbonaswww.devopsness.com
- Prisma ORM 8www.prisma.io
- Prisma Computewww.prisma.io
- Prisma Postgreswww.prisma.io
- default isolation levelwww.prisma.io
- inside a transactionwww.prisma.io
- connection poolerwww.prisma.io
- building a job queue in Postgreswww.prisma.io
- exclusion constraintwww.postgresql.org
- hosting a booking appwww.prisma.io
- ON CONFLICT DO NOTHINGwww.prisma.io