A cron job that matters enough to run on two machines has changed category. It is no longer a timer with a function attached. It is a distributed system.
On one machine, the scheduler starts a job and assumes it owns that execution. Add a second machine for availability, and both schedulers may observe that the same job is due. If duplicate work means sending the same cleanup query twice, that may be acceptable. If the job submits a settlement instruction or broadcasts a blockchain transaction, the second execution may be irreversible.
This is where “at most once” stops being free.
The basic lease
A common coordination mechanism is a lease stored in a shared database. The row usually contains:
A job identifier
The current owner
An expiry timestamp
A monotonically increasing fencing token
Acquisition must be atomic. Two workers cannot read an expired row and then both decide they own it.…