SkillSprout
Chapter 5 · Lesson 1
Beginner
5 min read

Latency, Throughput and Bandwidth

Overview

Latency, throughput and bandwidth are three different ways of talking about "speed". People mix them up, and then they apply the wrong fix. This lesson gives you clear words and numbers so you can say exactly what is slow.

Detailed Notes

What is latency, throughput and bandwidth

  • Latency is how long one request takes from start to finish (also called response time). Example: an API call takes 120 ms.
  • Throughput is how much work the system finishes per unit of time. Example: 2,000 requests per second (RPS).
  • Bandwidth is the maximum amount of data a link can carry per second. Example: a 1 Gbps network link.
  • Round-trip time (RTT) is the time for a message to reach the other side and come back.

Think of water pipes. Bandwidth is how wide the pipe is, latency is how long it is (how long the first drop takes to arrive), and throughput is how much water actually comes out each second.

The problem it solves

Without separate words, teams say "the site is slow" and buy more bandwidth when the real problem is distance, or add servers when the real problem is one slow database call.

Imagine a team moves its app from a data centre (a building full of servers) in Europe to one in the US to save money. European users now feel the app is sluggish: every request crosses the Atlantic, adding roughly 80-100 ms per round trip, and a page making 15 sequential calls adds more than a second. The pipe is just as wide; it got longer.

How it works

Where latency comes from. One request's latency is a sum:

text
Total latency = network + queueing + processing + storage + downstream calls
  • Network: distance (light in fibre travels about 200,000 km/s), hops and handshakes. You learned in the network chapter that connections need a handshake before data flows; each handshake costs round trips.
  • Queueing: waiting in line because the server is busy.
  • Processing: CPU time running your code.
  • Storage and dependencies: the database, disk and calls to other services.

Latency numbers worth remembering (orders of magnitude only):

  • Read from memory: ~100 nanoseconds
  • Read from SSD (a fast disk): ~0.1 ms
  • Round trip inside a data centre: ~0.5 ms
  • Read from a spinning disk: ~10 ms
  • Round trip across a continent: ~50-100 ms
  • Round trip across oceans: ~100-200 ms

Memory is faster than disk, disk is faster than a far-away network, and distance costs time no optimisation can remove.

Little's law. In a stable system:

text
Requests in flight = Throughput x Latency

If a service handles 500 requests per second and each takes 0.2 s, about 500 x 0.2 = 100 requests are in flight at once. If latency doubles to 0.4 s, 200 are in flight, needing twice the threads, memory and connections. That is how slowness snowballs.

Latency explodes near capacity. When a server gets close to 100% busy, requests wait in a queue and latency curves sharply upward. At 50% busy a server answers fast; at 95% waits can be many times longer. So leave headroom: never plan to run servers flat out.

Latency vs throughput trade-off. Handling many items together (batching) raises throughput but makes each item wait longer. A chat app needs low latency; a nightly report needs high throughput.

A simple example

A page makes 8 sequential API calls, each with 60 ms of network time and 20 ms of processing. Total = 8 x 80 = 640 ms. If you call them in parallel, the page takes about 80 ms. You did not add bandwidth or servers; you removed waiting. At 300 page requests per second, Little's law says 300 x 0.64 = 192 are in flight, versus only 24 after the fix.

System design example

Suppose users complain an online shop feels slow. A good investigation goes:

  1. Set a target (for example, 95% of requests under 300 ms).
  2. Measure end-to-end latency from the user's side.
  3. Break it down per component (network, queue, code, database).
  4. Fix the largest piece, then measure again.

If most time is distance, no bigger server helps; the data must move closer to the user. If most time is queueing, you need more capacity or headroom.

Summary

  • Latency = wait for one request; throughput = work per second; bandwidth = capacity of the link.
  • Latency is the sum of network, queue, processing and dependency time.
  • Little's law: in flight = throughput x latency.
  • Latency rises steeply near full utilisation, so keep headroom.
  • Distance sets a floor that bandwidth cannot lower.

Architecture Diagram

Where a request's time goes
Architecture
User
App Serverqueue + processing
Databasestorage

Latency is the sum of network, queue, compute and storage time.

  1. 1The request travels over the network to the server.
  2. 2It may wait in a queue if the server is busy.
  3. 3The server processes it and calls the database.
  4. 4Each step adds time; the sum is the user's latency.

Common Interview Questions

Finished this lesson?

0 of 91 lessons done · 0% of the course