KatInterview

Orchestrating Classification and Embedding Services at Scale

Machine LearningModel answer
MediumModel answerMachine LearningML System DesignAPI DesignScalability

Last updated

Build a document processing pipeline that calls two ML services (classification and embedding) for both single-file and bulk uploads up to 1,000 files.

You have access to two third-party ML services that you cannot modify:

  1. Classification Service

    • Accepts: text documents
    • Returns: a category label for each document
  2. Embedding Service

    • Accepts: text documents
    • Returns: a dense vector (e.g., 768 dimensions) for each document

Your task is to design a complete pipeline that:

  • Lets users upload files containing text documents
  • Handles both individual file uploads and batch uploads (up to 1,000 files at once)
  • Processes each document through both services to obtain its label and embedding
  • Stores all results for later retrieval and search
  • Provides fast responses for small uploads while efficiently handling large batches

Your design should cover:

  1. API Interface

    • How clients submit files (single vs. bulk)
    • Response format (immediate vs. asynchronous)
  2. System Architecture

    • Workflow for calling the two ML services
    • Storage approach for files, text, labels, and vectors
    • Strategy to serve both latency-sensitive and throughput-heavy workloads
  3. Scale & Performance

    • Handling 1,000-file batches without memory issues or timeout failures
    • Batching, queueing, and parallelism when interacting with ML services
  4. Fault Tolerance & Monitoring

    • Handling partial failures (some documents succeed, others fail)
    • Logging, metrics, and error recovery

Remember: you can only call the ML services via their APIs; you cannot change how they work internally.

Hints

Hint 1

Separate the request acceptance layer from processing—async patterns help with large uploads

Hint 2

Both ML services can likely accept batched requests; take advantage of this to reduce round trips

Hint 3

Consider using object storage with presigned URLs to avoid streaming gigabytes through your API servers

Hint 4

Use priority queues or multiple lanes to ensure small uploads don't wait behind large batches