Skip to the guide

Long-running work: async jobs, status and callbacks

IntermediatePattern5 pages

Applying for a passport takes weeks, so nobody waits at the counter. The office takes your form, gives you a reference number, and you check the status online or wait for a text saying it's ready. Behind the counter an officer takes your file from a tray, and the office notes who has it and when she last worked on it. A file left untouched on a desk goes back in the tray for someone else, and a second form with the same reference is recognised as yours, not a new application.

The form is a request for slow work, like a video transcode, and the reference number is a job ID. The tray is a queue, the officers are workers, and the office's note is a lease the worker renews with a heartbeat. The status website is an endpoint the app polls, the text is a push notification or a webhook, and the second form is a retry with an idempotency key. For any step longer than a request should hold, interviewers listen for what the user sees meanwhile and what happens when a worker dies halfway. The move: answer at once with a job ID, keep the job's status in a row you own, let workers lease jobs and renew the lease while they run, and tell the client when it's done.