Shared GPU Cluster Scheduler for ML Training Jobs
System DesignModel answerLast updated
Design a multi-tenant platform that accepts ML training job submissions, schedules them fairly across a heterogeneous GPU fleet, and handles failures gracefully.
Context
Your organization runs a shared pool of GPU hardware used by dozens of teams simultaneously. Researchers and engineers submit one-off training and fine-tuning jobs that each specify a particular GPU model (for example, A100 40 GB, A100 80 GB, H100, or L40S), how many GPUs they need, and how long the job is expected to run. Because the fleet is finite and teams have different sizes and priorities, unmanaged first-come-first-served allocation quickly leads to resource hoarding and indefinite waits for smaller teams.
Design the internal platform that sits between job submissions and raw hardware.
Functional Requirements
- Job specification intake: Users declare a container image, a startup command, the GPU model and count they need (single- or multi-GPU), a maximum runtime, and a path where checkpoints should be stored.
- Two-stage scheduling: First, validate that a submitting team is within its quota and admit the job into a queue. Second, when capacity opens up, bind the job to specific physical machines according to hardware topology constraints.
- Topology-aware placement: Multi-GPU jobs must land on hardware that actually provides the interconnect they need — all GPUs on one machine for NVLink jobs, or all machines under the same network leaf switch for multi-node runs.
- Fairness with no starvation: The scheduler must share capacity proportionally across teams (weighted by team size or entitlement) and must ensure that no job waits indefinitely, including large jobs that keep losing out to smaller ones that fill gaps.
- Preemption and recovery: Lower-priority or over-quota jobs must be stoppable to make room for higher-priority work. The platform signals the job to checkpoint before forcibly terminating it, and rescheduled jobs resume from the last checkpoint.
- Observability: Teams can see current queue position, estimated start time, live GPU utilization across the fleet, and how much of their quota they are currently consuming.
Non-Functional Requirements
- The control plane must survive a restart without losing any queued or running job state.
- Scheduling decisions must be issued within 1–2 seconds of capacity becoming available.
- Concurrent node re-registration or delayed heartbeats must never result in two jobs sharing the same GPU.
Scale
- 5,000 GPUs spread across 750 physical nodes
- 50 teams, peaking at 500 job submissions per hour
- Job durations range from 15 minutes (hyperparameter sweeps) to 48 hours (large fine-tuning runs)
What to Cover
- Architecture overview: Identify the major control-plane components and how they interact.
- Data model: Define the core entities — jobs, allocations, nodes, and per-team quotas — and the state transitions jobs move through.
- Scheduling pipeline: Explain how fair-share ordering and topological placement are separated into distinct stages, and how you prevent large jobs from starving.
- Failure handling: Describe how node heartbeat loss, GPU hardware faults, graceful preemption, and duplicate-allocation prevention each work end to end.
Hints
Hint 1
Start by working out the actual numbers: 500 jobs/hour is a very low write rate, so throughput is not the hard part — think about where the real difficulty is (placement quality, fairness correctness, and consistency under failure).
Hint 2
Dominant Resource Fairness is the standard algorithm for multi-resource fair sharing; think about what the 'dominant resource' is here and how you normalize across GPU types with different costs.
Hint 3
Gang scheduling (all-or-nothing placement) is the central correctness requirement for multi-GPU jobs — think through how you commit multiple nodes atomically and what happens when a node disappears mid-allocation.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Size the Problem First
500 jobs/hour is roughly 0.14 jobs/second. Submission throughput is trivial. The real challenges are placement quality (keeping fragmentation low), fairness correctness across 50 teams, and consistency guarantees when nodes fail or restart.
Expected concurrency: with jobs lasting 15 min to 48 h, somewhere between 500 and 1,500 jobs are running at any moment. Node agents heartbeat every 5 seconds, producing about 150 writes/second to the state store — comfortable for any replicated SQL database or etcd cluster.
The 1–2 second scheduling latency target is achievable: a full pass over ~1,000 pending jobs and 750 nodes fits in memory and completes well under 1 second.
Confirm with the interviewer: jobs are batch (not latency-serving), the platform only signals for checkpoints (users write the checkpoint logic), and there are priority tiers such as prod, research, and preemptible.
2. API Surface
POST /jobs # submit; body includes idempotency_key
GET /jobs/{id} # state, queue position, ETA, allocation
POST /jobs/{id}/cancel
GET /tenants/{id}/usage # guaranteed, borrowed, running, queued counts
The idempotency_key absorbs client retries on submit so the same job is never enqueued twice.
3. Data Model
All state lives in a strongly consistent store (Postgres with serializable transactions works well; etcd is an alternative).
Job — id, tenant_id, spec (image, cmd, gpu_type, gpus_per_node, num_nodes, max_runtime, checkpoint_uri, priority_class), state, attempt, submitted_at, last_checkpoint_at.
States follow the lifecycle: PENDING → ADMITTED → SCHEDULED → RUNNING → PREEMPTING → SUCCEEDED / FAILED. Storing each transition as an append-only event row gives you audit history and queue-wait analytics for free.
Allocation — id, job_id, attempt, node_ids[], gpu_indices[], epoch (a monotonically increasing fencing token), state, created_at.
Node — id, gpu_type, gpu_count, leaf_switch, nvlink_domain, health (HEALTHY / SUSPECT / CORDONED / DEAD), lease_expiry, free_gpu_bitmap, version.
TenantQuota — tenant_id, gpu_type, guaranteed, max_borrow, weight, current_usage.
4. Architecture Overview
Users ──► API Service (stateless, horizontally scaled)
│
▼
State Store (Postgres, replicated)
┌─────┴──────────────────────────────┐
│ Admission Controller │
│ Scheduler (leader-elected) │
│ Health Monitor │
└─────┬──────────────────────────────┘
│ watch streams
Node Agents (one per physical node)
│
Prometheus → dashboards / ETA service
The scheduler is stateless across restarts: on startup it rebuilds its in-memory view from the store and then tails watch events. Leader election uses a store-backed lease; every write includes the leader's term as a fencing token, so writes from a stale leader are rejected.
Node agents operate on a reconciliation loop (Kubernetes-style): they read their desired allocation from the store, start or stop containers to match actual state, and report status back. Agents never make scheduling decisions.
5. Scheduling Pipeline
Stage 1 — Admission and fair-share ordering
When a job is submitted, the admission controller checks that the tenant has not exceeded guaranteed + max_borrow for that GPU type. Admitted jobs are tagged as either within guarantee or borrowed; borrowed jobs are preemptible.
The pending queue is ordered using Dominant Resource Fairness. GPU types are normalized to cost units (e.g., H100 = 1.0, A100-80 GB = 0.6, L40S = 0.3). Each tenant's dominant share = current usage / tenant weight. Jobs are dequeued in ascending dominant-share order, breaking ties by priority class then submission time. A priority aging term grows with wait time, ensuring no job sits behind newer arrivals forever.
Stage 2 — Topological gang placement
The fleet is a tree: rail/leaf switch → node → NVLink domain → GPU.
- Single-node jobs (≤ 8 GPUs): Use best-fit — pick the node with the fewest free GPUs that still satisfies the request. This leaves whole 8-GPU nodes intact for large jobs.
- Multi-node jobs: Require all
num_nodesnodes to be under the same leaf switch. Pick the leaf with the tightest fit. - Gang atomicity: All GPU assignments are committed in a single transaction using compare-and-swap on each node's version field. If any node's state changed since the scheduler read it, the transaction aborts and the scheduler retries immediately. A job never receives a partial allocation.
Anti-starvation for large jobs
Small jobs continuously fill single gaps, so a 64-GPU job may never find 8 co-located free nodes. Two mechanisms address this:
- Reservation: Once a large job reaches the head of the fair-share queue or has waited past a threshold, the scheduler marks the most suitable leaf switch as reserved. It estimates when that leaf will clear using running jobs'
max_runtimevalues. - Backfill: Smaller jobs may still use reserved resources only if their
max_runtimeguarantees they finish before the reservation window opens. Utilization stays high and the large job's start time does not slip.
If the reservation horizon is too far out, the scheduler preempts borrowed or lower-priority jobs on that leaf.
6. Preemption Flow
- Scheduler sets allocation to
PREEMPTINGwith a grace deadline (typically 2–5 minutes). - Agent delivers SIGTERM; the deadline is exposed to the process via an environment variable.
- The job checkpoints to
checkpoint_uri. When the deadline passes, the agent sends SIGKILL. - Job returns to
ADMITTEDwithattempt + 1and will resume fromlast_checkpoint_at.
Two guards prevent thrashing: a minimum runtime before a job is eligible for preemption (e.g., 15 minutes), and a per-job cap on total preemptions.
7. Failure Handling
Node failure: Agents renew a lease every 5 seconds. After 3 missed renewals the node is marked SUSPECT; when the lease expires (≈30 seconds) it becomes DEAD. All allocations on that node are torn down — the entire gang across all other nodes is also terminated, since a partial gang cannot make progress. The job is requeued with its original submitted_at, preserving its queue position.
Idempotency and duplicate prevention: Every allocation carries a monotonic epoch. Agents only start containers whose epoch matches the current store value. A node that re-registers after being declared dead receives an empty desired state and kills any orphaned containers before it can accept new work. Heartbeats from a stale epoch are discarded. This guarantees no two jobs share a GPU and no job runs twice.
GPU hardware faults: Agents stream DCGM metrics and Xid error events. A node with uncorrectable errors is automatically CORDONED — no new allocations land on it — and an alert fires for ops to inspect.
8. Common Mistakes to Avoid
- Scheduling without gang atomicity. Assigning GPUs node-by-node with separate writes lets two concurrent schedulers (or a restart mid-placement) produce overlapping allocations.
- Fair-share without aging. Pure DRF with large teams will indefinitely delay small teams' large jobs if the large team keeps submitting small ones.
- Preempting without a checkpoint grace period. Immediately SIGKILLing wastes hours of compute. A configurable grace window costs very little and dramatically reduces wasted work.
- Relying on max_runtime for correctness. Use it only as an estimate for backfill scheduling. Never let a job run past it; terminate and requeue instead.