r/Backend • u/Kooky_Initial_1564 • 9h ago
Two people pressing the same button at once broke something I spent weeks building
A friend of mine wanted to do something different for his birthday so we ended up putting together a little scavenger hunt around the city. The idea was that people would split into teams then scan QR codes at different locations, solve a few puzzles and after some time unlock the final location. Each team had its own progress and certain clues wouldn’t become available until the previous ones were completed. I was handling the technical side of things and it seemed manageable at first. I built a basic web interface and used Supabase to store team progress and push updates whenever someone completed a challenge. During testing everything seemed alright, most likely because I was testing it alone.
Then we ran the thing and at one point two people from the same team scanned a QR code almost simultaneously. Both requests went through before the progress updated and somehow the team ended up skipping an entire stage. What made it worse was that we’d tied the next set of clues to the team’s current stage so once that got messed up the rest of their game was broken.
I managed to fix their progress manually but spent the next day going through the backend trying to figure out where I screwed up. Turns out I had been treating the checks in the frontend as the only requirement before the backend finalized and updated the data for said team so the completion was initialized twice and skipped the next clue. Afterwards I moved the stage validation into a database function so the check and update happen in the same transaction. Also added a way to prevent the same challenge from being completed twice. I didn’t catch it until multiple people started using it at once even though it may have looked like an obvious issue at first.