Latency vs throughput

The notes

Latency (time)

The time it takes for a single request to travel from client to server and back. Measures the speed of individual operations.

What it represents

  • Think of latency as the time for one car to drive from point A to point B
  • The total duration from when a user clicks a button to when they see the result
  • Lower latency means faster, more responsive user experiences

Common causes of high latency

  • Network delays, slow database queries, inefficient code, geographical distance between client and server, and lack of caching

Measurement

  • Measured in: milliseconds (ms) or seconds (s)
  • Goal: minimize (lower is better)
  • Example: 50 ms response time for a web page

Throughput (volume)

The number of requests a system can handle in a given time period. Measures the capacity and processing power of the system.

What it represents

  • Think of throughput as the number of cars passing through a checkpoint in one hour
  • Measures system capacity regardless of individual request speed
  • Higher throughput means the system can serve more concurrent users

Factors affecting throughput

  • Server capacity, parallel processing capabilities, resource availability and efficient load distribution determine maximum throughput
  • Bottlenecks anywhere in the system limit overall throughput

Measurement

  • Measured in: requests per second (RPS), transactions per second (TPS)
  • Goal: maximize (higher is better)
  • Example: 10,000 requests per second

Relationship and trade-offs

Both are crucial, but often require different optimization strategies.

Independent yet related

  • You can have low latency with low throughput (fast but limited capacity), or high latency with high throughput (slow per request but handles many)
  • Both need optimization

The trade-off

  • Optimizing for one may hurt the other
  • Adding more concurrent connections increases throughput but may increase latency due to resource contention
  • Finding balance is key

Optimization strategies

Reducing latency

  • Use caching and CDNs, optimize database queries, minimize network hops, use faster algorithms, and place servers closer to users geographically

Increasing throughput

  • Add more servers (horizontal scaling), use load balancers, implement async processing, optimize resource utilization, and use connection pooling

Balance both

  • Use efficient architectures like microservices, implement rate limiting to prevent overload, monitor both metrics continuously, and scale based on actual bottlenecks

Prioritize by use case

  • Real-time apps (gaming, trading) prioritize latency
  • Batch processing and analytics prioritize throughput
  • Most apps need both, balanced appropriately

System design deck

  1. 1. Fundamentals
  2. 2. Scaling
  3. 3. Frontend vs backend
  4. 4. Client-server architecture
  5. 5. Databases
  6. 6. Load balancer
  7. 7. Caching
  8. 8. Latency vs throughput
  9. 9. Availability and redundancy
  10. 10. CAP theorem

and many more