How In-Process Cron Jobs Break When You Scale Horizontally
A developer discovered duplicate database records after scaling a NestJS service to three instances, each running its own in-process cron job simultaneously at 08:00. The built-in @Cron decorator schedules jobs inside every running process, so horizontal scaling multiplied job executions rather than distributing them. Three options were considered: distributed locking, idempotency checks, or moving scheduling outside the app entirely. The developer chose to remove @Cron and expose a standard HTTP endpoint triggered by a single external scheduler, ensuring only one job run per cycle. An idempotency check was retained as a fallback to handle retries or accidental re-triggers safely.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in