Skip to main content

Network Latency

Summary

Network latency is the amount of time it takes for a packet of data to travel from its source to its destination. It is an important factor in determining the overall performance of a system, as it affects the amount of time it takes for data to be transferred between two devices.

Calculation formula: Network latency = (Transmission time + Propagation time + Queuing delay) / 2

Transmission time: the time it takes for the source device to send the packet Propagation time: the time it takes for the packet to travel from the source to the destination Queuing delay: the time it takes for the data to be stored in the network queues

Examples: If a packet of data takes 2 ms to send and 10 ms to travel from source to destination, and there is no queuing delay, the network latency would be calculated as follows:

Network latency = (2 ms + 10 ms + 0 ms) / 2 = 6 ms

Network latency can be affected by a variety of issues and can be measured with various metrics:

MetricDescription
Round Trip Time (RTT)The total time it takes for a packet to travel from the source to the destination and then back to the source.
Packet Loss RateThe number of packets that are lost during the transmission from the source to the destination.
ThroughputThe rate of data transfer between the source and the destination.
Connection TimeThe time it takes to establish a connection between the source and the destination.
JitterThe variation in latency between consecutive packets.
Latency VarianceThe difference between the average latency and the maximum latency.
Response TimeThe time it takes for the destination to respond to the packet sent by the source.
Avg. Transmission TimeThe average time it takes for the packet to be sent from the source to the destination.
Path MTUThe maximum size of a packet that can be sent from the source to the destination.
Retransmission RateThe rate of packet retransmissions due to packet loss or errors.

Some ways to improve network latency

#Action
1Switch to a faster/better ISP
2Reduce the number of hops in the network
3Use faster or higher bandwith hardware such as faster switches and routers
4Implement Quality of Service (QoS)
5Utilize caching techniques
6Optimize network protocols
7Utilize the latest network standards and technologies
8Reduce packet fragmentation
9Manage bandwidth usage
10Utilize a Content Delivery Network (CDN)
11Use compression
12Increase Bandwidth
13Improve Hardware

Ways to improve network latency on the frontend:

#Frontend Latency
1Use a CDN
2Optimize your images
3Minify and combine files
4Use browser caching
5Use HTTP/2
6Enable compression
7Use a lightweight framework
8Use pre-rendering
9Use Chrome DevTools
10Optimize client-side code
  1. Use a CDN – Using a content delivery network (CDN) to host static resources such as images, CSS, and JavaScript can greatly reduce the amount of time it takes for the browser to download them, thus reducing latency.

  2. Optimize your images – Optimizing images that are being served to the client can significantly reduce the amount of time it takes for them to be loaded.

  3. Minify and combine files – Minifying and combining JavaScript and CSS files into fewer files can reduce the number of requests the browser must make, thus reducing the amount of time it takes for each request to be processed.

  4. Use browser caching – Setting up browser caching for static resources such as images, CSS, and JavaScript can reduce the amount of time it takes for the browser to download them, since they are already cached in the browser.

  5. Use HTTP/2 – HTTP/2 allows multiple requests to be sent in parallel, reducing the amount of time it takes for the browser to download each resource.

  6. Enable compression – Enabling compression on the server can reduce the size of the files being sent to the client, thus reducing the amount of time it takes for them to download.

  7. Use a lightweight framework – Using a lightweight front-end framework such as React can reduce the amount of code that needs to be sent to the client, thus reducing the amount of time it takes for the browser to download it.

  8. Use pre-rendering – Pre-rendering pages can reduce the amount of time it takes for the browser to render the page, since the content is already rendered on the server.

  9. Use Chrome DevTools – Using Chrome DevTools can help identify areas of your website that are causing latency, and can provide insights into how to reduce it.

  10. Optimize client-side code – Writing efficient client-side code can reduce the amount of time it takes for the browser to process it, thus reducing latency.

Examples of Latency differences by country - actual will vary based on many factors like infrastructure, peering and traffic routing will affect the latency

From San Francisco:

Region/Country Latency (ms) San Francisco 0 Los Angeles 5 Denver 20 New York 25 London 30 Frankfurt 35 Singapore 40 Mumbai 50 Sydney 55 Tokyo 60 Sao Paulo 70 Johannesburg 75 Hong Kong 80 Mumbai 85 Sydney 90