KatInterview

Design a Query Router Between a Local Assistant and a Cloud LLM

Machine LearningModel answer
MediumModel answerMachine Learningsystem-designnlpclassification

Last updated

Design an end-to-end ML system that decides whether a natural-language query should go to a lightweight local assistant or a powerful cloud LLM.

Context

You are a machine learning engineer at a company that ships a voice and text assistant on mobile devices. The assistant has two backends:

  • Local assistant (LA): runs fully on-device. Fast, private, and reliable for structured tasks — setting reminders, sending messages, controlling device settings, looking up contacts, playing media, managing calendars.
  • Cloud LLM (CL): a large language model hosted in the cloud. Slower and more expensive, but far better at open-ended tasks — drafting text, explaining concepts, summarizing documents, creative brainstorming, multi-step reasoning.

Routing errors are not symmetric:

  • Sending a device-control query to CL risks task failure, unnecessary latency, and exposing personal data to a third-party server.
  • Sending an open-ended reasoning query to LA produces a poor or empty answer, degrading the user experience.

The system must balance task success, user satisfaction, latency, privacy, and inference cost.

What to design

Walk through the full system end to end. Your answer should address:

  1. Objective and metrics. What is the system optimizing for? What are the primary success metrics, guardrails, and the tradeoffs among them?
  2. Labels and ground truth. How do you define what the "correct" route is? How do you collect or construct training labels when you can only observe the outcome of the route that was actually taken?
  3. Features and model architecture. What signals does the router use? What kind of model (rules, classifier, LLM, hybrid)? How do you handle the on-device latency constraint?
  4. Hard cases. How do you handle ambiguous queries, queries with multiple intents, follow-up turns in a conversation, and low-confidence predictions?
  5. Offline evaluation. How do you measure router quality before shipping? What does calibration mean here and why does it matter?
  6. Online experiment. How do you run an A/B test to validate the router, and what makes this experiment tricky to interpret correctly?

You may assume queries arrive in English initially, but briefly discuss how the design generalizes to other languages and privacy-sensitive contexts.

Hints

Hint 1

Start by framing routing as a cost-sensitive decision rather than a plain classification task — the cost of routing a device-control query to the cloud is much higher than the reverse error, so your model and thresholds should reflect that asymmetry directly.

Hint 2

Logged outcomes are not unbiased labels: you only ever observe the result of the route that was taken. Think about how to recover the counterfactual — what would have happened under the other route — through annotation, sandboxed replay, or pairwise judgments.

Hint 3

Online experiments on a router face a selection-bias trap: treatment and control users receive different query distributions by construction. Think carefully about what your holdout unit should be and how to measure task success rather than engagement proxies.