Payment authorisation gives your model a 50 ms p99 budget including feature fetches. How do you design for it?
Answer
Model answer, written in a candidate's voice
In short
- Break the 50 ms p99 into network, feature fetch, and inference; measure each with traces, not averages.
- Precompute aggregates offline and colocate a low-latency feature cache near the model.
- Fetch features in parallel with hard deadlines/timeouts; do not let one slow source consume the budget.
- Use a smaller or compiled model (e.g., ONNX/TensorRT); keep batching small or off for tail latency.
- Define timeout fallbacks, monitor p99, and load-test at peak and tail conditions.
In full
I would treat 50 ms p99 as a hard end-to-end budget and first split it into network/serialisation, feature fetch, and model inference using traces, because the exact split is workload-specific rather than a fixed number. I would precompute aggregates offline, colocate a feature cache close to the model, and fetch remaining features in parallel with tight deadlines so one slow source cannot consume the budget. For inference I would use a smaller or compiled model such as ONNX/TensorRT, and be cautious with batching: it can improve throughput but adds queueing delay, so for p99 I would prefer small or dynamic batches or no batching. On timeout I would fall back to cached/default features or a degraded path according to risk, never block the payment decision on a slow dependency. Finally I would track p99 rather than mean, and load-test at peak and tail conditions to verify the budget holds under realistic latency spikes.
What a strong answer covers
- Latency breakdown (network, feature lookups, model).
- Precompute aggregates; colocate a feature cache; parallel fetches with timeouts.
- A smaller or compiled model (ONNX/TensorRT), batching trade-offs.
- Fallback rules on timeout; measure p99 not mean; load-test.
Common mistakes
- optimising the model while feature fetches dominate
- no timeout fallback.