KatInterview

Design a Large-Scale Batch Inference Pipeline

Machine LearningModel answer
MediumModel answerMachine Learningbatch inferenceMLOpssystem design

Last updated

Design a production-grade batch inference system that runs a language model over millions of daily documents with exactly-once semantics, versioning, and operational reliability.

Background

Your team owns a platform that runs a text classification model over large document collections every day. The raw documents land in object storage (partitioned by date), and the results must be written to a data warehouse for analytics and compliance queries.

Daily volume is on the order of tens of millions of documents with noticeable day-to-day spikes. The warehouse is read by downstream teams who need confidence that every document was scored, no document was scored twice, and they can always trace a result back to the exact model and data that produced it.

What you need to design

Address all four areas below. For each one, go beyond naming tools — explain the mechanism and the reasoning behind your choices.

1. Correctness under failure Workers will crash mid-shard. A network partition will cause a result to be delivered twice. Explain how the pipeline guarantees that each document ends up with exactly one result row in the warehouse regardless of these failures.

2. Autoscaling The pipeline must absorb volume spikes up to 3× baseline without manual tuning. Describe what signals drive scaling and how you size the work units to make that safe.

3. Artifact and data versioning An auditor asks: "What exact model, preprocessing steps, and source data produced this row?" Describe the metadata schema and the naming conventions that make that query possible, even six months later.

4. Operational health Define the metrics you would track and the alerts you would set to detect a silent failure (for example, a 5 % drop in document count) before downstream consumers notice.

Expected deliverables

  • A component-level description of the pipeline (orchestrator, workers, storage, metadata store)
  • A concrete explanation of the commit protocol that enforces exactly-once semantics
  • A data model for versioning and lineage
  • A monitoring and alerting strategy with specific metric names and thresholds

Hints

Hint 1

Start by sizing the problem: estimate token volume, GPU-seconds required, and how many GPUs you need to finish within a time budget. Real numbers force the design to make sense — spot instances, autoscaling signals, and shard size all fall out of the math.

Hint 2

Exactly-once doesn't mean executing each shard exactly once — that's too hard to guarantee. It means making the commit idempotent: at-least-once execution plus a conditional write that only the first successful attempt can win.

Hint 3

Versioning is a data model problem, not just a naming convention. Think about what columns a downstream query needs to reconstruct full lineage, and work backwards to the tables that need to exist in your metadata store.