Sub topic 2
Starting from user and business requirements
A latency or throughput target is a decision made on behalf of users and the business. If you pick numbers first, you tend to optimize things nobody cares about, or promise things nobody asked for. This chapter shows how to start from requirements and end with draft targets you can defend.
This chapter assumes you know basic client-server and request/response concepts, and that you recognize components such as load balancers, services and databases. You should also be comfortable reading short Python programs and doing arithmetic on rates and durations. Percentiles, load estimation, SLIs and SLOs get their own chapters. Here they appear only as far as needed.
Why start with requirements
Engineers often ask "how fast can we make it?" The better question is "how fast does it need to be, for whom, and what happens if it is not?" The first question has no stopping point. The second one does.
Targets that are not tied to a requirement fail in two ways:
- Too strict. You pay for capacity, caching and engineering time that users cannot perceive.
- Too loose. Users abandon the product, a partner contract is breached, or a downstream system times out, and nobody noticed because the target never described those cases.
A requirement-backed target also gives you something to say when someone asks to relax it or tighten it. You can point to the requirement it protects.
Three sources of requirements
Requirements usually come from three places. Collect all three before writing any number.
| Source | Typical statement | What it constrains |
|---|---|---|
| User experience | "Search should feel instant." | Latency of interactive requests |
| Business | "We expect 20,000 orders in the Black Friday hour." | Throughput, availability, cost |
| Technical or contractual | "The partner API times out after 2 seconds." | Hard upper bounds on latency and error rate |
User statements are usually vague, business statements are usually about volume, and contractual statements are usually precise. Your job is to turn all three into the same form: a number, a unit, a scope and a percentile or rate.
Step 1: Identify the user journeys
A system rarely has one latency target. Different operations have different tolerances, so list the journeys that matter and treat each separately. A journey is a sequence of requests that a user performs to reach a goal, such as "find a product" or "pay for an order".
For each journey, ask:
- Is a person waiting for the response, or is a machine?
- What does the person do while waiting? Stare at a spinner, or keep working?
- What is the cost of a slow or failed response? A lost sale, a support call, a retry storm?
- How often does this journey happen compared with the others?
Do not give every endpoint the same target. A health check and a report export are not alike. Giving them one target usually means the strictest requirement is applied everywhere, which is expensive, or the loosest is applied everywhere, which hurts users.
Step 2: Classify the interaction
The kind of interaction sets the order of magnitude of the target. These ranges are widely used rules of thumb from usability research, not laws, so check them against your own product.
| Interaction type | Rough perception threshold | Typical consequence of missing it |
|---|---|---|
| Direct manipulation (typing, dragging, tapping) | Around 100 ms | Interface feels laggy |
| Page navigation or search result | A few hundred ms to about 1 s | User loses flow, may retry |
| Transaction (payment, booking) | 1 to 3 s, with a visible progress cue | Doubt, double submits, abandonment |
| Background or batch work | Minutes to hours | Missed deadline, not felt per request |
Notice the last row. For batch work, per-request latency is the wrong metric. The requirement is "the nightly report is ready by 06:00". That is a deadline, and it converts into a throughput target: how many records per second must the job process to finish in the window.
Step 3: Subtract what you do not control
A user limit applies to the whole experience, from the tap to the rendered result. Your system controls only part of that. The device renders the page, the network carries the bytes, and only the remainder is yours.
This subtraction is the first real derivation in target setting. The following program does it for three journeys. The numbers for client time and network time are assumptions you would replace with measurements from your own users.
from dataclasses import dataclass
@dataclass(frozen=True)
class Journey:
name: str
user_limit_ms: int # time after which the user notices or gives up
client_ms: int # rendering and app work on the device
network_ms: int # round trip outside our data center
percentile: int # share of requests that must meet the limit
def backend_budget_ms(self) -> int:
return self.user_limit_ms - self.client_ms - self.network_ms
journeys = [
Journey("search results", 1000, 250, 150, 95),
Journey("add to cart", 700, 150, 150, 95),
Journey("payment confirmation", 3000, 300, 150, 99),
]
for j in journeys:
budget = j.backend_budget_ms()
assert budget > 0, f"{j.name}: client and network already use the whole limit"
print(f"{j.name}: p{j.percentile} backend <= {budget} ms")
# search results: p95 backend <= 600 ms
# add to cart: p95 backend <= 400 ms
# payment confirmation: p99 backend <= 2550 msThe assert is deliberate. If it fires, the requirement cannot be met by backend work alone. You then have to change the product, for example by caching on the device, showing a placeholder, or relaxing the user-facing limit. Discovering that at this stage is far cheaper than discovering it in production.
Note that this sum is a planning simplification. Percentiles of separate parts do not add exactly, a point that a later chapter on latency budgets and tail amplification covers.
Step 4: Choose the scope and the percentile
A target such as "responses within 400 ms" is incomplete. A usable target states:
- Which requests. For example, successful
POST /cart/itemscalls, measured at the load balancer. - Which percentile. "95% of requests within 400 ms" tolerates a slow tail. "99.9%" tolerates almost none.
- Over what period. For example, any rolling 30-day window.
Choose the percentile from the cost of a slow response. Browsing can tolerate a slow 5%. A payment confirmation that hangs makes users click again and may create duplicate charges, so it deserves a stricter percentile. A stricter percentile costs more, because the slowest requests are the hardest and most expensive to fix. Reserve it for journeys where the damage is real.
Step 5: Turn business numbers into throughput requirements
Throughput targets come from business events, not from guesses about servers. Work in this order:
- Start with the business event you can count: orders per day, messages sent, videos uploaded.
- Find how many requests one event causes. One order might involve a search, several product views, a cart update and a payment, so a single business event can become many requests.
- Identify the peak. A campaign, a morning rush or a regional holiday can concentrate a day's volume into a short window.
- Add headroom for growth and for failure of part of the fleet.
The detailed arithmetic belongs to the load estimation chapter. At the requirements stage, the important output is a written statement of the assumptions, such as "target 20,000 orders in the peak hour, 40% above last year's peak, measured at the order service". Written assumptions can be reviewed and corrected. Silent assumptions cannot.
Step 6: Capture hard constraints
Some requirements are not preferences. Record them separately because they cannot be traded away:
- Timeouts of callers. If your client times out after 2 seconds, a 3-second response is a failure, however fast the average is.
- Contracts. A partner agreement may fix a response time and an availability level, with penalties.
- Regulation. Some domains require a response or settlement within a fixed time.
- Dependency limits. A third-party API may cap you at a request rate, which caps your throughput.
A hard constraint sets a ceiling, and your internal target must sit below it with margin. If a caller times out at 2 s, a target of "p99 under 2 s" leaves no room for variation. A target of "p99 under 1.2 s" does.
From requirement to target
The steps above form a pipeline, shown in the diagram below.
Worked example: an online ticket shop
Suppose a ticket shop is about to sell seats for a popular concert. Requirements gathered from three sources:
- Product: "Choosing a seat must feel immediate. Checkout must not feel risky."
- Business: "We expect 50,000 buyers in the first 10 minutes after the sale opens."
- Contract: "The payment provider returns a result within 2 seconds, or the attempt is treated as failed."
A first pass at the targets might be:
| Journey | Latency target | Reason |
|---|---|---|
| Seat map load | p95 backend under 400 ms | Navigation-type interaction, user is browsing |
| Seat selection (hold a seat) | p99 backend under 300 ms | Competing buyers, a slow hold means a lost seat |
| Checkout submit | p99 under 2.5 s end to end including the provider call | Provider limit of 2 s plus our own processing |
| Order confirmation email | Delivered within 5 minutes | Asynchronous, user is not waiting |
The checkout row exposes a tension. The provider alone may take up to 2 s, so our own work gets 0.5 s. If that is not enough, the requirement has to change, for example by confirming the order asynchronously after accepting the payment request. Surfacing this during requirements work is the point of the exercise.
For throughput, 50,000 buyers in 10 minutes is a business event count and a window. Each buyer causes several requests, and the peak is sharp, so the capacity plan will be driven by the first minutes. The load estimation chapter turns this into request rates.
Common errors
- Copying a number from a famous company. Their users, devices and architecture differ from yours.
- One target for the whole system. This hides the journeys that need attention.
- Targets with no owner or reason. Nobody can later decide whether a miss matters.
- Ignoring the client side. A fast backend does not rescue a slow page.
- Treating every requirement as equally strict. Strictness has a cost, so spend it where users feel it.
- Forgetting failure. A target on latency alone lets a system "meet" it by returning errors quickly. Always pair latency with a success condition.
Treat the first draft as a hypothesis
Targets set from requirements are estimates of what users need. Measurements, load tests and real traffic will show where they are wrong. Keep the requirement next to each number, so that when evidence changes you revise the target for a known reason.
Exercise
A video app wants "uploads to feel fast". Users upload from phones on mobile networks. The team proposes "average API latency under 200 ms" for the upload endpoint. List three problems with this requirement and target, and rewrite it as a better draft.
Show answer
Problems: (1) "Feel fast" is vague and has no number or user limit behind it. (2) An average hides slow requests, so the target should be a percentile. (3) API latency ignores the dominant cost, which is transferring the file over a slow mobile network, and it mixes different operations such as starting an upload and sending the file. A better draft separates journeys: "Starting an upload: p95 backend response under 300 ms. Upload progress is visible within 1 s of tapping. Upload of a 50 MB file completes within 60 s for 95% of users on a 10 Mbit/s connection. The post is visible to followers within 2 minutes of upload completion." Each target names a scope, a percentile or deadline, and the user need it protects.
Exercise
A checkout page must show a result within 3000 ms at p99. Client rendering takes 300 ms and the network round trip takes 150 ms. A payment provider can take up to 2000 ms. How much time is left for your own backend work, and what should you do if your own processing needs 800 ms?
Show answer
The backend budget is 3000 - 300 - 150 = 2550 ms. The provider takes up to 2000 ms, which leaves 550 ms for your own work. If your processing needs 800 ms, the sum is 2800 ms, which exceeds the budget by 250 ms. Options are to reduce your own processing, run work in parallel with the provider call, move non-essential work such as emails and analytics after the response, or renegotiate the user-facing limit or show a pending state and confirm asynchronously.