The scheduler re-queues every due PENDING job and there is no atomic "claim" when moving to PROCESSING (lib/queues/job-worker.ts:22). Multiple API instances will duplicate-execute.
Fix: Add SELECT … FOR UPDATE SKIP LOCKED or a conditional updateMany on status = 'PENDING' before processing. See ARCHITECTURE.md §8.
Deferred: The service runs in-process inside Next.js as a single long-lived process by design (ARCHITECTURE.md §8), so no duplicate execution occurs today. This only bites if the API is horizontally scaled — PM2/Node cluster mode, rolling or blue-green deploys with overlap, Docker replicas > 1, or Next.js standalone with multiple workers — none of which are on the roadmap. Revisit when multi-instance deployment is actually planned.
The scheduler re-queues every due
PENDINGjob and there is no atomic "claim" when moving toPROCESSING(lib/queues/job-worker.ts:22). Multiple API instances will duplicate-execute.Fix: Add
SELECT … FOR UPDATE SKIP LOCKEDor a conditionalupdateManyonstatus = 'PENDING'before processing. SeeARCHITECTURE.md§8.Deferred: The service runs in-process inside Next.js as a single long-lived process by design (ARCHITECTURE.md §8), so no duplicate execution occurs today. This only bites if the API is horizontally scaled — PM2/Node cluster mode, rolling or blue-green deploys with overlap, Docker
replicas > 1, or Next.js standalone with multiple workers — none of which are on the roadmap. Revisit when multi-instance deployment is actually planned.