Design a distributed task scheduler with dependencies
I was asked this
No reports yet. Sign in to say where you were asked it.
A system design interview question asked in Google's first round (coding), last asked Sep 2025. It tests job scheduling, workflows and fault tolerance.
Design task-scheduling infrastructure for jobs made of tasks with dependencies between them (a DAG), including tasks that run for hours. Specify the data model for tasks and DAGs, the APIs to submit, cancel and query, the execution engine, retries and idempotency, back-pressure, worker heartbeats, and handling of stuck and straggler tasks. Then discuss scaling, multi-tenant isolation and observability.
Requirements
- Functional: submit a DAG of tasks with their commands, resources and dependencies; run each task once all its parents succeed; retry failed tasks by policy; cancel a job or a task; query status and logs; scheduled and recurring jobs.
- Non-functional: persistent state that survives scheduler restarts; no task runs twice at the same time; many thousands of concurrent tasks; fair sharing between tenants; long tasks keep running through scheduler failover.
Clarifying questions
- How many jobs and tasks per day, and how large is a typical DAG?
- Are tasks idempotent? If not, what happens on retry?
- What scheduling policies: priority, deadlines, fair share?
- How long can a task run, and can it checkpoint?
- Do tasks pass data to their children, or only signal completion?
What a strong answer covers
- Data model: jobs, tasks with state (pending, ready, running, succeeded, failed, cancelled), dependency edges, attempts with worker id and lease, and a count of unfinished parents per task so readiness is O(1) to check.
- APIs:
POST /jobswith the DAG (validated for cycles),GET /jobs/{id},POST /jobs/{id}:cancel,GET /tasks/{id}/logs. - The engine: when a task succeeds, decrement each child's parent count and enqueue children that reach zero; ready queues per tenant and priority; workers pull tasks they have capacity for.
- Leases and heartbeats: a running task holds a lease renewed by heartbeat; an expired lease means the worker is presumed dead and the task is retried, with a fencing token so a late zombie can't report success.
- Retries and idempotency: retry policy with backoff, attempt ids passed to the task, idempotent side effects or output written atomically.
- Stuck and straggler tasks: timeouts per task, progress heartbeats separate from liveness, speculative duplicates for stragglers when tasks are idempotent.
- Back-pressure: per-tenant quotas and concurrency limits; admission control when queues grow.
- Scaling: the scheduler sharded by job id with a leader per shard; state in a replicated database; workers stateless and autoscaled.
- Observability: per-job DAG view, task timelines, queue depth, lease expiries, and alerts on jobs past their deadline.
Follow-ups
- A task 10 hours in fails. How do you avoid starting from zero (checkpoints)?
- Add a dependency type "run after the parent finishes, whether or not it failed".
- Thousands of tasks become ready at once when a big parent finishes. What happens?
Where it's asked
- Google · First round: coding · Last asked Sep 202545 min · Coding in a Google Doc, no syntax highlighting or autocomplete · No AI
What it tests
job scheduling · workflows · fault tolerance
No official answer yet. Draw yours on the right; publish it and it shows under Community.
Nothing published yet. Publish your canvas and it shows here for others to open and remix.
