nsf/sqlrace — explained in plain English
Analysis updated 2026-08-07 · repo last pushed 2015-10-28
Teach students how race conditions corrupt data when multiple workers update the same database row simultaneously.
Demonstrate that a standard database transaction alone does not prevent lost updates under concurrent access.
Compare row locking versus atomic updates to find the safest and fastest strategy for concurrent decrements.
Simulate an e-commerce oversell scenario where two customers buy the last item in stock at the same time.
| nsf/sqlrace | beppetemp/cartographer | d4l3k/turtle | |
|---|---|---|---|
| Stars | 8 | 8 | 8 |
| Language | Go | Go | Go |
| Last pushed | 2015-10-28 | — | 2018-01-27 |
| Maintenance | Dormant | — | Dormant |
| Setup difficulty | moderate | moderate | moderate |
| Complexity | 2/5 | 4/5 | 2/5 |
| Audience | developer | developer | developer |
Figures from each repo's GitHub metadata at analysis time.
Requires a running MySQL-compatible database and Go installed to build and execute the demo.
SQL Race is a teaching tool that demonstrates a common but tricky bug called a "race condition" in database applications. It shows that simply wrapping database operations in a transaction does not, by itself, prevent data corruption when multiple processes try to change the same data at the same time. A race condition happens when multiple workers all try to read and update the same piece of data at once, stepping on each other's toes. This tool runs a simple experiment: it starts with a counter set to 4,096 and asks four workers to subtract 1 from it repeatedly, over a thousand times each. If everything works correctly, the counter should reach zero. The tool lets you test different strategies for updating the database, ranging from a naive approach with no protection to more sophisticated methods. The demo's output tells the story clearly. When the workers use the naive approach, the final result is wrong, they lose some decrements because the workers overwrite each other's changes. Switching to a standard transaction does not fix the problem, the result is still incorrect. Only two methods get the right answer: locking the row so no one else can touch it until the update is complete, or using an atomic update where the database itself handles the subtraction safely. This project is aimed at developers and students learning about database concurrency. A practical example would be an e-commerce checkout where two customers are buying the last item in stock simultaneously, without proper safeguards, both might succeed, and the store oversells. The demo proves that you need specific techniques like row locking or atomic operations, not just transactions, to keep data accurate under concurrent load. The project is written in Go and requires a MySQL-compatible database to run. The README notes that the atomic method is also the fastest, since it avoids the overhead of locking, making it both correct and efficient.
A teaching tool in Go that demonstrates race conditions in databases. It shows how concurrent workers corrupt shared data and proves that transactions alone aren't enough, you need row locking or atomic updates.
Mainly Go. The stack also includes Go, MySQL.
Dormant — no commits in 2+ years (last push 2015-10-28).
No license information is provided in the repository, so usage rights are unclear.
Setup difficulty is rated moderate, with roughly 30min to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Verify against the repo before relying on details.