Critique a GPU Inference Service Design and Schedule Mixed Models
System DesignModel answerLast updated
Analyze a design for a batched GPU inference API, identifying flaws in batching, load distribution, caching, and admission control, then calculate capacity needs and schedule heterogeneous models.
You're reviewing a technical proposal for a GPU-powered prediction service. Instead of designing from scratch, your task is to evaluate an existing architecture, identify its weaknesses, reason about its capacity, and solve a multi-model scheduling challenge.
The Proposed Architecture
HTTP Prediction Service
Target: handle 10,000 requests/second at peak traffic.
Architecture:
1. Round-robin L4 load balancer distributes incoming POST /predict requests
across independent API server instances.
2. Each API server maintains its own request buffer. Once B requests accumulate
(where B matches the model's batch size limit), the server dispatches them
to a GPU worker. Each batched inference operation requires 100 ms.
3. An in-memory response cache uses the complete request body as the cache key,
positioned before the API servers to avoid redundant GPU computation.
4. Clients implement timeout-based retry logic without unique request tokens.
5. No per-client throttling exists; all incoming requests enter the queue.
6. Capacity formula: each GPU processes B requests every 100 ms, therefore
the fleet requires exactly 10,000 / (10 × B) GPUs total.
Your Tasks
Task 1: Identify Design Weaknesses
Review the architecture and pinpoint its critical problems. For each issue, describe:
- The concrete failure mode it creates under real traffic patterns
- A practical remediation approach
- Your priority ranking: which 2-3 issues are blocking concerns?
Focus on: batching behavior at different load levels, how load distribution affects batch formation, cache utility given actual traffic, retry handling, and capacity protection.
Task 2: Capacity Analysis
Given the 100 ms batch time and 10,000 QPS target:
- Calculate the GPU count using the document's formula as a function of B
- Explain why actual throughput falls short of the theoretical maximum
- Describe how you would size the fleet differently, and why
- Contrast realtime serving requirements with offline batch processing
Task 3: Heterogeneous Model Scheduling
A single pool of 8 GPUs must now serve two different models with identical latency requirements:
- Large model: requires all 8 GPUs simultaneously for one batch
- Small model: requires 1 GPU for one batch
Proposed scheduling approach: maintain separate queues for each model, allocate GPU time proportionally to each model's request rate, and prioritize the large model when request rates are equal.
Evaluate this proposal. Provide:
- The capacity constraint for meeting both models' latency targets
- Risks in the proposed approach (particularly for the large model)
- Your recommended scheduling policy with latency protection for both
- Assessment of the proportional allocation and tie-breaking rule
Clarifying Questions to Consider
- What latency SLA applies, and is this user-facing or batch processing?
- How much do request sizes vary, and does batch time depend on them?
- Are predictions deterministic or sampled?
- Is traffic uniform or bursty? Single-tenant or multi-tenant?
- Single model deployment or multiple models per server?
Hints
Hint 1
At low traffic, how long does each server wait to fill a batch? At high traffic with independent queues, what happens to batch efficiency?
Hint 2
The cache key is the full request body. How often will identical requests arrive close enough in time for a cache hit to matter?
Hint 3
Without request IDs, what happens when a client retries after timeout? Consider the resource cost when many clients retry simultaneously.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Task 1: Critical Design Flaws
High-Priority Issues
1. Batching Policy Creates Latency Spikes
The "wait until B requests arrive" policy causes two failure modes:
At low load (< B requests/second per server), requests wait indefinitely. If B = 32 and traffic is 20 QPS split across 4 servers (5 QPS each), each server receives one request every 200 ms but waits for 32 requests—6.4 seconds minimum latency. This violates any reasonable SLA.
At high load, the round-robin L4 balancer distributes connections uniformly, but request arrival is stochastic. Independent per-server queues create batch size variance: one server might accumulate 35 requests (sends 32, holds 3) while another has 28 (waits). This fragments batches and reduces GPU utilization.
Fix: Implement timeout-based batching: dispatch after B requests or T milliseconds, whichever comes first. For a 100 ms P99 latency target, T = 10-20 ms works. Add cross-server queue visibility or use consistent hashing to balance load at the request level, not connection level.
2. Retry Storm Without Idempotency
Clients retry on timeout without request identifiers. When load causes timeouts, retries arrive as new requests, doubling the queue. This creates a positive feedback loop: timeouts → retries → more timeouts. Without admission control or rate limits, the system enters cascading overload.
Fix: Add unique request IDs. API servers deduplicate in-flight requests and cache responses briefly. Implement exponential backoff on the client side. Add per-client rate limits and admission control that rejects requests when queue depth exceeds a threshold (e.g., 2× average).
3. Response Cache Has Low Hit Rate
Cache keys are entire request bodies. For cache hits to help, identical requests must arrive within the cache TTL. In most inference workloads:
- User-generated inputs (text, images) are unique
- Even parameterized requests vary (timestamps, session IDs)
- Cache hit rates are typically < 5% in production
The operational cost (memory, serialization, coordination) exceeds the benefit.
Fix: Remove the cache unless traffic analysis shows > 20% exact duplicates within seconds. If caching is valuable, use semantic hashing or cache only feature vectors after preprocessing, not raw inputs.
Medium-Priority Issues
4. No Load Shedding or Backpressure
Every request is queued regardless of system state. Under sustained overload, queues grow without bound, memory exhausts, and all servers fail simultaneously.
Fix: Implement queue depth limits. Return HTTP 503 with Retry-After headers when queues exceed capacity. Monitor queue depth and shed load probabilistically when utilization > 80%.
Task 2: Capacity Analysis
Theoretical Calculation
Each GPU processes B requests per 100 ms = 10B requests/second.
For 10,000 QPS: GPUs needed = 10,000 / (10 × B) = 1,000 / B
Examples:
- B = 32: 31.25 GPUs (round to 32)
- B = 64: 15.625 GPUs (round to 16)
Why Actual Throughput Is Lower
In realtime serving:
-
Incomplete batches: Even with timeout-based batching, final batches in each window are partially filled. Average utilization: 85-90%.
-
Head-of-line blocking: While GPU processes batch N, incoming requests for batch N+1 queue up. With 100 ms batch time and 20 ms batching timeout, effective utilization is 100/(100+20) = 83%.
-
Variance and tail latency: To meet a P99 latency target (e.g., 200 ms), you cannot operate at 100% utilization. At 90%+ utilization, queuing delays explode (M/M/1 queue behavior).
-
Framework overhead: Model loading, data transfer to GPU, kernel launch, result serialization add 10-20% overhead.
Realistic throughput per GPU: 6-7B requests/second (60-70% of theoretical).
Proper Sizing Method
For a 200 ms P99 latency target:
- Target 60-70% GPU utilization to maintain queue stability
- Add 20% headroom for traffic spikes
- Plan for N+1 redundancy (lose one GPU without SLA violation)
Formula: GPUs = (10,000 / (6 × B)) × 1.2 × (N/(N-1))
For B = 32, N = 32 GPUs: 10,000 / 192 × 1.2 × 1.03 ≈ 65 GPUs (2× theoretical)
Offline Batch Processing
Offline workloads tolerate seconds or minutes of latency. You can:
- Use much larger batches (limited only by memory)
- Wait to fill batches completely (95%+ utilization)
- Pipeline data loading during GPU computation
- Achieve 90-95% of theoretical throughput
For offline, the original formula with 10-20% margin is reasonable.
Task 3: Mixed-Model Scheduling
Capacity Constraint
- Large model: 8 GPUs × 100 ms = 800 GPU-ms per batch
- Small model: 1 GPU × 100 ms = 100 GPU-ms per batch
Total capacity: 8 GPUs × 1,000 ms/sec = 8,000 GPU-ms/sec
If large model serves Q_L requests/sec and small model serves Q_S requests/sec (both with batch size B):
(Q_L / B) × 800 + (Q_S / B) × 100 ≤ 8,000
Simplifying: 8 × Q_L + Q_S ≤ 80 × B
Problems with the Proposed Approach
Gang scheduling starvation: The large model requires all 8 GPUs idle simultaneously. If small batches keep arriving, they fragment the pool and the large model starves. With proportional-to-QPS allocation, a burst of small-model requests blocks the large model for seconds.
Proportional allocation is flawed: If large model = 200 QPS and small model = 800 QPS, proportional allocation gives 20% time to large, 80% to small. But large batches need 8× the resources—the allocation must account for GPU-hours, not request counts.
Recommended Policy
-
Resource-weighted fair queuing: Allocate GPU-time proportionally to
Q_L × 800vsQ_S × 100, not raw QPS. Each model gets its fair share of GPU-milliseconds. -
Preemption with reservation: Reserve time slices for the large model (e.g., every 200 ms, attempt to schedule large if its queue is non-empty). Within each slice:
- If large queue has ≥ B requests: wait for all 8 GPUs to complete current work, dispatch large batch
- Otherwise: dispatch small batches on available GPUs
-
Latency-aware prioritization: If either model's queue depth exceeds its latency budget, prioritize that model until it returns to normal. This prevents latency SLA violations.
-
Tie-breaking: Preferring the large model "when QPS is equal" is arbitrary. Instead, prioritize the model whose next batch finishes soonest relative to its latency target.
Example schedule (B = 32, large = 400 QPS, small = 800 QPS):
- Large: 12.5 batches/sec × 800 ms = 10,000 GPU-ms/sec equivalent
- Small: 25 batches/sec × 100 ms = 2,500 GPU-ms/sec equivalent
- Allocate 80% time to large, 20% to small (opposite of request-based allocation)
This approach prevents starvation, respects resource costs, and maintains latency targets for both models.