Importance of proper Request Handling

Jan 07, 2019

In this article

  1. SPA
A Number of network requests grows rapidly and it is important to pick a proper way to handle them. Let’s check the most popular approaches.

SPA

Any service that gets incoming requests has to handle them and, most often, return some kind of response. Such a service can be either a service that handles tasks in a database or a service that handles requests over a network.

According to the Internet live stats, there are about 2 billion web services so far and the number of them is growing every minute. So, the number of network requests and data that should be handled, are also rapidly increasing.

Each method of network request handling has its own positive and negative sides. Therefore, the performance, speed, and operability of your application depend on the choice of approach for handling such requests.

A lot of articles consider how to handle synchronous and asynchronous network requests only partially. That's why we would like to describe the most widespread approaches to this process.

Synchronous approaches:

Probably the simplest synchronous approach to handling network requests is "Sequential handling of requests". But the lack of parallelism in request handling creates a natural queue, which makes scaling impossible. As a result, using this approach a large number of data can't be handled in a timely manner.

With a "Process for a request" architecture, an application consists of main and work processes. The main process handles incoming requests and creates a work process for each new request. In this case, scaling is the simplest, but the process consumes a lot of resources, and the absence (by default) of shared memory does not allow to have access to shared data.

At the same time, the work processes are independent of each other, and errors in one process do not affect the work of other work processes. Access rights are managed by standard OS mechanisms, and for changing the request handling algorithm the only thing you have to do is to change the script. Probably the best DBMS to handle such requests is PostgreSQL, which will make it possible to effectively use multi-core CPUs.

"Thread for a request" is also simple to implement and resembles the previous approach, except using of threads. In this case, it is possible to have shared memory and effectively use multi-core CPUs. But unfortunately, this approach is more resource intensive.

"Processes/threads pool" is a mixed approach that is difficult to implement and is quite expensive at cost. The main thread accepts incoming requests and builds them in a queue, which is handled by work processes. In this way, scaling is performed, but it is limited in conjunction with the resources used. At the same time, resources are more spent on creating a pool, which reduces costs while creating separated threads or processes and effectively uses multi-core CPUs.

Asynchronous approaches:

Asynchronous handling of all requests is typical for event-oriented handling - "Reactor pattern". Such handling consists of multiple calls followed by handlers. In a single-threaded application, only one handler is executed, while in an application that uses the "Reactor pattern" approach, handlers are pseudo-parallel.

This approach allows you to scale efficiently no-CPU-intensive requests and the number of connections, which will significantly increase application performance. "Reactor pattern" is quite difficult to implement and the occurrence of errors will lead to complete blocking of the service.

In the approach "Half sync/half async", a simplified (green) control thread is used. There are other threads in the application controlled at the OS level, but green threads are managed by the application execution system. In this case, the performance of the asynchronous approach is combined with the simplicity of programming the synchronous code.

With proper implementation of the approach, requests and the number of simultaneous connections could be well scaled. The code with the approach is easier to develop than code with other asynchronous approaches. However, errors that occurred and the handling time of requests can block the entire process, which is especially bad for real-time systems.

"Pipelining" is the handling process with a chain of several OS threads. Each thread at each moment of time performs a set of operations to handle the request.

This approach is well scaled, but unfortunately, it is not suitable for some types of network requests. Moreover, this approach is quite difficult to implement and test.

This article describes only the most frequently used approaches for network request handling and you could hear about other ones. However, more pros and cons for each method can be found in a specific situations and in specific application.

Blog

using-chatgpt-in-projects-development-today

Using ChatGPT In Projects Development Today

Apart from text-to-image models, one of the landmark events of 2022 was undoubtedly the ChatGPT model.

Sep 06, 2023
artificial-intelligence

Artificial Intelligence In Logistics: How To Apply AI In The Supply Chain?

Artificial intelligence is taking a bigger place in our lives every day.

Aug 16, 2023
real-world-ai-applications-retail-autonomous

Real-World AI Applications: Retail, Autonomous Transportation, Engineering, And Manufacturing

Welcome to the age of AI, where technological marvels have seamlessly woven into the fabric of our daily lives. With scientific advancements in artificial intelligence and computer vision, our world has changed profoundly, shaping how we interact with technology and each other.

Aug 01, 2023
importance-of-software-maintenance-to-your-business

Importance of Software Maintenance to Your Business

Companies that neglect to maintain their software can face several difficulties that can seriously affect business.

Jul 24, 2023
all-about-integrating-ai

All About Integrating AI Into Web And Mobile Applications

AI integration has become increasingly accessible thanks to advancements in machine learning algorithms, cloud computing infrastructure, and open-source libraries. It empowers developers to create applications that can understand, learn, and adapt to user behavior, ultimately improving efficiency and personalization. From virtual assistants that can understand natural language to image recognition systems that can identify objects in real-time, AI is reshaping how we interact with technology daily.

Jul 12, 2023
offshorenearshore-development-service

All You Need To Know About Offshore/Nearshore Development Service

In today's globalized and technologically interconnected world, offshore and nearshore development have emerged as compelling strategies for companies seeking cost-effective and scalable software development solutions. These approaches offer access to a diverse talent pool, reduced development costs, and increased flexibility. However, they also present unique challenges that must be carefully navigated to ensure successful outcomes.

Jul 04, 2023
terms-of-reference

Terms Of Reference For The IT-Product Development: Why It Is Important

The question of developing or not developing the terms of reference sometimes becomes the point at which contradictions erupt between the client and the executor. Without terms of reference, you can slow down the project's development, worsen the result of the work, and lose common ground with each other going separate ways without starting anything.

Jun 16, 2023
it-staff-augmentation-when-profitable

IT Staff Augmentation: When Profitable And When Is Not The Best Option

IT staff augmentation is an approach for the profitable hiring of specialists. With IT staff augmentation, you don't have to develop a catchy ad for a vacancy, conduct dozens of interviews, and then think hard about the best choice. IT staff augmentation is much easier: you apply to the staff provider, get CVs, assess the suitable developers, sign the contract, and in the defined timeframe, the employee starts to work.

May 29, 2023

Contact Us

We have a good offer for you

clock

15 minutes of consultation

shield

Strict non-disclosure policy

window

Involvement of High-Level Developers to your Project

hand-shake

Fruitful Cooperation & Prominent Increment

Server error. Please, try in a few minutes again
Call Back