lock all stateful mutations #313

Merged
RecentRunner merged 2 commits from worktree-fix-refund-idempotency into main 2026-04-15 16:02:37 -06:00
RecentRunner commented 2026-04-15 16:02:32 -06:00 (Migrated from github.com)

Summary

  • Pessimistic write locks on inventory, user, cart, coupon, pet, and password reset token rows to eliminate race conditions across all stateful endpoints
  • Coupon usage limit now re-checked at sale creation time (inside the lock)
  • AuthController.updateProfile made @Transactional so the user row lock is held for the full update
  • DataIntegrityViolationException caught in register and profile update → clean 409 instead of 500
  • Migration V6: unique constraint on users.phone as DB-level backstop

Test plan

  • Concurrent sale requests for the same low-stock product should not oversell
  • Simultaneous loyalty point redemptions should not double-discount
  • Double-submitting checkout confirmation should not create duplicate sales
  • Concurrent coupon applications at the usage limit should reject the second
  • Two adoption requests for the same pet should only create one pending record
  • Double-submitting a password reset form should not apply the token twice
  • Registering with a duplicate phone number returns 409
## Summary - Pessimistic write locks on inventory, user, cart, coupon, pet, and password reset token rows to eliminate race conditions across all stateful endpoints - Coupon usage limit now re-checked at sale creation time (inside the lock) - `AuthController.updateProfile` made `@Transactional` so the user row lock is held for the full update - `DataIntegrityViolationException` caught in register and profile update → clean 409 instead of 500 - Migration V6: unique constraint on `users.phone` as DB-level backstop ## Test plan - [ ] Concurrent sale requests for the same low-stock product should not oversell - [ ] Simultaneous loyalty point redemptions should not double-discount - [ ] Double-submitting checkout confirmation should not create duplicate sales - [ ] Concurrent coupon applications at the usage limit should reject the second - [ ] Two adoption requests for the same pet should only create one pending record - [ ] Double-submitting a password reset form should not apply the token twice - [ ] Registering with a duplicate phone number returns 409
Sign in to join this conversation.