Interview concept

High-Throughput ML Inference Microservices

Asked of: Machine Learning Engineer

Last updated

Editorial architecture diagram showing a high-throughput ML inference service: requests flow through batching and worker replicas to a model server, with feature parity, autoscaling, observability, and overload controls.

What's being tested

This topic tests whether you can turn a trained model into a reliable, high-throughput production service rather than treating inference as a notebook operation. The interviewer is probing your ability to reason about latency, throughput, batching, concurrency, memory, model lifecycle, and online/offline feature parity together. General cares because a small serving inefficiency or stale feature can affect a large volume of predictions, while an unsafe deployment can silently degrade model quality.

Core knowledge

  • Latency and throughput are different objectives: latency measures request completion time, while throughput measures predictions per second. Track p50, p95, and p99 latency separately from QPS; averages hide queueing and tail behavior.

  • Use Little’s Law, L=λWL = \lambda W, to connect concurrency LL, arrival rate λ\lambda, and average latency WW. If traffic is 2,000 requests/second and average service time is 10 ms, roughly 20 requests are concurrently in service before queueing.

  • Dynamic batching combines requests arriving within a short window, improving accelerator utilization and amortizing preprocessing overhead. Larger batches usually increase throughput but also add queueing delay; enforce both a maximum batch size and a maximum batching timeout.

  • Micro-batching is particularly valuable for GPU inference, where kernel-launch and host-device transfer overheads are material. For strict low-latency paths, use bounded batching, separate latency-sensitive and throughput-oriented endpoints, or choose a smaller model.

  • Horizontal scaling adds replicas behind a load balancer; scale on request rate, queue depth, accelerator utilization, and p99 latency rather than CPU alone. A replica may appear healthy while its internal request queue is saturated.

  • Concurrency control prevents overload and resource collapse. Use bounded worker pools, admission control, request deadlines, and load shedding; return an explicit degraded response or controlled error instead of allowing unbounded queues and timeout cascades.

  • Model optimization can include graph compilation, operator fusion, quantization, pruning, and distillation. FP16 or INT8 reduces memory and can improve accelerator throughput, but validate calibration, numerical stability, and task metrics against the original model.

  • Feature serving must preserve online/offline parity. Features generated in training through Spark or a feature pipeline should have equivalent online transformations, definitions, defaults, and point-in-time semantics; otherwise serving quality can fall despite healthy infrastructure metrics.

  • Model versioning should make artifacts immutable and deployments reproducible. Record model hash, feature-schema version, preprocessing code, dependency versions, and training data window; support shadow, canary, and rapid rollback deployment strategies.

  • Caching can reduce repeated inference for identical or slowly changing inputs, but cache keys must include model version, feature version, and relevant context. Avoid caching personalized predictions when user state or authorization can change.

  • Observability needs both system and model signals: request volume, error rate, timeout rate, resource utilization, queue depth, latency percentiles, feature missingness, prediction distributions, confidence, and delayed ground-truth metrics such as calibration or AUC.

  • Drift monitoring distinguishes input drift, prediction drift, and concept drift. Compare production feature distributions with a reference using metrics such as PSI or population-level distribution tests, but investigate before automatically retraining.

Worked example — Design a High-Throughput ML Inference Microservice

I would first clarify the model type, request and response schemas, target QPS, latency SLO, payload size, accelerator availability, feature freshness, and whether predictions are synchronous or asynchronous. I would declare an initial assumption such as 10,000 requests per second, a 50 ms p99 target, and a model that fits comfortably on one GPU. I would organize the answer around four pillars: request handling and bounded concurrency, model execution and batching, feature retrieval and parity, and deployment plus observability. The serving path might use a stateless API layer, an in-process or sidecar model server such as NVIDIA Triton, a low-latency feature store, and horizontally scaled replicas behind a load balancer. I would explicitly compare dynamic batching with single-request execution: batching improves accelerator utilization, but an overly long batching window violates the latency SLO. I would add timeouts at every dependency, queue-depth-based autoscaling, circuit breaking, and load shedding to prevent downstream failures from becoming cascading outages. For rollout, I would use shadow traffic first, then a canary with model-version and infrastructure metrics compared against the current model. I would close by saying that with more time I would benchmark realistic payload distributions, test burst traffic and cold starts, and validate online/offline feature parity with replayed production requests.

A second angle — Optimize Batch Inference for Offline Scoring

For a nightly or nearline scoring workload, the framing changes from strict per-request latency to cost, completion time, and reproducibility. I would ask about the total entity count, deadline, retry behavior, checkpointing, and whether predictions must be deterministic. The design could use partitioned batch jobs with Spark, vectorized preprocessing, large batches, accelerator utilization monitoring, and idempotent output writes. The key tradeoff is maximizing batch size and hardware utilization without exhausting memory or creating stragglers; partition sizing and checkpoint boundaries matter more than request-level admission control. I would also verify that the exact model and feature snapshot are recorded so scores can be reproduced later.

Common pitfalls

Pitfall: Treating average latency as the SLO. A design that reports 20 ms average latency but has 500 ms p99 latency under burst traffic is not reliable; discuss queueing, tail behavior, and overload explicitly.

Pitfall: Assuming more replicas automatically solve throughput. If the bottleneck is feature-store latency, serialized preprocessing, GPU memory, or a shared connection pool, scaling model containers only moves the bottleneck elsewhere.

Pitfall: Discussing deployment mechanics without ML correctness. Kubernetes probes, autoscaling, and load balancing are useful, but a strong MLE also covers feature parity, model-version traceability, shadow evaluation, drift, calibration, and rollback criteria.

Connections

The interviewer may pivot to feature stores, online/offline parity, model drift and monitoring, canary deployment, or GPU inference optimization. They may also ask how delayed labels change evaluation, or how to choose between synchronous APIs, asynchronous queues, and precomputed predictions.

Further reading

  • Designing Machine Learning Systems by Chip Huyen — practical coverage of feature consistency, serving architectures, monitoring, and deployment tradeoffs.
  • Machine Learning: The High-Interest Credit Card of Technical Debt by Sculley et al. — explains why data dependencies, feedback loops, and configuration debt make production ML harder than model training.
  • NVIDIA Triton Inference Server documentation — useful reference for dynamic batching, concurrent model execution, model repositories, and accelerator-oriented serving.

Related concepts