DEV Community

Odumosu Matthew
Odumosu Matthew

Posted on

Race Conditions in Production: When Two Requests Compete for One Resource

π’π¨πŸπ’πš 𝐒𝐬 𝐒𝐧 𝐌𝐚𝐝𝐫𝐒𝐝. π‰πšπ¦πžπ¬ 𝐒𝐬 𝐒𝐧 𝐓𝐨𝐫𝐨𝐧𝐭𝐨.

Both find the same small hotel in Lisbon for the same weekend. Both see β€œOnly 1 room left!”

At exactly the same second, both tap β€œBook now.”

Who gets the room?

In a badly built system, both do. Two confirmations. One room. One very awkward morning at the front desk.

Engineers call this a race condition: two operations each make a decision on information that’s about to become wrong.

Exactly the same scenario plays out in payments, just with money instead of rooms. Two withdrawals, one balance, same moment.

Which of the five fixes have you used in production?

race condition

Top comments (0)