Latency simply means the time delay between an action and the response to that action.
In computing and networking, it refers to the time it takes for data to travel from one point to another — like from your computer to a server and back. It’s usually measured in milliseconds (ms).
Simple real-life analogy
If you:
- Clap your hands → you hear the echo after a delay → that delay is like latency.
In networking:
If you send a request (like clicking a link on a website):
- Your computer sends the request to the server.
- The server processes it and sends back the data (webpage, etc.)
- The time taken between your click and when the page starts loading is the latency.
In databases:
If you run a query:
- The time between sending the query and getting the result is query latency.
Types of latency
| Type | Example |
|---|---|
| Network latency | Delay between your computer and a remote server |
| Disk latency | Delay in reading/writing to a hard drive or SSD |
| Application latency | Delay caused by code execution or database processing |
| Input latency | Delay between pressing a key and seeing it appear on screen (like in gaming) |
Low latency = Good
(Fast response time — e.g., 20ms)
High latency = Bad
(Slow response time — e.g., 300ms or more → noticeable lag)
Quick example:
- You ping google.com → It replies in 40ms → That round-trip time is the latency.
Query Latency
👉 The total time between sending the query and getting the first response back.
It includes all delays:
- Time to send the query to the server (network delay, if remote)
- Time for the server to start processing
- Time to return the first byte of the result back to you
Focus: How long you (the client) wait to start seeing a response.
Query Execution Time
👉 The time the database engine spends actually processing (executing) the query on the server.
It includes:
- Time to parse the query
- Time to optimize the query plan
- Time to fetch/process the data (scan tables, filter rows, etc.)
- Time to prepare the result set
Focus: How long the server spends working to produce the result (ignores network delays).
In short:
| Term | What it measures | Includes network delay? |
|---|---|---|
| Query Latency | Time from sending query to receiving first result | Yes |
| Query Execution Time | Time the database server takes to process the query | No |
Quick analogy (Restaurant example 🍽️)
- You place an order (send query)
- Waiter walks to kitchen (network delay)
- Chef cooks the food (query execution time)
- Waiter walks back to your table (network delay)
- You get your food (response)
The total time you waited = Query Latency The time chef spent cooking = Query Execution Time
✅ Summary:
Query Latency = Query execution time + network delay (round-trip) + any other delays.
If you’re running queries on the same machine (local DB), network delay is negligible — so latency ≈ execution time. But in real-world distributed systems or cloud apps, they can be quite different.
🚀 Latency vs Bandwidth — Clear Definitions
| Term | Meaning | Unit | Key Point |
|---|---|---|---|
| Latency | Time delay for data to travel from source to destination | Milliseconds (ms) | How long it takes for 1 bit to go from A → B |
| Bandwidth | Amount of data that can be transferred per second | Megabits per second (Mbps) (or GB/s etc.) | How much data you can send per second |
Simple analogy — Road example 🛣️
-
Latency = Travel time of a single car from city A to B (How long it takes one car to reach)
-
Bandwidth = Road width (number of lanes) (How many cars can travel together per second)
✅ Quick facts to remember
| Term | High is good or bad? | Key goal |
|---|---|---|
| Latency | Lower = Better (less delay) | Fast response time |
| Bandwidth | Higher = Better (more data at once) | More throughput |
📱 Real-world example
- You have 100 Mbps bandwidth (fast pipe)
- But 300 ms latency (high delay, e.g., satellite link)
→ Even though the pipe is wide (lots of data can go), every request/response takes time to start flowing → Laggy experience (bad for gaming, video calls)
✨ Super short takeaway
- Latency = Speed of a single packet 🕒
- Bandwidth = Size of the pipe (amount per sec) 📶