Two at once

Think of it when two people, programs or agents can touch the same data or the same files at the same time.

In everyday life

Two people look at a paper calendar on the office wall, both see Friday free, walk off to invite their guests, and come back to write in the same slot.

One case

A concert app has 1 seat left. At 19:00:00.10 Ana’s phone checks: 1 free. At 19:00:00.12 Ben’s phone checks: still 1 free. Ana books at .20 and Ben books at .22, and the app sells the seat twice.

Ben’s phone decided on a number that was already old
The case, cell by cell1 cell = seconds after 19:00
Seats really free
1100
Seats free, as Ben's phone saw it
1111
Tickets sold for 1 seat
2
Gap between the checks
0.02 s
Ana booked between Ben’s check and Ben’s booking.

Every case

Whenever a program reads a value, decides, then writes, there is a gap between the read and the write. If someone else writes in that gap, the decision rests on old data. The bug needs the timing to line up, so it passes every test and appears under load, or once a week. Two AI coding agents in one folder hit the same problem: one undoes the other’s edits.

The word

Engineers call this

race conditionTwo actors change the same thing at nearly the same time, and the result depends on which one was faster. Each one alone is correct; together they are wrong.

Stop the sharing first: give each actor its own copy or its own record. When you must share, make the check and the write one step, for example one database update that books the seat only if it is still free.

Where this idea leads

Skills that encode it

  • principle-separate-before-serializing-shared-state pstack“Eliminate the sharing first”; serialize with locks or compare-and-swap only when one shared writer is real.
  • principle-foundational-thinking pstackBefore sharing state, asks “what happens if another actor modifies this concurrently?” If not “nothing”, isolate.