{
  "id": 20585506,
  "title": "How to prevent spending from the same balance twice?",
  "url": "https://urgent.news/2026/11/18/ayn-bakiyeden-iki-kez-harcama-nas-l-onlenir",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-18T11:12:06.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/huseyinbozdemir/ayni-bakiyeden-iki-kez-harcama-nasil-onlenir-10dh"
  },
  "original_language": "pt",
  "account": "A bug was discovered in a banking system that occurred when two withdrawal requests were made simultaneously from the same account. The issue arose because the system checked the account balance and then updated it in two separate steps, allowing one request to pass the balance check while another request was still in progress, resulting in an incorrect balance. To fix this, the developers implemented a row lock using UPDLOCK in SQL Server, which prevents other requests from accessing the account until the transaction is complete. Alternatively, they suggested using a single UPDATE statement with a conditional check to update the balance, eliminating the need for a separate read operation.",
  "summary": "Two requests came from the same customer at the same time. Both passed our balance check. One went to the bank and returned with insufficient balance. The customer saw an error message on the screen and complained. We only learned about the issue from that complaint. There was no obvious error in the code. We were reading the balance, checking if it was sufficient, and then deducting it. This is correct for a single request. The problem is with two requests for the same account…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}