Importance of proper Request Handling

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

nearshore-staff-augmentation-guide image

Nearshore IT Staff Augmentation: Maximizing Efficiency and Talent Acquisition

Learn how nearshore staff augmentation can enhance your software development team's capabilities. Explore its benefits, key strategies, and how to find the right IT talent to meet your project needs.

Oct 04, 2024
react-micro-frontend image

Micro Frontend in React: Mastering Modular Architecture for Optimal Scalability

As web applications grow more complex, micro frontend architecture in React is changing the game. By splitting up large, monolithic apps into smaller, independent pieces, React microfrontends make it easier to scale, develop faster, and improve the overall user experience. Let’s explore how this approach can help you build more flexible and efficient apps.

Oct 01, 2024
migrate-from-react-to-next-js image

How to Convert React JS to Next JS: A Step-by-Step Guide

React apps are great for building dynamic user interfaces, but when it’s time to scale up performance, it’s Next.js to the rescue. If you’re looking to move React app to NextJS, this guide will walk you through the process step-by-step. From handling React components to configuring server-side rendering, let’s dive into the transition and unlock faster page loads, better SEO, and a smoother development flow.

Sep 26, 2024
convert-figma-to-react image

How to Convert Figma Design into React Code: A Comprehensive Step-by-Step Guide

Ready to turn your sleek Figma designs into a fully functional React app? With the right tricks and tools, you can effortlessly bring your static designs to life. Let’s jump into the ultimate guide to convert Figma into React like a pro!

Sep 23, 2024
alternatives-to-react image

Top 9 Alternatives to ReactJS: Exploring the Best Front-End Frameworks

ReactJS has taken the web development world by storm with its innovative approach to building user interfaces. Its component-based design and efficient virtual DOM have set a high standard for dynamic, interactive web applications. But while React is a dominant player, it’s not the only game in town. In this article, we’ll dive into the eight best React alternatives, each offering its own set of features and advantages tailored to various needs and preferences in front-end development.

Sep 19, 2024
technology-stack-for-saas-product image

SaaS Technology Stack That You Should Pay Attention To in 2024

SaaS is a powerful model for driving business growth, as it leverages cloud computing services to eliminate the need for customers to buy and manage their own infrastructure. This approach helps businesses save money, while software providers benefit from steady revenue through the subscription model.

Sep 03, 2024
offshore-react-development image

Offshore React Developers: Main Skills and Tips for Hire

React is not just a buzzword in the tech world - it’s a game-changer. Its ability to build sleek, responsive user interfaces has made it a favorite among developers everywhere. But here’s the catch: the best React engineers are often so in demand that they may be unavailable in your local market. So, what do you do when you need top talent but can’t find it close to home? You look offshore. Offshore development can connect you with skilled React experts ready to convert your vision into reality. In this guide, we’ll walk you through how to hire and collaborate with an offshore React team that’s perfect for your project.

Aug 29, 2024
react-performance-optimization-techniques image

React Performance Optimization: Best Techniques and Ways to Implementation

A fast and responsive React application is key to keeping users happy. But as your app grows, performance can start to lag. In this article, we’ll explore some important techniques to optimize React app performance, like code splitting, reducing bundle size, profiling, and steering clear of common mistakes. Let’s dive in and learn how to keep your React applications lightning-fast

Aug 27, 2024

Contact Us

We have a good offer for you

clock icon

15 minutes of consultation

shield icon

Strict non-disclosure policy

window icon

Involvement of High-Level Developers to your Project

hand-shake icon

Fruitful Cooperation & Prominent Increment

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