A paste that self-destructs on first view. Two people open it at once.
transcript
This paste self-destructs after one view. Two people open the link at the same instant. Who sees it?
The obvious way: check if it's burned. If not, show it, then mark it. Both readers check at once. Both see not burned. Both see the paste. So make the check and the burn one step. One atomic update.
Both readers send the same update. Set burned to true, only where it's still false. The updates can't interleave. The first finds it unburned, and flips it. It gets a row back. Reader 1 sees the paste. The second update finds nothing to change. No row. Reader 2 gets 404.
But here's the catch. Normal pastes never change, so the CDN caches them. A burn-after-reading paste can't be cached anywhere. Every read must reach the database.
Check, then act? Two people slip through the gap. Check and change in one atomic step. Exactly one reader wins.
Full breakdown in the lecture.