This article explores strategies for designing low-latency, resilient APIs in distributed systems, drawing on practical experiences from eBay. It emphasizes latency budgeting, optimizing network hops, managing serialization overhead, and employing resilience patterns like caching and circuit breakers. The core focus is on actionable techniques to achieve sub-100ms API response times by addressing common bottlenecks in complex service interactions.
Read original on InfoQ ArchitectureIn distributed systems, every millisecond counts, as user experience is highly sensitive to latency. The article highlights that users perceive latency as "friction" which compounds across interactions. Achieving sub-100ms API response times requires a systematic approach, where latency is treated as a critical architectural constraint from the outset. This involves more than just optimizing code; it demands careful consideration of network interactions, data serialization, and resilience strategies across multiple services.
A key strategy presented is the concept of latency budgeting, where the total end-to-end latency goal is broken down and allocated to each hop or component in the request path. This provides concrete performance targets for individual teams and ensures alignment across product, engineering, and quality assurance. A typical breakdown might include allocations for edge layers (TLS, routing), API gateways (authentication, throttling), application logic (microservices), and data access layers.
Example Latency Budget Allocation
Client-to-Edge: 10ms (TLS handshake, initial routing)Gateway: 5ms (Authentication, throttling)Application Logic: 30ms (Single or multiple microservices)Data Access Layer: 20ms (Entity service, database queries)Buffer: 10-15ms (For unexpected delays or spikes)
To maintain low latency under stress, robust resilience patterns are indispensable. This includes implementing circuit breakers to prevent calls to failing services, graceful degradation strategies, and intelligent retry mechanisms. The article emphasizes that building a low-latency system is achievable, but sustaining it requires continuous engineering effort, monitoring, and a repeatable process to identify and address performance regressions as systems evolve and scale.
Actionable Insight
Eliminating a single network hop often saves more time than rewriting thousands of lines of code. Prioritize reducing inter-service communication overhead.