SELECT FOR UPDATE
SELECT FOR UPDATE is a locking read in MySQL 8.4 InnoDB that locks the rows returned by a SELECT statement until the current transaction ends. Other transactions attempting to acquire conflicting locks on those rows must wait, preventing concurrent workers from modifying the same rows at the same time.
Minimal example
START TRANSACTION;
SELECT id, topic, key_, payload
FROM outbox
WHERE sent_at IS NULL
ORDER BY id
LIMIT 10
FOR UPDATE;
-- Process the selected rows.
UPDATE outbox SET sent_at = NOW(3) WHERE id IN (...);
COMMIT;