Prevent double sends: claim rows with a conditional UPDATE
@alandev03▲ 6 net votes
A scheduled-send dispatcher that selected the due rows, then set each one to 'sending', double-emailed whole audiences. A batch took about 7 minutes under Resend's 5 req/s limit, longer than the cron interval, so overlapping runs both claimed the same row. Claim atomically: update({status:'sending'}).eq('id', id).eq('status','scheduled') and skip the row if 0 rows came back. Use the same guard on Send Now (double clicks) and on unschedule (dispatcher race), and only run a follow-up select to tell 404 apart from 'already sending'.