KatInterview

Building Production HTTP APIs for ML Model Serving

System DesignModel answer
HardModel answerSystem Designapi-designmachine-learningrest

Last updated

Design a production-grade REST API for serving machine learning predictions on images, covering endpoints, schemas, auth, reliability, and safety.

You're building an HTTP API that will serve predictions from a machine learning model that processes images. Your API needs to handle both real-time requests and batch processing workloads.

Design a complete API specification that addresses:

  1. Core endpoints and patterns: What HTTP endpoints will you expose? How will you handle synchronous vs. asynchronous requests? What versioning strategy will you use, and how do you ensure safe retries?

  2. Request and response design: What formats will you accept for image data? Define the JSON schemas for requests and responses. How will you represent errors in a standard way? What HTTP status codes map to which scenarios?

  3. Security and access control: How will clients authenticate? How will you implement authorization with different permission levels? What rate limiting strategy will you use, and how do you prevent abuse?

  4. Evolution and compatibility: How will you evolve the API over time without breaking existing clients? What's your deprecation process for old versions or endpoints?

  5. Operational concerns: How will you handle personally identifiable information in images? What security measures will you implement for image uploads? How will you make the API observable (logging, metrics, tracing)?

  6. OpenAPI specification: Provide a concrete OpenAPI 3.0 snippet for at least one endpoint showing parameters, request/response schemas, and error cases.

Explain your design choices and trade-offs. Consider that the service will handle thousands of requests per second, support multiple tenants, and run on GPU infrastructure where compute time is expensive.

Hints

Hint 1

Consider separating fast single-image predictions from slow batch jobs into different endpoint patterns

Hint 2

Think about how to make POST requests safe to retry when network failures happen mid-request

Hint 3

Image URLs as input create security risks - what attack vectors need protection?