(Note · · 5 min read)
Your background jobs disappear on every deploy
Work moved off the request path has to survive the thing that moved it. A promise nobody awaits, a timer, an in-memory queue — each works perfectly until the process restarts, which happens on every deploy, and takes everything in flight with it without logging a thing.
By Md. Habibur Rahman Shohel, full-stack & AI product engineer in Dhaka
In-memory means lost
Scheduling work inside the process makes the process the only record that it exists. Deploy, scale down, crash, or have the platform reclaim an idle instance, and the work is gone. Nothing failed, so nothing is reported, and the user is left waiting for something that is no longer happening.
Write the job down first, in a database or a durable queue, before anything begins. If the record exists, the work can be resumed by someone else; if it does not, there is nothing to resume.
Workers should claim, not receive
Handing a job to a worker means it is lost if that worker dies. Having workers claim jobs — marking one as taken, with a time by which it must be finished — means an abandoned job becomes visible and can be picked up again.
That single property, a claim that expires, is what separates a queue that recovers from one that quietly drops things when an instance disappears.
Assume every job runs more than once
Retries, reclaimed jobs and duplicate deliveries all mean a job body can execute twice. Write them so that is harmless: check whether the work is already done, make writes conditional on current state, and key external calls so a repeat does not create a second charge or a second email.
A job that is only correct when run exactly once will be wrong eventually, and the day it is wrong is the day something else was already going badly.
Fail in a way that stops
Give each job a maximum number of attempts and back off between them, so a job failing because a dependency is down does not hammer it. After the last attempt, move the job somewhere visible rather than deleting it or retrying forever.
That place needs looking at. A failure holding area nobody reads is the same as deleting the job, with extra storage.
Watch the queue, not just the errors
The informative signals are depth and age: how many jobs are waiting and how long the oldest has waited. Both rise before anything errors, which makes them the earliest warning that consumers have stopped or slowed.
Alert on jobs that are claimed but unfinished past their deadline, too. Those are the ones that produce no error at all, because nothing returned to report one.
Deploy without discarding
On shutdown, stop accepting new jobs, finish or release what is in hand, and only then exit. Combined with claims that expire, that makes a deploy ordinary rather than an event that quietly drops whatever was running.
Common questions
Why do background jobs disappear when I deploy?
Because they were only ever in memory. A promise, timer or in-memory queue makes the process the sole record of the work, so a restart, scale-down or crash removes it without an error. Write the job to a database or durable queue before starting it.
Should a queue push jobs to workers or let them claim?
Let them claim, with a deadline. Work handed to a worker is lost when that worker dies, whereas an expired claim makes an abandoned job visible again so another worker can pick it up.
Do background jobs need to be idempotent?
Yes. Retries, reclaimed jobs and duplicate deliveries all cause a job body to run more than once. Check whether the work is already done, make writes conditional, and key external calls so a repeat does not create a second charge or email.
What should be monitored on a job queue?
Queue depth and the age of the oldest waiting job, since both rise before anything errors. Also alert on jobs claimed but unfinished past their deadline — those produce no error because nothing returned to report one.