Design a Job Scheduler for a Distributed Rendering Cluster
System DesignModel answerLast updated
Design a distributed scheduling service that assigns variable-length rendering jobs to a heterogeneous GPU cluster while balancing priority tiers, resource fit, and fault tolerance.
Design a Job Scheduler for a Distributed Rendering Cluster
A media platform runs computationally intensive rendering jobs on a cluster of hundreds of GPUs. Each job consumes a significant chunk of GPU memory and runs for anywhere from a few seconds to several minutes, depending on what was requested. Your task is to design the scheduling service that sits between incoming user requests and the GPU worker fleet.
Context
The platform has two user tiers — paid subscribers and free users — and the scheduler must treat them differently without letting free users wait forever. The GPU fleet is heterogeneous: two or more hardware generations with different memory capacities and throughput characteristics. Model weights are large (tens of gigabytes) and loading them from scratch is slow enough to matter.
Functional Requirements
- Accept job submissions carrying a declared memory requirement and an estimated runtime.
- Route each job to a GPU that can satisfy its memory requirement.
- Support priority tiers: paid jobs should get lower queue latency than free jobs.
- Allow high-priority jobs to preempt lower-priority work already running on a GPU, with the displaced job resumable from a checkpoint.
- Let clients poll or stream progress updates for a submitted job.
Non-Functional Requirements
- GPU utilization should stay above 85% under normal load.
- Paid users should see p95 queue wait under 10 seconds.
- Free users must never starve: provide a bounded worst-case wait even at peak.
- The scheduler itself must survive a single-node failure with under 10 seconds of disruption.
- The system must handle thousands of jobs queued or running simultaneously.
What to Cover
- API — submission, status, cancellation, and streaming progress.
- Architecture — how the orchestrator, scheduler, and worker agents fit together and communicate.
- Data model — how you track GPU state, job state, and model cache state.
- Scheduling algorithm — how you score and match jobs to GPUs, handle cold starts, and decide when to preempt.
- Fairness vs. throughput trade-off — how you prevent starvation without sacrificing cluster efficiency.
Assumptions
- Individual job runtimes range from 5 seconds to 2 minutes, with a heavy-tailed distribution.
- GPUs have fixed VRAM; a job cannot run if its requirement exceeds available VRAM on a candidate GPU.
- Model weights for a job variant range from 20 GB to 60 GB; loading from local NVMe takes 10–20 seconds, from remote object storage 1–2 minutes.
- The fleet has roughly 500 GPUs across two hardware generations.
Hints
Hint 1
Start by deriving concrete numbers: jobs per second, average running jobs (Little's Law), and queue depth at peak. These numbers expose which components need to be durable and which can be in-memory.
Hint 2
Cold start is not a minor detail here — loading weights can take as long as running the job. Think about where weights are cached, how you predict demand, and how the scheduler prices a cold GPU versus waiting for a warm one.
Hint 3
Pure priority queuing maximizes throughput for paid users but starves free users; strict partitioning is fair but wastes idle capacity. The interesting design space is in how you combine both ideas — think pool borrowing and score aging.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Scope and Back-of-Envelope Numbers
Pin down scale before touching architecture — the numbers determine what must be durable.
Cluster: 500 GPUs, roughly 300 of the older generation and 200 of the newer, packed 8 per node (~60 nodes total).
Job throughput: Mean runtime ~40 s, so each GPU completes ~1.5 jobs/min. Cluster capacity is ~750 jobs/min, or about 12 jobs/s.
Concurrency (Little's Law): At 12 jobs/s with 40 s mean run time, ~500 jobs run simultaneously. Add queue depth at peak and you have several thousand jobs in flight. An in-memory queue on the scheduler is a single point of failure — the queue must be durable.
Cold-start cost: Loading weights takes 10–120 s. At a mean job runtime of 40 s, a cold start can double the effective job latency. Model placement is a first-class scheduling concern, not an afterthought.
Targets: Paid p95 queue wait < 10 s, free worst-case wait < 5 min, utilization > 85%, scheduler failover < 10 s.
2. API Design
# Submission
POST /v1/jobs
Body: { prompt, duration_s, resolution, model_variant, seed?, idempotency_key }
Response 202: { job_id, status: "QUEUED", estimated_start_s }
# Status polling
GET /v1/jobs/{job_id}
Response: { status: QUEUED|RUNNING|PREEMPTED|SUCCEEDED|FAILED|CANCELLED,
progress: 0.0–1.0, queue_position?, output_url?, error? }
# Streaming progress
GET /v1/jobs/{job_id}/events # Server-Sent Events
# Cancellation
DELETE /v1/jobs/{job_id}
Key decisions:
- Asynchronous by design. Jobs run up to 2 minutes; submission returns a 202 immediately.
- Idempotency key makes client retries safe without duplicate submissions.
- Tier comes from the auth token, not the request body, so it cannot be spoofed.
- The API layer derives
vram_gb_requiredandest_runtime_sfrom a lookup table over (model, resolution, duration) so the scheduler never has to trust client-supplied estimates.
The internal scheduler-to-worker protocol runs over gRPC: AssignJob(lease), Heartbeat(node_state), ReportProgress(job_id, step, checkpoint_ref), Preempt(job_id, checkpoint_deadline_ms).
3. Architecture
Client → API Gateway → Request Orchestrator → Job Store (Postgres)
→ Tier Queues (Redis sorted sets)
↓
Scheduler (active/standby, leader via etcd)
↓
Node Agents (one sidecar per node)
↓ ↓
Inference Container Local NVMe cache
↓
Object Store (weights)
Request Orchestrator — validates, rate-limits by tier, estimates VRAM and runtime, persists the job record, and pushes it onto the appropriate Redis sorted set scored by priority_score.
Scheduler — runs a matching loop every ~100 ms and also on events (job completed, new job arrived). Emits leases: "job J is assigned to GPU G, TTL 30 s, renewed by heartbeat." Stateless beyond what it reads from Postgres and Redis, so any replica can take over.
Node Agent — one sidecar per physical node. Reports GPU telemetry every 1–2 s via NVML (VRAM free, utilization, temperature, ECC errors, loaded model list). Manages the local weight cache. Runs the inference container and streams step checkpoints back.
High availability: Leader election via etcd. A standby becomes leader, replays current GPU states from the latest heartbeats, and resumes scheduling within one election timeout (~5–10 s). Crashed nodes cause their leases to expire; affected jobs are requeued from their last checkpoint. Every state transition uses a compare-and-swap on (job_id, attempt_number) to prevent a stale worker from overwriting a rescheduled job — the classic split-brain failure mode.
4. Data Model
-- GPU registry (hot replica in Redis hash)
gpu(gpu_id, node_id, hw_generation, vram_total_gb, pool,
health, -- OK | DEGRADED | DRAINING | DEAD
last_heartbeat_at, loaded_model_ids[], vram_free_gb, current_job_ids[])
-- Job record (durable in Postgres)
job(job_id, user_id, tier, model_variant_id, vram_gb, est_runtime_s,
status, priority_score, enqueued_at, attempt, assigned_gpu_id,
lease_expires_at, checkpoint_uri, last_step, gpu_seconds_billed)
-- Model weight catalog
model_variant(variant_id, weights_uri, size_gb, min_vram_gb, preferred_hw_gen)
Hot state (queue order, GPU availability) lives in Redis sorted sets keyed by (tier, model_variant) for locality-aware dequeue. Durable state lives in Postgres. A GPU missing three consecutive heartbeats is marked DEAD; rising ECC error rates or sustained thermal throttling mark it DEGRADED, at which point it only receives short jobs.
5. Matching and Placement
For each scheduling cycle, candidate (job, GPU) pairs pass a hard filter first:
vram_gb_required ≤ vram_free_gbon the target GPU.- GPU health is OK or DEGRADED (with runtime cap).
Survivors are scored:
score = w1·(model already loaded)
+ w2·(best-fit VRAM — i.e., smallest surplus that fits)
+ w3·(hw_generation matches job preference)
− w4·(estimated cold load seconds)
Locality first: Routing to a GPU that already holds the model weights avoids 10–120 s of loading. This is the single largest lever on effective throughput.
Best-fit packing: Minimizing leftover VRAM keeps large contiguous blocks available for memory-hungry jobs.
Hardware tiering: Route long, high-resolution jobs to faster hardware; short jobs can tolerate slower GPUs. This reduces tail latency without changing mean throughput.
Cold-start mitigation: Maintain a warm pool per popular model variant, sized proportionally to queued demand. Prefetch weights onto NVMe when queue depth for a model crosses a threshold. Treat "load time" as a real scheduling cost — a cold GPU is only chosen if the expected wait for a warm one exceeds the load time.
6. Fairness vs. Throughput
The core tension: pure priority ordering maximizes paid-user latency and cluster throughput, but free users starve under load. Strict resource partitioning prevents starvation but wastes idle capacity.
Hybrid approach — reserved pools plus borrowing:
| Pool | Share | Rule |
|---|---|---|
| Paid reserved | ~40% | Only paid jobs run here |
| Free guaranteed | ~15% | Anti-starvation floor |
| Shared | ~45% | Weighted fair share (paid:free = 4:1) |
Idle capacity in any pool can be borrowed by other tiers, but borrowed slots are preemptible. This keeps utilization high while preserving SLO headroom.
Score aging:
priority_score = base_tier_score
+ α · wait_time_s
− β · est_runtime_s
A free job's score rises continuously, guaranteeing it eventually outscores paid jobs waiting in the shared pool. The −β·est_runtime term is a mild shortest-job-first bias that improves mean latency; aging prevents long jobs from being permanently deferred.
Preemption cost accounting: Before preempting a running job, the scheduler checks whether the time-to-checkpoint plus expected re-run time is less than the preempted job's remaining runtime. Preemption that would waste more GPU-seconds than it saves is skipped.
7. Common Mistakes to Avoid
- Trusting client-supplied resource estimates. Always derive VRAM and runtime from the model catalog server-side.
- Ignoring cold-start cost in placement scoring. A GPU with the right weights loaded is often better than a faster idle GPU without them.
- Treating the scheduler as stateful. All truth must live in the job store; the scheduler should be a pure reader/writer of shared state so failover is trivial.
- Forgetting the split-brain case. Without compare-and-swap on
(job_id, attempt), a node that rejoins after a partition can overwrite the state of a job that was already rescheduled elsewhere.