Network latency can have a significant impact on the user experience, especially in today's fast-paced digital landscape. In this blog post, we'll explore and understand the basics of network latency, discuss the different types and examine how they can impact an application's performance. By understanding the nuances of network latency, you'll be better equipped to identify potential bottlenecks in your app's infrastructure and take measures to optimise its speed and user experience. 


Imagine you're sending a message to a friend. Network latency is the time it takes for that message to travel from your device, get processed by various network components, and reach your friend's device. In the context of applications, it's the time it takes for data to travel between your device and the server that powers the app. Every millisecond counts, especially for real-time applications or those that rely heavily on data transfer.


Types of Network Latency:

Network latency can be broadly classified into two categories

    - Internet latency 

    - Intranet latency

Internet latency refers to the delay that occurs when data travels over the internet to reach its destination. This type of latency is caused by several factors, including:
Distance: The farther away the data has to travel, the longer it takes to reach its destination. For example, if you are located in Europe and trying to access a website hosted in North America, there will be more latency due to the greater distance the data has to travel.

Network congestion: When many users are accessing the internet at the same time, it can lead to congestion on the network, resulting in increased latency. For instance, during rush hour when many people are using their smartphones or computers to access the internet, network latency may increase due to the high demand for bandwidth.

Network hops: When data travels over the internet, it passes through multiple networks (or "hops") before reaching its final destination. Each hop can introduce additional latency, as the data has to wait for each network to process and forward it. For example, if you are trying to access a website hosted in China but your computer is located in Europe, the data will have to pass through several networks on its way to China, leading to increased latency.

Intranet latency refers to the delay that occurs within an organisation's private network, typically used for internal communication and collaboration. This type of latency can be caused by various factors, including:

Network architecture: The design of an organisation's network infrastructure can lead to increased latency, such as using a hub-and-spoke topology instead of a more modern design like a mesh or star topology.

Network congestion: Intranet latency can also be caused by network congestion within an organisation's private network. For example, if many employees are accessing the same shared resource simultaneously, it can lead to increased latency as the network struggles to keep up with the demand.

Network hardware issues: Intranet latency can also be caused by issues with the network hardware itself, such as slow hard drives or outdated network cards. For instance, if an organisation's network storage is slow or unreliable, it can introduce additional latency when data is transferred between different parts of the network.

Sources of Network Latency

There are two main sources of network latency that can impact the responsiveness of any application:

    - Connection establishment time

    - Data transfer time

Connection establishment time refers to the amount of time it takes for a client to establish a connection to a server or database. This process can have a significant impact on the performance of an application, especially in terms of response time and user experience. Let's consider the example of SSL connection.The overhead of creating an SSL (Secure Sockets Layer) connection is significantly higher than creating a TCP connection because SSL adds encryption and key exchange protocols on top of TCP. For example, when we create an SSL connection between our browser and the server, there are two round trips involved: one for creating the TCP connection and another for exchanging encryption parameters. This results in a higher overhead compared to creating a plain TCP connection.

Data transfer-related overhead refers to the additional tasks or operations required for data to be transferred over a network. This overhead can result from various factors such as the size of the data being transferred, the format of the data, and the protocols used for data transfer. All these factors can impact network latency, which is the time it takes for data to travel from the sender to the receiver over a network.

Data Size: The larger the data size, the more overhead is involved in transmitting it over the network. This is because more bandwidth and processing power are required to transmit large files or chunks of data. As a result, larger data sizes can lead to higher latency due to the increased amount of time required for data transfer.

Data Format: The format of the data being transferred can also contribute to overhead. For example, if the data is compressed, it may require additional processing power to decompress it before it can be transmitted over the network. Similarly, if the data is encrypted, additional processing power and time may be required to decrypt it.

Data Transfer Protocols: Different protocols used for data transfer can also impact overhead and latency. For example, TCP (Transmission Control Protocol) is a popular protocol used for reliable data transfer over the internet. However, it can introduce additional overhead due to its reliability features, such as retransmitting lost or corrupted packets, which can increase latency. 

So far we discussed what network latency is and how different factors can contribute to the same. Now let's explore some ways to minimise network latency and improve the overall performance of an application.

Minimising Network Latency: Strategies and Techniques

To reduce the time it takes for data to travel between the client and server, there are several strategies and techniques that can be employed. Here are some ways to minimise network latency:

Connection overhead: One of the primary causes of network latency is the creation of new connections between the client and server. To avoid this overhead, we can create connections and reuse them for different requests. For instance, a business application can use a connection pool for its database, while a web application can have a connection pool for HTTP connections to a REST application.

Data transfer overhead: There are two ways to address data transfer-related overheads: reducing the size of the data being transferred or avoiding unnecessary data transfers altogether. Caching is an effective way to reduce data transfer costs by storing frequently accessed data in memory or on disk. Similarly, caching static data like JavaScript files, CSS, and images can help reduce the amount of data being transferred between the browser and server. It's essential to avoid transferring data that is not necessary. By reducing the amount of data being transferred, we can significantly reduce network latency and improve overall performance.

Efficient data formats: To further minimise data transfer related overheads, we can use efficient data formats like RPC-based protocols for communication between intranet applications. While these protocols may incur some interoperability issues, they significantly reduce network data transfer related overheads. Additionally, compression can be used to reduce the size of data being transferred, but it may incur some CPU overhead.

SSL session caching: Another technique for reducing network latency is SSL session caching. By caching the encryption parameters exchanged between clients and servers, we can reduce the number of round trips required to create an SSL connection. This can help minimise network latency and improve overall performance.

Persistent connections: Keeping existing connections open for longer periods of time can also help reduce the overhead associated with creating new connections. This technique is known as persistent connections, which can significantly reduce network latency by reducing the number of connection establishments and tear-downs.

Static data caching: Caching static data like images, CSS, and JavaScript files can help reduce the amount of data being transferred between the browser and server. This can help improve page load times and overall performance.

Understanding the factors that contribute to network latency is crucial, but how do we translate this knowledge into actionable steps during performance testing?

Here are some key areas a performance tester can focus on:

Network Traffic Patterns: Analyse network traffic patterns to identify peak usage times and potential bottlenecks. Tools like network monitoring software can help visualise traffic flow and pinpoint areas of congestion.

Geographic Distribution of Users: Simulate user traffic from various geographical locations to understand how distance impacts latency. This helps identify areas where latency might be a bigger concern and require specific optimisation strategies.

Data Transfer Size and Format: Monitor the size and format of data being transferred during tests.

Connection Overhead: Analyse the number of connection establishments and tear-downs during tests.

Network Infrastructure: Evaluate the network infrastructure for potential limitations. Outdated hardware or inefficient network topologies can contribute to latency. Collaborating with network engineers to identify areas for improvement can help.

Network latency is a crucial factor to consider when building and maintaining high-performing applications. By understanding its causes and implementing the strategies outlined above, you can ensure your application delivers a smooth and responsive user experience.