AIPricingLabQ&A
Q&A

What is the reserve / commit / release pattern?

reserve atomically holds quota with a 60-second TTL; commit confirms the reservation after the AI call succeeds; release rolls it back on failure. Reservations auto-release on crash. The only correct way to enforce AI quotas under concurrency.

Last updated: 2026-05-10

Why it exists

The naive flow - canUse → call OpenAI → track - has a race window. Two parallel requests can both pass canUse before either has tracked. Reserve / commit / release closes that race by making the check-and-increment atomic.

Lifecycle

reserve(): the slot is yours for 60 seconds. commit(): confirm - counter stays incremented. release(): roll back - counter decrements. No call: auto-releases after 60 seconds.

Why 60 seconds

Long enough for almost every AI call (LLMs, images, agent loops). Short enough that crashed workers don't leak quota for long.

Related questions