Skip to content

Lesson 7 of 8 · 4 min read

Queues, Leases and Workers for Long Agent Jobs

Agent runs that take minutes or hours run as jobs: a request enqueues a job and returns an id, a worker takes the job under a lease with an expiry, the worker heartbeats to extend the lease while the run progresses, and a worker that dies lets the lease expire so another worker can take over from the last checkpoint. Four mechanics make this safe. The lease is an atomic claim, so two workers never run one job. Each step the worker completes is recorded with an idempotency key, so a takeover does not repeat side effects. Retries are counted per job and a job that keeps failing goes to a dead-letter queue with its history instead of circulating. And the queue has a bounded depth with admission control, so a burst of requests produces honest waiting or refusal rather than an unbounded backlog. The same shape underlies hosted durable-execution engines; building it once makes those engines readable.

Premium lessonReviewed By the AIAgentInterviews editorial team
Get full Premium access · $25

All 19 topics with every worked answer, all lessons and courses, the full practice bank, and anything new that appears during your access.

6 months · One payment · No auto-renewal

Practise it as an interviewer asks it

Related lessons