KatInterview

Build a Real-Time ML Prediction Service

Machine LearningModel answer
HardModel answerMachine Learningml-systemsinferencelatency

Last updated

Design an ML inference API that serves predictions in milliseconds, handling multitenancy, model rollouts, monitoring, and graceful degradation.

You need to design a production machine learning inference service that delivers predictions with strict latency guarantees. The system must handle real-time scoring requests for multiple tenants, serve different model types (gradient-boosted trees and transformers), and maintain high availability.

Your design should address:

Core requirements:

  • Define concrete latency and availability targets and show how you'll meet them
  • Specify the API contract: request/response format, authentication, and tenant isolation
  • Propose a complete architecture from edge to model execution

Technical depth:

  • How will you retrieve features quickly enough to meet latency budgets?
  • What serving strategy will you use for CPU versus GPU models?
  • How do batching, quantization, and caching fit into your latency budget?
  • What autoscaling strategy accounts for both traffic patterns and cold-start time?

Operational maturity:

  • How do you safely deploy a new model version without risking production traffic?
  • What observability do you need to debug a latency spike or catch model degradation?
  • How does the system behave when a dependency is slow or unavailable?
  • What levers control cost as traffic scales?

Assume peak traffic of 50,000 requests per second across roughly 200 tenants, with models ranging from small tree ensembles to 100M-parameter transformers. Walk through the key design choices and explain the trade-offs.

Hints

Hint 1

Start by breaking your latency budget into stages: network, auth, feature fetch, inference, and serialization. Each stage needs a concrete millisecond target.

Hint 2

Consider what happens when one tenant's traffic spike threatens other tenants' SLOs. How do you enforce fairness without adding coordination overhead?

Hint 3

For GPU models, dynamic batching is the key throughput lever, but it adds queueing delay. Show how you tune batch size and wait time to balance throughput and p95 latency.