Design a Lease-Based Work Queue Using a Single Database Table
Last updated: November 29, 2026
Quick Overview
Design a simple, reliable job queue for a small internal Google tool that already uses a relational database, so that multiple workers can pull jobs without two workers processing the same job and crashed workers' jobs get picked up again.
0
0
0 solved
Design a simple, reliable job queue for a small internal Google tool that already uses a relational database, so that multiple workers can pull jobs without two workers processing the same job and crashed workers' jobs get picked up again.
Not every Google system needs a dedicated queue service, and interviewers sometimes ask for the simplest correct design. This checks whether you understand leasing, atomic claiming, and the limits of a database-backed queue.
What the Interviewer Expects
- Define a table schema with status, lease owner, and lease expiry
- Claim jobs atomically so two workers never take the same one
- Recover jobs whose worker died by lease expiry
- Add attempt counts and a failed state
- Know when to graduate to a real queue service
Key Topics to Cover
How to Approach This
- Start by clarifying functional and non-functional requirements with the interviewer.
- Estimate the scale: QPS, storage, bandwidth. This drives your design decisions.
- Draw a high-level architecture first, then deep dive into 1-2 critical components.
- Discuss trade-offs explicitly (e.g., consistency vs availability, SQL vs NoSQL).
- Address failure scenarios, monitoring, and how the system handles 10x traffic spikes.
Possible Follow-up Questions
- How do you avoid lock contention when 50 workers poll the same table?
- How would you add job priorities?
- When would this design stop being enough?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
- A few thousand jobs per hour, up to about 50 workers.
- No job processed by two workers at the same time; a job whose worker crashes is retried.
- Jobs retried at most 5 times, then marked failed fo...
High-Level Design
Table jobs(id, payload, status, priority, attempts, lease_owner, lease_until, run_after, created_at) with an index on (status, run_after, priority). Producers insert rows with status READY. Work...