Keeping Payload Jobs Alive Through Deploys
Why Payload jobs got stranded on deployments, and the worker setup that fixed it.
In July 2026, I started a full catalog sync in our content management system. The sync imports every brand, product, variant, and product image in our catalog, tens of thousands of records, and can take up to three hours. A routine deploy restarted the server partway through, and the job stopped. There was no error, no retry, and no alert. Its database record still said “processing” and it would have stayed that way indefinitely.
The problem went beyond one sync; every background job in the system could be stranded by a deployment. We use Payload CMS, and at the time, no Payload application at Fullscript had a dedicated job worker.
I proposed one, built it with our platform team, and worked through the failures that followed. Four months later, the approach runs 24 jobs across two teams and a deployment that interrupts a job now costs about a minute.
Why the job never came back
To understand what had happened to the sync, I traced how a job moved through our system. Payload stored the job as a database record, but left the application to decide which process ran the queue. In our setup, that was the web server that received the request.
That tied the job’s fate to the server’s. On Kubernetes, those servers are disposable: deployments replace them, and autoscaling removes them when traffic falls. That explained why it had stopped. What I still couldn’t understand was why nothing picked it up again.
Looking closer, I found that Payload marks a job as processing when it starts and clears that mark when it finishes or fails. But when the deployment killed the server, the job did neither. Its record remained marked as processing, so the queue kept skipping it. An abandoned job looked identical to one that was still running.
The job record survived the deployment, but the process responsible for finishing it did not.
The design
Five decisions shaped it:
- Web servers only enqueue. A request stores the job and returns immediately.
- One environment variable selects the worker. Every process runs the same build, but only the worker has RUN_JOBS enabled. The flag is read at runtime:
1constworkerAutoRun: NonNullable<Config['jobs']>['autoRun'] = async () => {2if (process.env.RUN_JOBS !== 'true') return []3return [{ cron: '* * * * *', queue: 'default', limit: 10 }]4}5
- Each worker runs as a single instance. During a deployment, the old instance stops before its replacement starts, so two copies never process the same queue.
- Payload initializes at boot. The worker receives no application traffic, so it cannot depend on a request to start Payload.
- Interrupted jobs recover automatically. The worker returns abandoned jobs to the queue at startup and every 15 minutes. Long jobs are split into steps so they can resume without repeating completed work.
Getting it over the finish line
The first version reached production within a day. The worker started, passed its health check, and reported healthy. Everything looked ready, but not a single job had run.
After some digging, I found two issues. First, Payload only starts its scheduler when initialized with cron: true, and I had left that out. Second, the environment flag that enabled the worker was being evaluated at build time, locking it to “off” before the worker ever started. Once both were fixed, jobs finally began to flow.
Getting jobs to run was only the beginning. Over the next ten days, we worked through three more failures, each one surfacing once we had fixed the previous one. The platform team built the worker deployment and joined every investigation. From there, getting it stable became a shared effort.
The next failure came within a week, when a large import ran out of memory and crashed the worker. On restart, recovery did exactly what I had designed it to do: picked up the unfinished import and tried again. That put the worker into a crash loop, and with our only worker stuck on the same import, background work across the system stalled.
We eventually traced the problem to Node.js’s default memory limit. It was using roughly half the memory available to its container, so the worker was crashing while the rest sat untouched. The platform team raised the limit with --max-old-space-size in NODE_OPTIONS, set a little below the container's 1.5 GB limit to leave headroom:
1env:2 - name: NODE_OPTIONS3 value: '--max-old-space-size=1280'4
The import that had repeatedly crashed the worker then finished in two minutes.
That solved the memory issue, but the worker still restarted whenever a full catalog sync was waiting in the queue. More processing power made no difference, and neither did a longer startup window. A platform engineer eventually traced the problem to a line I had written in the first week to start processing jobs as soon as the worker booted:
1await payload.jobs.run({ allQueues: true, limit: 10 })
Next.js could not serve requests until that startup code finished. When a three-hour sync was waiting, the worker would begin processing it before it could answer a health check. Kubernetes would restart it, recovery would queue the same sync again, and the cycle would repeat. Every production deploy waited ten minutes for the worker to become ready, then failed.
The fix was to remove await, allowing the jobs to run in the background while startup completed. The worker became ready immediately, and deploys started going through.
We also changed which endpoint the health check was called. The original endpoint loaded Payload and queried the database on every call, so a busy database or a sync in progress could make a healthy worker look unresponsive. The worker now answers from a lightweight endpoint that only confirms the process is running.
Once the full sync could run, we found the next bottleneck. Each updated record notified our main application through a webhook, so a full catalog sync sent tens of thousands of webhook calls in a single burst. The rate limiter in front of the application rejected them.
We first throttled the sender to get delivery moving again. I later rebuilt delivery so that each webhook became its own queued job, with retries and a way to replay failed deliveries.
Twelve days after the first version shipped, the restarts finally stopped.
Results
July | Today | |
|---|---|---|
Dedicated Payload workers at Fullscript | 0 | 3 |
Jobs running on this approach | 0 | 24 |
Teams using it | 0 | 2 |
Scheduled runs on workers | 0 | 130 a day |
A job interrupted by a deploy | Lost permanently | Resumes in about a minute |
The workers follow a fixed rhythm:
How often | What happens |
|---|---|
Every minute | Every queue is checked, so a new job starts within a minute |
Every 15 minutes | Each worker looks for abandoned jobs and recovers them |
Every hour | The product catalog syncs |
Every 4 hours | Data is collected from an external service |
Twice a day | Analytics events are sent, and a content feed syncs |
Together that is 130 scheduled runs a day, about 3,900 a month, with nobody involved.
Checklist for Payload jobs
- Enqueue on web servers and run on a worker.
- Read the worker flag at runtime, inside a function, and initialize Payload at boot with cron: true.
- Never await a job during startup, and keep the health check free of database calls.
- Run one worker, recover abandoned jobs at startup and on a schedule, and split long jobs into steps.
- Set the Node.js memory limit explicitly.
Conclusion
In July, a routine deploy could silently halt a job's work without an error, a retry, or an alert. Today the same deployment costs a job about a minute, and the approach behind that runs 24 jobs across two teams. It took one environment variable, one dedicated worker, and the checklist above.
