Skip to main content

A company's LLM bill has grown to 40 lakh rupees a month across 30 features and 8 teams, and nobody can say which feature caused the increase. Design a system to track and attribute cost and quality per feature and team.

System design · Pro 2

Short answer

Route all model calls through one gateway. Tag every request with team, feature, environment and prompt version, record tokens, model, latency and outcome, and compute cost from a price table. Build dashboards per feature, budgets and anomaly alerts. Join cost with quality signals to get cost per successful task, then act: caching, cheaper models, shorter prompts.

Deeper answer

Clarify the questions the system must answer: who spent what, why it changed, and whether the spend bought quality.

Design: a gateway or shared client library that every team must use. Each request carries required tags: team, feature, environment, user or tenant, prompt version. The gateway records model, input, output and cached tokens, latency, retries and errors, and sends events to a pipeline. A versioned price table turns tokens into money, so past cost stays correct when prices change. Tracing links the calls of one user task, which matters for agents, where one task may cause twenty calls. Dashboards show cost per feature, per team and per request over time, with alerts for sudden jumps and budgets with soft and hard limits.

Quality: cost alone pushes teams to weaker models, so join each trace with quality signals such as user feedback, task completion and sampled evaluation scores. The key number is cost per successful task. Trade-offs: logging full prompts helps debugging but raises storage cost and privacy risk, so sample and mask. What breaks first is tag discipline: untagged calls make reports useless, so reject them at the gateway.

What a strong answer covers

Answer it out loud in the mock interview about 2.5 min

Follow-ups to expect

Common mistakes

Learn it

Cost control

Practice System design questions

More on this topic

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.