skip to content

learn.smmeyer.devsystem-design11

system-design/11

ai systems · deep · ~4h practice

High-scale compute systems

outcome

Schedule heterogeneous compute fairly, efficiently, and predictably under scarcity.

Plan a practice session · ~4h including exercises
Read + trace the worked example
30 min
Assignment + constraint variations
140 min
Timed drill + repeated explanations
50 min
Closed-book recall + self-review
20 min

This is a suggested practice budget, including drawing, variations, and repeated drills. Reading is the first block. Split the work across sessions and use the rubric to judge when to move on.

why this matters

AI workloads make compute visible as a product constraint. GPUs are expensive, requests vary wildly, and utilization can conflict with latency and tenant fairness.

coverage

  • Compute shape: stateless/stateful, horizontal scaling, online/batch.
  • Pools: workers, queues, placement, autoscaling.
  • Resources: CPU, memory, network, accelerator bottlenecks.
  • Isolation: containers, quotas, preemption, noisy neighbors.
  • Scheduling: GPU-aware placement, bin-packing, affinity.
  • Control: admission, fairness, priorities, cost-aware scheduling.

mental model

Admission and scheduling translate product priorities into scarce-resource placement.

  1. 1 →Admit

    Budget + class

  2. 2 →Queue

    Priority + fairness

  3. 3 →Place

    Fit + locality

  4. 4 →Run

    Observe + preempt

Read in numbered order: admit → queue → place → run.

lessons

01Workload shape determines the pool

Online inference values low queue time and predictable latency. Batch training or embeddings can wait, fill troughs, and tolerate preemption. Separate pools or reservations prevent batch work from consuming interactive headroom.

Describe a job by the resources it needs and how long it holds them. A CPU batch transform, a memory-heavy index build, and a GPU decode request are not interchangeable work units. Track duration distributions, memory footprint, accelerator compatibility, and whether interruption is safe. A queue containing ten jobs may represent seconds or hours of work.

Separate scheduling from admission. Admission decides whether the service can promise to accept a job; scheduling decides which accepted job runs next on which resource. Reserve scarce resources before accepting work when necessary, and release or reconcile reservations at completion. If you accept unlimited work then schedule it fairly, users can still wait beyond every promised deadline.

Use workload classes where sharing harms predictability. Interactive requests need low waiting time; batch jobs may tolerate delay and benefit from larger batches. Separate pools or priority reservations can protect interactive latency. Explain the cost: idle reserved capacity may reduce utilization, and strict priority can starve batch work unless you allocate a minimum share.

  • Stateless frontends scale cheaply
  • Stateful workers need checkpoint and ownership semantics
  • Autoscaling lag makes admission control essential

02The bottleneck moves

A service may be GPU-compute bound during decode, memory-capacity bound by KV caches, CPU-bound during tokenization, or network-bound during distributed collectives. Measure per stage.

Compute can be limited by arithmetic, memory bandwidth, device memory, network transfer, or queueing. Increasing one resource helps only while that resource is the bottleneck. A model may fit in memory yet serve too slowly because each generated token requires reading substantial model state. Conversely, enough compute does not help if long contexts exhaust cache memory.

For an illustrative inference workload, 20 requests/s with 1,000 input and 200 output tokens require 20k input tokens/s and 4k output tokens/s. Those rates describe different serving phases and cannot simply be divided by one universal tokens/s rating. Measure capacity under representative context lengths, concurrency, batching, and latency targets; treat calculator coefficients as assumptions to test.

Little's Law relates average work in the system to arrival throughput and average time: L = λW in a stable population. At 20 requests/s and two seconds average residence time, about 40 requests are present on average. This is not a p99 guarantee or a memory estimate by itself. Use it to check consistency between observed concurrency and latency, then inspect distribution tails.

  • Bin-pack without fragmenting scarce accelerator shapes
  • Data/model locality reduces transfer cost
  • Queue age exposes insufficient service rate

03Fairness is explicit policy

FIFO can let one huge request block many small ones. Fair-share scheduling, tenant weights, size classes, and concurrency caps make service predictable. Cost-aware routing may choose a smaller model or batch path.

FIFO is easy to understand but a long job at the front can delay many short ones. Size classes, preemption where supported, or separate queues reduce this head-of-line blocking. A scheduler also needs a fairness unit: jobs, compute time, tokens, or reserved capacity. Equal request counts can give very unequal resource shares.

Give each tenant bounded concurrency and a resource budget, then allocate remaining capacity with a policy such as weighted fair sharing. Protect a minimum batch share from permanent interactive pressure. If you estimate job cost incorrectly, reconcile actual usage and adjust future admission; otherwise a tenant can repeatedly obtain more capacity than its reservation suggests.

Test overload as a normal operating case. Remove part of the fleet, double job size, or introduce one tenant with giant prompts. Specify what is rejected, queued, downgraded, or cancelled, and measure waiting time by class. A healthy average utilization is not enough if one class misses deadlines or one tenant monopolizes device memory.

  • Reserve capacity for critical traffic
  • Preemption requires checkpoint or restart policy
  • Charge/attribute shared resource cost

worked example

Plan serving capacity in tokens and headroom

Assume 100 requests/s, 1,000 input tokens and 200 output tokens per request. A measured fleet configuration in this fictional exercise sustains 25k output tokens/s at its target latency.

  1. The workload demands 100k input tokens/s and 20k output tokens/s. Keep those workloads separate because prefill and decode stress hardware differently.
  2. Decode demand is 80% of the stated capacity before retries, variance, and failure headroom. That does not prove the latency SLO is met for all prompt shapes.
  3. Losing a quarter of the fleet leaves 18.75k output tokens/s, below demand. Define queueing, shedding, shorter output caps, or fallback.
  4. Test representative length distributions and concurrency, including the KV-cache footprint, instead of extrapolating from an isolated tokens/s result.

Design decision: Reserve headroom around a measured workload envelope and admit work using both compute and memory constraints.

Limit: The capacity value is illustrative. Model architecture, batching, hardware, precision, and output distribution change actual throughput.

Teaching scenario · traffic, prices, and capacity values are illustrative.

lab

interactive lab

GPU capacity — token-shaped demand meets fixed supply

1 · predict first

120 RPS × (800 in + 300 out) tokens on 8 GPUs: over or under water? Guess the utilization first.

A guess makes the comparison useful. This lab draft lasts until you leave the page.

pedagogical model — values are illustrative, not measured.

assignment

Produce: A capacity sheet, admission policy, and overload experiment plan.

Paper, a text editor, or a spreadsheet is enough. Model access and paid services are optional.

  1. Use the lab to compare short-chat and long-document traffic; record token demand and the dominant constraint.
  2. Allocate tenant fairness, interactive versus batch capacity, queue bounds, and a degraded service mode.
  3. Design load tests for long-tail lengths and a node loss; revise the fleet estimate using the results you would need to measure.

Change a constraint

  • Average output length doubles with unchanged request rate.
  • A single tenant starts sending very long prompts while aggregate RPS stays normal.

Self-review rubric

  • Input and output token demand are both visible.
  • Capacity includes failure headroom and memory limits.
  • The overload response has a user-visible contract.

If a criterion is missing, revise that part of the artifact before rating your practice below.

Compare a sample artifact after your attempt

One defensible answer under these assumptions. Compare the reasoning and checks with your work; other designs can satisfy the same contract.

Use the example's 100 RPS, 1,000 input tokens, 200 output tokens, and fictional measured fleet output capacity of 25k tokens/s at target latency.

Input demand: 100 × 1,000 = 100k tokens/s
Output demand: 100 × 200 = 20k tokens/s
Output headroom: 25k - 20k = 5k/s (20% of capacity)
25% fleet loss, linear exercise assumption: 18.75k/s < 20k/s demand
Admission: request + token estimate + context/concurrency memory bounds
Queues: interactive protected share; batch bounded waiting/aged priority
Experiment: baseline → long prompts → doubled output → fleet loss

Output capacity alone does not establish input capacity or KV memory headroom. Doubling output length raises output demand to 40k/s; unchanged RPS does not mean unchanged load. Measure each scenario at its latency contract and track queue delay by class. A linear fleet-loss estimate is a planning assumption, not a hardware law.

Check your artifact

  • Input and output phases are modeled separately.
  • A noisy tenant cannot reserve every active slot or unbounded memory.
  • The overload policy selects rejection, delay, or degradation before accepting work it cannot serve.

A tempting mistake: Reporting 80% output utilization as universally healthy ignores input work, memory limits, traffic skew, and failure headroom.

cumulative practice

Relay · build and evolve a private file service

Project brief

Keep one design document for Relay, a tenant-aware file service. Start with 100k daily users, ten downloads per user/day, 10k uploads/day, 1 MB typical bodies, 30-day retention, and a 5× download peak. Files are private to workspaces. Treat these as fictional planning assumptions. Later chapters add previews, recovery, regional constraints, compute, and an assistant. Record each change rather than replacing the earlier version; the final review combines the whole packet. These activities share the chapter's existing practice budget.

Keep one project document across this track. Reconstruct earlier reasoning before opening notes, then revise the same artifact. Use part of the assignment and review budget for this work. If you enter mid-course, sketch the earlier decisions first using the linked chapters.

Add to your project: Relay's optional summarization pool, separate from raw file delivery.

Add ten summary requests/s, each with 1,000 input and 100 output tokens. Recall why queue size and RPS are incomplete. Calculate phase demand, then explain admission and isolation during a 25% compute loss without claiming a fleet size from token demand alone.

Compare cumulative reasoning after your attempt

Demand is 10k input and 1k output tokens/s before retries. Fleet sizing needs measured phase performance, memory, lengths, and the latency target. Reserve headroom and bound per-tenant tokens/concurrency; defer summaries or reject excess when capacity falls. The file-serving SLO should not depend on summary completion. Reuse durable jobs and ownership rules rather than building a separate unsafe retry path.

Keep your first attempt and revision together. If your answer differs, identify the assumption or mechanism that explains the difference before rating your recall.

senior signal

Name the scheduling objective and its victim: maximizing GPU utilization can worsen interactive p99; reserve latency headroom deliberately.

failure patterns

  • Autoscaling as the only overload plan
  • FIFO across highly variable jobs
  • Tracking GPU utilization without queue latency
  • Mixing batch and online workloads with no reservation

knowledge checks

Start with these quick checks, then explain the closed-book questions in your own words.

  1. 01Why can 100% accelerator utilization be unhealthy?

    select an option to check your answer

  2. 02Best protection from a tenant submitting giant jobs?

    select an option to check your answer

closed-book recall

Close the worked example and explain these from memory. Answers are self-reviewed. Drafts stay on this page; save anything you want to keep in chapter notes.

Rate the assignment and recall together

Use the assignment rubric as evidence. Completion is your own judgment; this score schedules practice.

interview drill

Design a shared GPU job scheduler for interactive inference, nightly embeddings, and fine-tuning.

  • 3 workload classes
  • GPU scarcity
  • tenant fairness
  • preemption
compare a strong approach after your attempt

Classify jobs by latency, duration, GPU shape, and preemptibility. Use separate queues with weighted fair share and reserved interactive capacity. Bin-pack by accelerator/memory, allow checkpointed batch preemption, expose queue estimates, and use admission/spend limits before accepting jobs.

Compare decisions and failure behavior, then repeat with a changed constraint. Keep your own wording.

Use the timed mock workspace →

references

Sources offer deeper context. Provider capabilities and API contracts can change; check current official docs before implementing.

notes

saved locally