Skip to content
mentoor

Design review of an AI-heavy service

For engineers

System, API and security review of a service that fronts several model gateways.

A design review of an AI-heavy service is a written walk through six questions: will it hold the load, is the API safe to depend on, can it be attacked, can you see what it is doing, what happens when a provider fails, and what does the gateway in the middle cost you. An agent can draft the design, and it will sound sure of itself. You decide whether it is right.

The case: Harbor Desk

Harbor Desk is a support assistant. Customers type a question, the service looks up their orders, asks a model for a reply and can issue small refunds. Calls go through one internal gateway to three providers: a primary, a fallback and a small self-hosted model. An agent wrote design v3. You are the reviewer.

Why it matters

Model calls are slow, costly, limited by tokens and sometimes wrong. A design that ignores this works in a demo and fails at 9 a.m. on a Monday. Most of the damage comes from a few gaps: a quota nobody calculated, a retry that repeats a refund, a log line that prints a key.

How to review it

  1. Start with numbers. Estimate peak requests per second and tokens per request, then multiply. Compare the result with the provider's limits before looking at anything else. The first limit to be hit is usually the provider's token quota, not your servers. Then walk the failure list: what is a single point of failure, what does a cache key leave out, what does a queue do when a message arrives twice.
  2. Read the API as a client would. Check that errors use one shape (RFC 9457 problem details) with the right status code and no internals. Check that every create or pay call accepts an idempotency key. Check that list calls have a default and a maximum page size, and that a rename is never shipped as a small change.
  3. Review it as an attacker. Walk the OWASP Top 10 categories. The common finding in generated code is a route that proves who you are but never checks that the object is yours. Look for secrets in logs and configs, an admin interface open to everyone, and tools that act on what the model says without a server-side check. A ticket is untrusted input, even when it reaches the model politely.
  4. Make it visible. Every event needs a request id. Metrics need labels with few values, so never an email address. Traces must show model calls as spans. Alerts should fire on what users feel, such as slow or failed answers against an SLO, not on CPU.
  5. Plan for failure. Set a first-token timeout, an idle-stream timeout and a total timeout from observed percentiles. Open a circuit breaker when a provider's error rate spikes, then fail fast to the fallback and probe the primary. Give every tool call that writes an idempotency key. Decide what the product does when all models are down.
  6. Weigh the gateway. It centralises keys, budgets, logging and fallbacks, and it can route easy tasks to cheap models. It also adds a hop, sees every prompt, and hides provider differences that show up on the fallback path.

Before and after

Weak: "Design v3 is fine. Retries handle errors and the cache saves money."

Better: "Peak is about 5.3 million tokens per minute against a 2 million quota, so the primary key saturates first. The cache key omits the customer, so it can show one person another's order. Retrying the whole job repeats the refund email. Block these three before launch."

What goes wrong

  • Trusting the draft. An agent describes risk in confident prose and often skips the arithmetic. Ask for the numbers.
  • Testing only the happy path. The fallback model may format output differently. Run the evals on every route a request can take.
  • Fixing symptoms. A longer timeout, a keyword filter or a stronger hash can feel like a fix while the cause stays. Ask what stops the failure if the model, the client or the network misbehaves.
  • Reviewing in one pass. The six areas catch different bugs. Review in the order above and write each finding with the line it refers to.

The output of a review is short: the findings ranked by impact, the change that fixes each, and what you will check after the fix.

Steps

  1. Check capacity with numbers

    Skill: eng-system-design

    Multiply peak requests per second by tokens per request and compare with each provider key's token-per-minute limit. At 40 requests per second and about 2,200 tokens each, Harbor Desk needs roughly 5.3 million tokens per minute. Then list single points of failure and check what each cache key leaves out.

    Harbor Desk load estimate
    Design v3 inputs
    ItemValue
    Peak load40 requests/s
    Tokens per request2,200
    Neededabout 5.3M tokens/min
    Primary key limit2M tokens/min
  2. Read the API as a client

    Skill: eng-api-design

    Check that errors share one problem-details shape with the right status, that refunds take an idempotency key, that lists have a default and a maximum page size, and that renames are treated as breaking changes.

  3. Review as an attacker

    Skill: eng-security

    Walk the OWASP Top 10 categories. Look for routes without an ownership check, secrets in logs or config, an open admin interface, and tools that act on model output without a server-side limit.

  4. Make the service visible

    Skill: eng-observability

    Put a request id on every event, keep metric labels to a small fixed set, trace model calls as spans, and alert on answers that are slow or failing against an SLO instead of on CPU.

  5. Plan for provider failure

    Skill: llmops-reliability

    Set first-token, idle-stream and total timeouts from observed percentiles. Open a circuit breaker on a spike in errors, fail fast to the fallback and probe the primary. Give each write tool call an idempotency key.

  6. Weigh the gateway

    Skill: api-gateways

    List what the gateway should own (keys, budgets, fallbacks, routing by task) and what it costs (an extra hop, sight of every prompt, hidden provider differences). Run evals on the fallback path.

Skills this scenario uses

Where to study