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
- 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.
- 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.
- 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.
- 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.
- 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.
- 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
Check capacity with numbers
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 Item Value Peak load 40 requests/s Tokens per request 2,200 Needed about 5.3M tokens/min Primary key limit 2M tokens/min Read the API as a client
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.
Review as an attacker
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.
Make the service visible
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.
Plan for provider failure
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.
Weigh the gateway
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
- OWASP Top 10:2025 (opens in a new tab)StandardFree
The risk categories to walk through when reviewing generated code.
- OWASP Top 10 for LLM Applications (opens in a new tab)DocsFree
Prompt injection, excessive agency and other risks specific to model-backed services.
- RFC 9457, Problem Details for HTTP APIs (opens in a new tab)StandardFree
The standard error body with a stable type, status and detail.
- RFC 9110, HTTP Semantics (opens in a new tab)StandardFree
What each method and status code means, including idempotent methods and 5xx errors.
- OpenTelemetry semantic conventions for generative AI (opens in a new tab)StandardFree
Standard span and attribute names for tracing model calls.
- Alerting on SLOs (Google SRE Workbook) (opens in a new tab)BookFree
How to alert on error budget burn rather than on causes.
- LiteLLM documentation (opens in a new tab)DocsFree
A working example of an LLM gateway with routing, budgets and fallbacks.