KatInterview

Lease-Based Task Dispatch for a Pool of Human Reviewers

System DesignModel answer
MediumModel answerSystem Designsystem-designtask-queueleases

Last updated

Design a platform that routes skill-specific manual tasks to human operators with leases, heartbeats, fair prioritization, and safe automatic reassignment after failures.

Problem

Your infrastructure organization relies on people for jobs that cannot be automated, such as hands-on triage of suspect GPU servers, unusual hardware validation, and manual policy checks. Design a service that hands these jobs to the right person at the right time and tracks each job until it finishes.

The service must keep working through operator disconnections, expired claims, and hard completion deadlines.

Functional requirements

  • Submission and priority: Upstream systems submit tasks that declare the skills needed, a priority, and a maximum time to completion (SLA).
  • Matching: Operators sign in, state whether they are available, and receive only tasks they are qualified for. You may choose push, pull, or a hybrid.
  • States and leases: Each task moves through QUEUED, ASSIGNED, IN_PROGRESS, COMPLETED, FAILED, and EXPIRED. An assigned task is held under a lease that the operator must keep renewing with heartbeats.
  • Recovery: If an operator goes offline or fails to finish before the lease runs out, the task must return to the queue automatically and without corrupting its state.
  • Auditing and metrics: Keep a full history of state changes, time until assignment, time spent actively working, and per-operator performance.

Non-functional requirements

  • Reliability: At-least-once execution. A network partition or crash must never cause a task to be lost.
  • Fairness: Low-priority tasks must not wait forever, and work should spread evenly across operators who are eligible.
  • Consistency: Two operators must never end up legitimately working the same task at once.

Scale

  • 10,000 operators online at the same time, worldwide.
  • 1,000,000 new tasks per day, peaking at 100 tasks per second.
  • Task durations between 30 seconds and 30 minutes.
  • Assignment or pull latency must stay below 200 ms at p99.

What to cover

  1. Overall architecture: ingestion, queueing and scheduling, operator-facing dispatch, and the state store.
  2. Data model and the task state machine.
  3. The assignment approach: push versus pull, priority handling, and skill-based routing.
  4. Lease renewal, detection of unresponsive operators, and safe reassignment.

State your assumptions, show rough capacity math, and discuss trade-offs and failure modes.

Hints

Hint 1

Convert the numbers into rates first (tasks per second, completions per second, heartbeats per second). If the load turns out modest, the real difficulty is correctness and fairness rather than raw throughput.

Hint 2

Make every state change a conditional write guarded by the expected state and a lease epoch (fencing token), and write the audit record in the same transaction. This stops two operators from winning the same task and stops stale workers from overwriting newer results.

Hint 3

Pull-based assignment fits people well because they request work only when free. For fairness, combine a priority weight with an aging term that grows with wait time, plus a deadline-slack term, so low-priority work eventually surfaces.

Hint 4

A background reaper that scans an index on lease expiry can requeue abandoned tasks. Consider how a returning operator who missed the expiry is rejected, and what happens to tasks that exceed their SLA or retry limit.