In complex distributed systems, users do not experience latency merely as statistical figures, but as a state of direct friction in the user experience, the effects of which multiply as transaction volumes increase. This guide, based on practical experience in massive production environments like eBay, reviews the engineering steps necessary to build ultra-fast APIs that respond in under 100 milliseconds while maintaining infrastructure flexibility and stability under pressure.
Allocating Latency Budgets per Station
The first step to avoiding slow responses is to convert the target latency into a "strict budget" distributed across the entire request path, rather than treating the system as a black box. A typical distribution for a fast path under the 100-millisecond ceiling includes the following:
- Edge Layer: Approximately 10 milliseconds allocated for TLS handshake and initial routing.
- API Gateway: About 5 milliseconds reserved for authentication and rate limiting.
- Application Logic: 30 milliseconds allocated for business logic, while avoiding excessive microservice fragmentation to prevent unnecessary network hops.
- Data Access Layer: A budget ranging from 30 to 40 milliseconds for queries, databases, or caching.
- Buffer: Retaining about 10 to 15 milliseconds to absorb sudden fluctuations without breaking service level agreements (SLAs).
Managing Asynchronous Branching and Thread Pools
When a single request calls multiple disparate backend services (Fan-Out), sequential calling inevitably accumulates latency. Asynchronous and parallel execution is a fundamental solution, but it requires precise tuning of thread pools to avoid resource bottlenecks and queue congestion.
Correct thread architecture depends on classifying the nature of the work:
- CPU-bound tasks: Such as image processing, encryption, and rule validation; it is preferable for the number of processing threads to approximate the number of CPU cores to prevent excessive contention.
- I/O-bound tasks: Such as network calls and database queries; these require a calculated increase in the number of threads to cover wait times based on mathematical formulas that link wait time to processing time, and Little's Law to determine the density of concurrent requests.
- Request Rejection Policies: Defining a clear, pre-emptive strategy for fast rejection if queues become full, rather than flooding the system and causing a cascading failure.
Optimizing Data Payloads and Caching Policies
Many developers overlook the cost of data serialization; sending massive JSON objects containing hundreds of unnecessary fields slows down processing and consumes memory. The principle of payload reduction must be applied by returning only the data the actual client needs, adopting solutions like GraphQL for diverse read services, or using the gRPC protocol for internal service-to-service communication with high payloads.
Caching also requires distinguishing between sensitive and public data, and choosing an invalidation strategy appropriate to the nature of the system, whether through Time-To-Live (TTL) as a starting point, or event-based updates to ensure accuracy in critical systems, while avoiding reading cash data or sensitive prices from a cache that may be stale.
Circuit Breakers and Graceful Degradation
The circuit breaker acts as a critical safety valve to prevent the propagation of failures. If a backend service falters, the breaker immediately isolates it rather than exhausting threads on failed retry attempts that would only exacerbate the problem. This design allows for the activation of fallback paths that provide acceptable responses or cached data to the user until the affected service recovers.
What changes in practice?
Transitioning to APIs with response times under 100 milliseconds is not achieved through minor code tweaks, but by adopting an engineering culture that prioritizes the close monitoring of p99 latency metrics rather than relying solely on averages, and by examining distributed tracing paths to uncover the bottlenecks that silently consume precious milliseconds.