Overview of the Stock Reservation API example
mainThe Stock Reservation API is a demonstration application built with Hono, Bun 1.4.2, and Bun.SQL, using ClickHouse Managed Postgres as the backend. It demonstrates how to handle limited inventory with transactional integrity and idempotency.
Key Features
- Transactional Integrity: All stock changes occur within Postgres transactions. Conditional inventory updates prevent over-reservation.
- Idempotency: Retrying a successful request with the same
Idempotency-Keyreturns the original reservation without consuming additional stock. - Concurrency Control: Uses unique constraints to coordinate requests using the same client identity and idempotency key across different processes.
- Release Safety: Releasing a reservation restores its quantity exactly once, even if multiple release requests are received simultaneously.