Definition
Latency is the delay between a user’s action and a web application’s response to that action, often referred to in networking terms as the total round trip time it takes for a data packet to travel.
Overview
Latency is generally measured in milliseconds (ms) and is unavoidable due to the way networks communicate with each other. It depends on several aspects of a network and can vary if any of them are changed.
There are four main components that affect network latency, including:
- Transmission medium: The physical path between the start point and the end point. The type of medium can impact latency. For instance, old copper cable-based networks have a higher latency than modern optic fibers.
- Propagation: The further apart two nodes are the more latency there is as latency is dependent on the distance between the two communicating nodes. Theoretically, latency of a packet going on a round trip across the world is 133ms. In actuality, such a round trip takes longer, though latency is decreased when direct connections through network backbones are achieved.
- Routers: The efficiency in which routers process incoming data has a direct impact on latency. Router to router hops can increase latency.
- Storage delays: Accessing stored data can increase latency as the storage network may take time to process and return information.
How to reduce latency
Latency can be reduced by addressing the aforementioned components and ensuring that they are working correctly. It can also be reduced by using dedicated networks that streamline the network path and provide direct communication between nodes.
Content Delivery Network (CDN) providers such as StackPath provide customers with private networks that allow them to bypass the public internet. These private networks reduce latency by providing more efficient paths for data packets to travel on.
How Latency Works
Let’s look into how latency actually works and how, as a user, you’re usually impacted by it. Consider that you are buying a product through an online shop and you press the “Add to Cart” button for a product that you like.
The chain of events that occur when you press that button are:
- You press the “Add to Cart” button.
- The browser identifies this as an event and initiates a request to the website’s servers. The clock for latency starts now.
- The request travels to the site’s server with all the relevant information.
- The site’s server acknowledges the request and the first half of the latency is completed.
- The request gets accepted or rejected and processed.
- The site’s server replies to the request with relevant information.
- The request reaches your browser and the product gets added to your cart. With this, the latency cycle is completed.
The time it takes for all these events to complete is known as latency.
Latency vs bandwidth vs throughput
The performance of your network and application depend on latency, bandwidth, and throughput, but it’s important not to confuse one with the other.
Bandwidth is the amount of data that can pass through a network at any given time. Consider bandwidth as how narrow or wide a pipe is. A wider pipe allows for more data to be pushed through. Throughput, on the other hand, is the amount of data that can be transferred over a given period of time.
An efficient network connection is composed of low latency and high bandwidth. This allows for maximum throughput. The bandwidth can only be increased by a finite amount as latency will eventually create a bottleneck and limit the amount of data that can be transferred over time.
Examples of Latency
High latency can adversely affect the performance of your network and greatly reduce how quickly your application communicates with users. A content delivery network allows customers to reach their users in the most efficient manner possible. These delivery channels greatly reduce the network lag between the user and the application.
You can check the network latency of your internet connection with any website by passing its web address or IP address in the command prompt on a Windows or Mac. Here is an example of the command prompt on Windows:
C:Usersusername>ping www.google.com
Pinging www.google.com [172.217.19.4] with 32 bytes of data:
Reply from 172.217.19.4: bytes=32 time=47ms TTL=52
Reply from 172.217.19.4: bytes=32 time=45ms TTL=52
Reply from 172.217.19.4: bytes=32 time=47ms TTL=52
Reply from 172.217.19.4: bytes=32 time=43ms TTL=52
Ping statistics for 172.217.19.4:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 43ms, Maximum = 47ms, Average = 45ms
Here you can see the result of pinging www.google.com
. The statistics show that the average time it takes for a roundtrip between the given PC and Google’s network is 39ms.
Key Takeaways
- Latency is the time it takes for a data packet to travel from the sender to the receiver and back to the sender.
- High latency can bottleneck a network, reducing its performance.
- You can make your web applications less latent by using a CDN and a private network backbone to transfer data.