Skip to content

Fix/issue 2342 atomic checkout#2348

Merged
janavipandole merged 5 commits into
janavipandole:mainfrom
Prateek2007-cmd:fix/issue-2342-atomic-checkout
Jun 20, 2026
Merged

Fix/issue 2342 atomic checkout#2348
janavipandole merged 5 commits into
janavipandole:mainfrom
Prateek2007-cmd:fix/issue-2342-atomic-checkout

Conversation

@Prateek2007-cmd

Copy link
Copy Markdown
Contributor

Description

Resolves Issue #2342 (Lack of Atomic Stock Verification).

The checkout logic previously lacked any backend validation of inventory, exposing the system to severe race conditions where overselling limited-stock items was guaranteed under moderate load.

This PR introduces a robust, atomic backend verification layer.

Changes Made

  • Inventory Tracking: Extended the Product SQLAlchemy model with a stock column.
  • Row-Level Locking: Implemented a POST /api/products/checkout endpoint that enforces transactional atomic locks (.with_for_update()) on product rows during checkout processing.
  • Race Condition Prevention: The system now guarantees stock is available and safely decrements it within a single atomic database commit, rejecting the order with a 400 Bad Request if stock falls below the requested quantity.
  • Frontend Sync: Upgraded checkout.js to dispatch authentic checkout payloads instead of simulating success.

Type of Change

  • Architectural Overhaul
  • Bug Fix

@vercel

vercel Bot commented Jun 18, 2026

Copy link
Copy Markdown

@Prateek2007-cmd is attempting to deploy a commit to the janavipandole's projects Team on Vercel.

A member of the Team first needs to authorize it.

@janavipandole janavipandole merged commit 3d98fac into janavipandole:main Jun 20, 2026
12 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants