CSE Roadmap

Core tier · about 6 hours · 4 parts

Part 2 of 4 · 11 min read

Definitions

Covers: Definitions; The answer, step by step and more.

Definitions

Service-level objective (SLO)

  • SLO: a numeric target for the system, such as p95 latency at most 8 s, cost at most $0.02 per request, availability at least 99.5%, quality at least 0.80.

Tail latency

  • p95 / p99: the latency that 95% / 99% of requests stay under. The tail is what users remember.

Availability

  • Availability: the share of requests that finish successfully. Serial stages multiply: two stages at 99% give about 98%.

Sensitivity analysis

  • Sensitivity: change one input (halve one stage's latency) with the same random numbers and measure the change in the output.

Router and cache

  • Router: sends each request to a cheaper or specialised model. Exact cache: reuses an answer for an identical request. Semantic cache: reuses an answer for a similar request.

Correlated failure

  • Correlated failure: one cause (a provider outage) breaks many stages together; independent-failure arithmetic then overstates availability.

The answer, step by step

AAAWgmp1bWIAAAAeanVtZGMycGEAEQAQgAAAqgA4m3EDYzJwYQAAABZcanVtYgAAAEdqdW1kYzJtYQARABCAAACqADibcQN1cm46YzJwYTpmYjM2NGM4YS1hMTRlLTRkYzQtODEyMy03MzNiMDY5ZjVlN2IAAAADl2p1bWIAAAApanVtZGMyYXMAEQAQgAAAqgA4m3EDYzJwYS5hc3NlcnRpb25zAAAAALxqdW1iAAAARGp1bWRjYm9yABEAEIAAAKoAOJtxE2MycGEuaW5ncmVkaWVudC52MwAAAAAYYzJzaBq3z4/wjd+qCdPVzPia50AAAABwY2JvcqNpZGM6Zm9ybWF0bWltYWdlL3N2Zyt4bWxqaW5zdGFuY2VJRHgseG1wOmlpZDpjYjg5OTljMi0xY2I2LTRjOGYtOTJkNS1kN2FlMDlkOWJmNWJscmVsYXRpb25zaGlwaHBhcmVudE9mAAAB4mp1bWIAAABBanVtZGNib3IAEQAQgAAAqgA4m3ETYzJwYS5hY3Rpb25zLnYyAAAAABhjMnNo1oRznchLsry9Ojxccubl4gAAAZljYm9yomdhY3Rpb25zgqJmYWN0aW9ua2MycGEub3BlbmVkanBhcmFtZXRlcnOha2luZ3JlZGllbnRzgaJjdXJ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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPZYQGSARTlKNbuWRlriS/P6HioTuNOX4qiPudBe3Zal8/+dGAOJ+YvrAnHe05abHbBCWvKazGVa09NppBDYW8SOoH8=p95 latency as each box from AI Engineering chapter 10 is added (assumed component numbers, simulated)4.6 smodel only$0.0080 q 0.845.0 s+ context$0.0085 q 0.845.1 s+ guardrails$0.0090 q 0.844.2 s+ router$0.0052 q 0.784.0 s+ cache$0.0042 q 0.7810.4 s+ agent loop$0.0125 q 0.78target p95 8 sDark bar: p95. Light bar: median. Under each step: mean cost per request and an assumed answer-quality score q (target 0.80).The router lowers cost and latency but drops q below the target; the agent loop breaks the latency target.Quality here is an assumed number per model, not measured. A real design needs an evaluation to fill it in (level 9).A common build-up order: context, guardrails, router and gateway, caches, agent patterns. Use the order that fits your application.
Adding boxes one at a time: p95, cost and assumed quality.
  1. Clarify. Who is the user? What is the job? What is the worst failure (wrong refund, leaked data)? What volume? Is a write action involved?
  2. Targets. Put numbers on quality, p95, cost and availability. If the interviewer gives none, propose them and say so.
  3. Baseline. One model call plus retrieval if the answer needs data. Estimate its latency, cost and quality.
  4. Add boxes for a reason. Guardrails for risk, router for cost, cache for repeated queries, a loop only when one pass cannot do the job.
  5. Failure modes. Timeouts, tool errors, bad plans, loops that never end, prompt injection, write actions that need approval.
  6. Evaluate and monitor. Offline set, online sampling, traces, the three observability metrics above.
  7. Trade-offs. Say what you gave up and what would make you reverse a choice.

Results

Step added p50 (s) p95 (s) p99 (s) Cost per request Availability Assumed quality Misses (p95 8 s, $0.02, 99.5%, q 0.80)
Model only 2.0 4.6 6.7 $0.0080 100.0% 0.84 none
+ context 2.3 5.0 7.0 $0.0085 100.0% 0.84 none
+ guardrails 2.5 5.1 7.2 $0.0090 99.89% 0.84 none
+ router 1.7 4.2 6.1 $0.0052 99.88% 0.78 quality
+ cache 1.5 4.0 5.8 $0.0042 99.91% 0.78 quality
+ agent loop 4.7 10.4 13.1 $0.0125 99.91% 0.78 latency, quality
Retries per LLM call Availability p99 (s)
0 98.61% 12.8
1 99.91% 13.2
2 99.91% 13.1
3 99.91% 13.2
Halve one stage p95 saved (s)
planner LLM 2.69
CRM tool 0.85
answer LLM 0.70
small answer model 0.20
retrieval 0.16
Fix to the latency miss p95 (s) Cost Misses
As designed 10.4 $0.0125 latency
Cap loop at 2 rounds 9.1 $0.0115 latency
Small planner model 7.7 $0.0063 none (planner quality not modelled)
Both 7.0 $0.0061 none (planner quality not modelled)
AAAWgmp1bWIAAAAeanVtZGMycGEAEQAQgAAAqgA4m3EDYzJwYQAAABZcanVtYgAAAEdqdW1kYzJtYQARABCAAACqADibcQN1cm46YzJwYToxYWRiZDkyNS0wOTU1LTRmNGItYjFkYy01NTd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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPZYQOyhZ3EiHf8KN1qhEGhZEgvOzKXLA/eXeMUnzZOoBFohTRri+x23G1cupYZGHNLMkBJxiXS7G85teBh8eWGiTvA=Full design with an agent loop: sensitivity and three fixes (simulated, assumptions as in the notes)Sum of component percentiles vs the simulated requestsum of p50s5.2 ssimulated p504.7 ssum of p95s12.6 ssimulated p9510.4 ssimulated p9913.1 sAdding p95s overstates the p95 of the whole (12.6 vs 10.4 s) because not every stage is slow at once.Retry timeouts push the other way: the model-only design simulates slightly above its listed p95 (4.6 vs 4.5 s).Halving one stage: p95 saved (seconds)planner_llm2.69crm_tool0.85answer_llm0.70answer_small0.20retrieval0.16Fixes for the latency miss (target p95 8 s)as designedp95 10.4 s, $0.0125 misses latencycap loop at 2 roundsp95 9.1 s, $0.0115 misses latencysmall planner modelp95 7.7 s, $0.0063bothp95 7.0 s, $0.0061The small-planner fix does not model any loss of planning quality. It is a candidate to test, not a result.Failures are independent in this model. A provider outage hits every stage at once, so real availability is lower.
Sum of percentiles vs simulation, sensitivity, and three fixes.
Assumption sweep (full design) p50 (s) p95 (s) Cost
Cache hit rate 0% 5.5 10.8 $0.0156
10% 5.1 10.6 $0.0140
20% 4.7 10.4 $0.0125
40% 3.5 9.8 $0.0094
Router share 0% 11.3 $0.0156
90% 9.8 $0.0109
  1. A cache moves the median far more than the tail: at 40% hits the median fell 37% but the p95 only 9%, because misses still take the slow path.
  2. The loop dominates latency and cost once it exists, so bound it first.
  3. Seed noise is small: ten runs of 50,000 requests gave p95 between 10.35 and 10.44 s.
  4. The router trades quality for cost and only an evaluation can say whether the trade is acceptable.
  5. Retries fix independent blips, not outages.

Design rules

  • State targets before drawing boxes.
  • Start from the baseline, and add a component only against a missed target.
  • Estimate with distributions; do not add p95s.
  • Bound every loop: maximum rounds, maximum cost, maximum time.
  • Cache the expensive, repeatable steps, and check staleness.
  • Put human approval in front of write actions, because they add risk that read-only steps do not.
  • Design observability in: traces per step, cost per request, change failure rate.
  • Say which numbers are assumptions and how the design changes if they are wrong.

Interview questions, with the follow-ups

Design a customer-support agent that can look up orders and issue refunds.

"I would first ask the volume, the refund limit and what a wrong refund costs. Targets: p95 under 8 s, cost under 2 cents, 99.5 percent availability, quality at least 0.80 on an evaluation set. Baseline: retrieval plus one model call. Add input and output guardrails, a router to a small model for simple questions, a cache for repeated policy questions, and a bounded planner loop with the CRM tool. Refunds above a limit need human approval. I would instrument traces per step." Follow-up: "Where is the risk?" The write action and prompt injection through ticket text; give the tool narrow permissions and require approval.

Your design has p95 of 10 s and the target is 8 s. What do you do?

"Measure, not guess: halve each stage in a simulation or from traces. In my example the planner call is the biggest lever (2.7 s), so a smaller planner model or fewer loop rounds. I would test the quality effect before shipping." Follow-up: "What if the quality drops?" Route only easy requests to the small planner, or stream partial results.

How do you estimate end-to-end latency?

"Sample each stage from a distribution fitted to its median and p95, compose in sequence, parallel and loops, and read the percentile of the total. Adding p95s overstates (12.6 against 10.4 s in my example); ignoring retry timeouts understates." Follow-up: "What is the weakest assumption?" Independence between stages and between failures.

How do you make it reliable?

"Timeouts, bounded retries with backoff, fallbacks to a cheaper model or a cached answer, idempotent write actions, a circuit breaker for a failing provider, and monitoring of detection and response time." Follow-up: "Do retries always help?" No; they help with transient errors, not outages, and they add tail latency.

Common mistakes

  • Drawing the final architecture first without targets.
  • Adding p95s or using only averages.
  • Ignoring the loop's variable length.
  • Forgetting evaluation: a router or small model without a quality check.
  • Assuming independent failures.
  • No cost number.
  • Write actions without approval.
  • Quoting made-up numbers as facts instead of labelled assumptions.

What the example does not do

  • No measurement: every component number is invented.
  • No correlation: outages, rate limits and shared dependencies are ignored.
  • No quality model: quality is a fixed number per model; the router's errors and the small planner's losses are not modelled.
  • No queueing: concurrency, load and rate limits can dominate real tail latency.
  • No streaming: time to first token is not separated from total time.
  • Optional experiment (I did not run this): replace each stage's p50 and p95 with values from your own project's traces and see which target fails first.

Check yourself

Your design has ten stages with a p95 listed for each. Can you add the p95s to get the request p95? (No. In my simulation the sum of stage p95s was 12.6 s while the simulated request p95 was 10.4 s, because not every stage is slow at once.)

For the curious Every box buys something and costs something

Adding a router cut cost from $0.0090 to $0.0052 and p95 from 5.1 s to 4.2 s, but my assumed quality fell from 0.84 to 0.78, below a 0.80 target. The agent loop pushed p95 to 10.4 s against an 8 s target. A smaller planner model got p95 to 7.7 s in the simulation, which says only that it is worth testing, because the model does not capture planning quality. Availability treats failures as independent, so it is an upper bound; a provider outage hits every call at once.

What you will use daily at work

Practice What it looks like
Clarify the user, job and failure that matters Before drawing any box.
Set targets: quality, p95, cost, availability Then draw the simplest baseline.
Add a box only for a missed target Name the target each box serves.
State your numbers as assumptions Show how the design changes if they are wrong.

Draft: confirm which cost and latency numbers your own stack gives, so you can quote real figures in an interview.

What you must be able to say (one page)

  • Use a fixed order. (1) Clarify the user, the job and the failure that matters. (2) Set targets: quality, p95 latency, cost per request, availability. (3) Draw the simplest baseline (one model call). (4) Add boxes only when a target is missed, naming the target each box serves. (5) Walk through failure modes and approval points. (6) Say how you would evaluate and monitor. (7) State the trade-offs you made. This order is my own.
  • A common build-up order for the boxes: enhance context, add guardrails, add a model router and gateway, reduce latency with caches (exact and semantic), add agent patterns (loops, parallel branches, write actions), with monitoring and observability designed in from the start. Follow whichever order suits your application.
  • Percentiles do not add. In my simulation of a fictional support agent with ten stages, the sum of the stage p95s was 12.6 s while the simulated request p95 was 10.4 s; the sum of medians was 5.2 s against a simulated 4.7 s. The back-of-envelope sum overstates the tail because not every stage is slow at once. In the other direction, retry timeouts push the real tail up: the model-only design simulated 4.6 s against a listed p95 of 4.5 s.
  • Serial availability multiplies, retries raise it, and correlation breaks it. With three attempts allowed on each LLM call, request availability went from 98.6% (no retries) to 99.91% (one retry); further retries gained nothing because my model treats failures as independent. A provider outage is not independent: it hits every call at once. I did not model that, so treat these availabilities as upper bounds.
  • Find the bottleneck by perturbation. Halving each stage's latency in turn, the planner LLM call saved 2.7 s of p95, the CRM tool 0.85 s, the answer model 0.70 s; guardrails under 0.1 s each. Optimise what the experiment shows, not what feels slow.
  • Every box buys something and costs something. Router: cost fell from $0.0090 to $0.0052 per request and p95 from 5.1 s to 4.2 s, but my assumed quality fell from 0.84 to 0.78, under a 0.80 target. Agent loop: p95 rose to 10.4 s (target 8 s) and cost to $0.0125.
  • Fixes are hypotheses. A smaller planner model brought the simulated p95 to 7.7 s and cost to $0.0063; capping the loop at two rounds alone only reached 9.1 s. My simulation does not model any loss in planning quality from the smaller model, so the answer is "test this", not "this works".
  • Defend the numbers as assumptions. In an interview, state the figures you assume ("about 2 s median for a large-model call"), say they are assumptions, and show how the design changes if they are wrong (sensitivity).
  • Two more points to say out loud. From the user's view, time to first token is much longer when an agent plans and calls tools before answering, so stream progress. Three useful operations metrics are mean time to detection, mean time to response and change failure rate. Resilience needs error handling, retries and fallbacks, with timeout and retry logic tuned to the latency requirement of the use case.
  • Honest limits: the stage numbers, quality scores, cache hit rate and router share are assumptions; the code is arithmetic, not a measurement of any real system.