AI code review
Evaluate generated code for correctness, security, and reliability.
What is wrong with this example NestJS service?
The example performs a read, checks stock in application code, and later writes a modified value. Those steps are not one atomic operation, so another request can change the record between them. It also trusts the quantity without showing validation, making both business-rule and concurrency bugs possible.
How can an atomic update prevent overselling?
A conditional atomic update makes the database check availability and reduce stock as one write operation. This avoids the application-level read/check/write gap. It protects the stock row, but related reservation records and repeated client submissions still need their own transaction and idempotency design.
Difficulty is an editorial estimate. Completion means you chose to mark a question as understood.