Skip to main content

How to Connect a .NET C# Web API to a MySQL Database — Part 4: Transactions, Row Locks and Retries with MySQL

· 68 min read
Jagdish Kumawat
Founder @ Dewiride

Part 3 changed one row at a time. Real work changes several: take the stock, record why, create the order. In this part, those become one unit, you'll watch what MySQL's row locks do when two people buy the last item, and the API learns to survive deadlocks, a MySQL restart and a dropped connection. Some of it surprised me: with Oracle's provider, the retries from Part 1 retry nothing, and a short CommandTimeout can make a request hang for good.

How to Test a Race Condition in a Web API from the Terminal

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

A race condition doesn't show up when you send one request at a time. You need several at the same moment, and you don't need a load-testing tool: curl with xargs does it on macOS and Linux, and ForEach-Object -Parallel does it in PowerShell. Then check what's in the database, because the status codes alone can look fine.