How to Build an API Latency Budget (With a Worked Example)
Turn a vague 'make it faster' request into a measurable latency budget, then use it to decide which optimization work matters.
A latency budget is a plain agreement about how long a request is allowed to take and which parts of that time belong to which component. It turns an argument about "slow APIs" into a short list of numbers that engineers can design against. This article walks through building one from scratch.
Start with the user-visible target
Begin with the experience you owe the user, not with a server metric. A search box that suggests results while someone types needs a different budget from an end-of-day report that runs in the background. Write the target as a percentile and a condition, for example: "the order summary request completes within 400 ms at the 95th percentile for authenticated users in the primary region."
A percentile is important because averages hide the slow requests that people remember. If you only track the mean, a small number of very slow calls can disappear while users still notice them. Use p95 as a practical working target and p99 when the endpoint is part of a critical path.
Split the budget into phases
A single number is hard to act on. Break it into phases that map to things you can change:
- DNS lookup: resolving the hostname to an address
- TCP and TLS setup: establishing a connection, including certificate negotiation
- Server processing: routing, authentication, business logic, and database work
- Downstream calls: payments, inventory, search, or other services
- Response transfer: serializing and sending the body
For a 400 ms budget, a reasonable starting allocation might be 20 ms for connection setup on a warm connection, 180 ms for local processing, 150 ms for downstream calls, and 50 ms for transfer. These are example allocations, not universal constants. The point is to make the trade-off explicit: if a new feature needs 120 ms of downstream time, something else has to shrink.
Work through a real example
Imagine an order summary endpoint that currently takes 620 ms at p95. A timing breakdown shows 30 ms in connection setup, 340 ms in application code, 210 ms in a pricing service call, and 40 ms transferring a 40 KB response. The budget says 400 ms total, so roughly 220 ms must be removed.
Where should the work go? Rewriting serialization would save only a few milliseconds. Caching pricing decisions for a short window could remove most of the 210 ms downstream call for repeat requests. Adding an index to a slow query might save 80 ms in application code. Those two changes move the number; a framework rewrite probably would not.
This is why a budget is a decision tool. It tells you what not to do as clearly as what to do.
Measure each phase, not just the total
You cannot manage a budget you cannot observe. At minimum, record:
- Total duration and status code for every request.
- Duration of each downstream call made during the request.
- Database query count and total query time.
- Whether the response was served from cache.
- A correlation ID that connects the request to its logs and traces.
Our API response time checker gives an external view of DNS, connection, TTFB, and download time. Combine that with server-side traces so you can tell whether a slow TTFB came from your code or from a dependency.
Turn the budget into a regression gate
A budget that lives in a document is easy to ignore. Put it where changes are reviewed. For a critical endpoint, add a check in continuous integration that runs a representative request against a staging environment and compares p95 to the agreed limit. Use the same request shape each time so the comparison stays meaningful.
Be careful with noisy environments. A shared staging server can produce misleading numbers. Treat the gate as a signal to investigate, not as an absolute pass or fail, and rerun before blaming a change.
Review the budget periodically
Traffic patterns change. New regions, new clients, and new dependencies all alter what is realistic. Review the budget quarterly and after any major architecture change. Keep the reasoning next to the number: future readers need to know why 400 ms was chosen, not just that it exists.
A short checklist
- Define the target as a percentile under a specific condition.
- Break it into phases that map to owned components.
- Measure the current p95 and p99 before changing anything.
- Choose the largest phase first.
- Add a repeatable regression check.
- Record the reasoning alongside the number.
A latency budget is not a promise that every request will be fast. It is a shared language for deciding which slowness matters and what to fix next.
Related Tools
What is API Response Time? The Complete Guide to Measuring & Optimizing API Performance
Learn everything about API response time, why it matters for your business, and how to optimize your API performance wit...
How to Reduce API Latency: 10 Proven Strategies for 2026
Discover 10 proven strategies to reduce API latency and improve your application's performance. From caching to edge com...
API Monitoring Best Practices: The Complete Guide for 2026
Learn API monitoring best practices to ensure your services are reliable, fast, and always available. Covers uptime moni...
Understanding TTFB: Time to First Byte Explained — The Key to API Performance
A deep dive into TTFB (Time to First Byte), what it means for your API performance, and how to improve it with actionabl...
API Speed Test: How to Benchmark Your REST & GraphQL APIs in 2026
Complete guide to API speed testing. Learn how to benchmark REST and GraphQL API performance, interpret results, and opt...
How to Achieve 99.99% API Uptime: The Definitive Guide
Learn how to achieve 99.99% API uptime with proven strategies including redundancy, failover, monitoring, and incident r...