Prisma transaction with retries for serialization errors

2805
0

Under real concurrency, even ‘simple’ write paths can hit serialization failures, especially with stricter isolation levels. Instead of pretending it won’t happen, I wrap the transaction in a small retry loop with jitter. I only retry on known transient errors (e.g. 40001 / SERIALIZATION_FAILURE); everything else bubbles up immediately. The other important piece is keeping the transaction body small—don’t do network calls inside it. This pattern is useful for counters, seat allocation, and any workflow where two requests can race. Combined with proper unique constraints, you get correctness without building a complex distributed lock system.