SShortSingh.
Back to feed

Concurrent Checkout Bug Lets 20 Buyers Purchase One Ticket, and Two SQL Fixes

0
·2 views

A developer found that a check-then-act purchase function in Node.js and PostgreSQL oversold a single concert ticket up to 20 times, even though the stock count still ended at zero. Twenty simultaneous buyers all read the stock before any write occurred, so each passed the availability check. Wrapping the logic in a plain transaction did not solve the problem under PostgreSQL's default isolation level. The article presents two fixes: a single atomic UPDATE with a stock condition, and SELECT ... FOR UPDATE to lock the row while the transaction runs. Both approaches prevented overselling in the author's tests.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Guide Shows How to Scrape LinkedIn Job Postings Without Logging In

A developer tutorial explains how to collect LinkedIn job listings using public pages that are visible to logged-out visitors. It describes two sources: a paginated search endpoint that returns job cards with IDs, titles, companies, locations and posting dates, and individual job pages that include descriptions, criteria, applicant counts and sometimes salary. The author notes that some fields, such as external apply links, workplace type, job function and the poster, are only available to signed-in users or must be inferred from the text. The piece includes Python code using requests and BeautifulSoup, and the author discloses that they maintain a commercial LinkedIn jobs scraper on Apify. The approach was tested in November 2026.

0
ProgrammingDEV Community ·

dol8: A Python CI/CD gate that blocks pull requests with energy regressions

dol8 is an open-source CI/CD gate that stops pull requests from increasing a Python program's CPU energy use. It reads real RAPL energy measurements on bare-metal Linux and falls back to perf counters on virtual machines or CPU-time estimates on Windows. Its measurement core is written in Rust via PyO3, keeping the measurement separate from Python's own overhead, while Python handles statistics and orchestration. Every result is labeled with its measurement source and confidence, the gate avoids failing builds on noisy data, and comparisons across measurement types are blocked. The project is at v0.4-alpha under the MIT license, validated on AMD Ryzen, with Intel validation still in progress.

0
ProgrammingDEV Community ·

Kaze: A Go Terminal Client That Searches Multiple Sources and Drives mpv Over IPC

After repeated gaps in ani-cli, the developer built Kaze v4.3.0, a single static Go binary for Windows, macOS, and Linux that searches several sources at once. Queries run concurrently under a 3-second timeout, with results streamed into a Bubble Tea UI, and AUTO mode switches to another mirror when a CDN fails. The app controls mpv through IPC, using Unix sockets on Linux and macOS and Windows Named Pipes on Windows, which avoids shell injection and enables live shader swaps and skip-chapter controls. A security audit also removed an unsafe mpv TLS-bypass flag and added IP checks at dial time to block SSRF and DNS rebinding attacks.

0
ProgrammingDEV Community ·

A Single Line Made a Python Queue 2,500 Times Slower: Why list.pop(0) Is Costly

A developer found that processing one million tasks from a Python list took about 58 seconds because each pop(0) call shifted every remaining element. Replacing the list with collections.deque and using popleft() cut the runtime to roughly 0.023 seconds on Python 3.15.2 on an Apple M4. The article explains that list removal and insertion at the front cost O(n), so total work grows quadratically as data increases. It also covers related slowdowns, such as repeatedly building lists with out = out + [x] and string concatenation with += when the string has extra references. The author recommends deque for queues, append or += for lists, and str.join for building strings.