A critical region is the small, coordinated part of a request that performs the core state change atomically. It handles conflict checks, writes, and idempotency before asynchronous side effects begin. section 8.4
Keep the region narrow and give it explicit concurrency controls:
- Wrap the state change in one database transaction, from BEGIN through COMMIT. section 8.4
- Use an idempotency key with a UNIQUE constraint to prevent retried requests from creating duplicates. section 8.4
- Choose optimistic locking with version checks or pessimistic locking with SELECT ... FOR UPDATE. section 8.4
- Exclude emails, webhooks, and other follow-up work so lock windows stay short. section 8.4
Booking request
After validation and rate limiting, a booking request checks for conflicts, writes the booking, and records its idempotency key inside one transaction. The API returns 201 only after commit; email and webhook delivery happen afterward. section 8.4
Figure 8.6 A typical API request has three phases: synchronous pre-flight checks the user waits for, a core database transaction, and asynchronous follow-up work that runs after the 201 response is sent.

Use the request-phase diagram to distinguish edge gating, the critical region, and asynchronous follow-up work. section 8.4









