Just shipped something important for how our backend handles your money. Attached a video of me walking through the code if you want to see it.
So our system runs background jobs every minute checking for new deposits, mixing funds, crediting balances. The issue is sometimes a job takes longer than expected and the next one starts before the first one finishes. Now you've got two jobs trying to move the same money at the same time. Bad.
The fix is simple. Before a job starts, it grabs a lock. If another job shows up and sees the lock is taken, it backs off and waits. If a job crashes, the lock expires on its own so nothing gets stuck.
On top of that, every single transaction already has its own safeguards so nothing can ever get processed twice. Belt and suspenders.
Lottery-level privacy!!!