KatInterview

Build a GPU-Based Model Serving System

System DesignModel answer
MediumModel answerSystem Designmachine-learningdistributed-systemsapi-design

Last updated

Design a service that exposes a trained ML model over an API, routes requests to GPU workers, and maximizes hardware utilization.

You're building a service that serves predictions from a trained machine learning model running on GPU hardware. Clients will send requests over the network and receive predictions back. Your job is to design both the client-facing interface and the internal architecture that delivers those predictions efficiently.

The problem has two parts:

Part A: Architecture and API

Design the complete serving stack. This includes:

  • The client-facing API: what do requests and responses look like, how do errors surface, and what guarantees do you provide?
  • The data flow: how does a request travel from entry point to GPU and back?
  • Resource management: how do you decide which requests to accept, how do you distribute work across available GPUs, and what happens when load exceeds capacity?
  • Operational concerns: handling GPU failures, deploying updated models, and monitoring system health

Part B: GPU Optimization

Once the basic system works, explain how to increase the number of requests each GPU can handle while maintaining acceptable response times. What are the bottlenecks in GPU execution for this workload? What techniques can improve throughput, and what trade-offs does each involve?

Assumptions You Should Clarify

The interviewer intentionally leaves details unspecified. Before diving in, establish:

  • Model characteristics: Does it produce a single output (image classification, embeddings) or generate sequences iteratively (language models producing tokens one at a time)?
  • Scale: How big is the model? Does it fit in one GPU's memory or require multi-GPU sharding?
  • Performance requirements: Is the priority time-to-first-token, end-to-end latency for complete outputs, or maximum throughput for batch workloads?
  • Traffic patterns: Expected request volume, burstiness, whether responses should stream back incrementally
  • Client needs: Authentication schemes, per-user quotas, priority tiers

A reasonable working assumption for concreteness: a large language model that generates text token-by-token, serving real-time user requests where streaming responses matter.

Hints

Hint 1

For the API surface, think through what happens when capacity is full, a request times out, or generation hits a configured limit.

Hint 2

GPU compute vs memory bandwidth: different phases of inference are bottlenecked by different resources.

Hint 3

Batching helps, but naive batching creates head-of-line blocking when requests in the same batch have different output lengths.