Menu

Why a Lease Is Not Enough to Stop Duplicate Scheduled Jobs
📰

Why a Lease Is Not Enough to Stop Duplicate Scheduled Jobs

DEV Community: backend·Christian Pichichero·12 days ago
#lIksA7P3
#devtobackend#devto#dev#lease#token
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.