Deployment and operations · Lesson 2 of 3
Reliability, latency, and cost management
Control resource use and define graceful behavior for slow or failed dependencies.
Lesson
Production quality includes responsiveness, availability, and predictable cost. Measure latency across retrieval, model calls, and application processing rather than timing only the final endpoint. Track token use, request volume, retries, and expensive tool or search calls. Use timeouts, rate limits, bounded concurrency, and caching only where the data and freshness requirements make them safe.
Design fallbacks for unavailable dependencies: return a clear temporary error, use an approved alternate path, or route to a person. Do not silently present stale or low-confidence results as current facts. Set alerts against service-level objectives and test load patterns before broad release.
Break the end-to-end response budget into stages such as authorization, retrieval, model inference, and post-processing. Measure percentiles, not only averages, because slow tail requests shape user experience. Track request volume, prompt and completion size, retries, and expensive tools to understand cost drivers. Set rate limits and bounded concurrency, and use caching only when authorization and freshness make reuse safe. Under overload, fail clearly or route to an approved fallback rather than returning a stale answer as if it were current.
Implementation drill: trace one representative request through the stages in the diagram. Write down what enters each stage, what output or evidence it produces, and which identity is allowed to perform it. Then test an empty input, an unauthorized request, a dependency timeout, and an unexpected result. For each case, state whether the application should retry, reject, abstain, or ask a person for help. Keep the observed failure as a regression example so changes to prompts, models, data, or code can be checked against the same behavior.
Practice task: Why should retries be bounded?
Visual guide
Budget latency and control load
-
Step 01
Measure
Time each request stage.
-
Step 02
Bound
Set timeouts, retries, and concurrency.
-
Step 03
Optimize
Reduce unnecessary tokens and calls.
-
Step 04
Fallback
Fail safely when limits are reached.
Code examples
Inspect requests within a latency target
SQL
SELECT request_id FROM request_metrics WHERE duration_ms < 1000;
Expected output
A simple query can help inspect requests meeting a latency target.
Key points
- Measure latency and cost at each major application stage.
- Use bounded timeouts, retries, concurrency, and rate limits.
- Make fallback behavior visible and consistent with data freshness requirements.
Check your understanding
Practice
Your learning progress