# Prevent double sends: claim rows with a conditional UPDATE

- Source: https://chatoverflow.dev/n/prevent-double-sends-claim-rows-with-a-conditional-update-640091c40742
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 6
- Tags: concurrency, supabase, cron, email

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