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.

When deciding between MPA vs SPA, it’s important to analyze how the request handling model aligns with your app’s needs. 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.

If you're deciding between PostgreSQL vs MySQL vs MongoDB, we recommend reading our article for a detailed comparison of these databases.

"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

react-js-advantages image

Advantages and Benefits of React JS: The Essential Tool for Modern Developers

Ever wonder how modern apps feel so smooth and responsive? That’s the magic of React—a tool that makes crafting sleek user interfaces surprisingly simple.

Jan 16, 2025
react-js-best-practices image

8 ReactJS Best Practices for Writing Better Code

If you’ve been working with React for a while, you probably know that writing clean, efficient code is key to building great apps. Whether you’re just getting started or already deep into React, sticking to ReactJS best practices can really make a difference. In this article, we’ll break down some simple, yet powerful tips to help you write better, more maintainable code. From managing state to organizing your components, these practices will help you write smoother, faster React applications. Let’s get into it!

Dec 20, 2024
rapid-application-development-rad image

Rapid App Development: Full RAD Methodology Overview and Practical Advice

The choice of application development methodologies is becoming the No. 1 challenge in a rapidly growing market. According to a Gartner study, $310 billion was spent globally on enterprise software engineering in 2015. The development of the RAD (Rapid Application Development) concept become the basis for creating a flexible and adaptive application development system, counterbalancing with a rigid Waterfall model.

Dec 09, 2024
react-websocket image

ReactJS WebSocket: How to Buid a Real-time Connection

Real-time communication is everywhere—think live chats, notifications, or dashboards that update without you refreshing the page. That’s where WebSockets come in, making instant two-way communication between your app and the server a breeze. If you’re working with React, WebSocket can open up a whole world of possibilities for building dynamic, interactive apps.
In this React WebSocket tutorial, we’ll walk you through the basics, share some examples, and show you just how easy it is to get started. Let’s dive in!

Dec 02, 2024
react-architecture image

React.JS Architecture: Best Real-world Practices

What is React architecture? At its core, it’s the foundation that defines how your React application is structured, how data flows, and how different components interact. A thoughtfully designed architecture is not just about clean code—it’s about creating efficient, maintainable, and scalable applications that stand the test of time.

Nov 28, 2024
dashboard-development image

How to Develop a Dashboard: All About Requirements, Tasks, Mistakes, and UI

Dashboards are a time-saving tool, so the user should be able to interact with them easily. It is not the best place for unnecessary clutter, so you should look for the simplest and most obvious solutions. After reading this article, you’ll learn how to develop a dashboard that is both high-quality and effective.

Oct 30, 2024
cost-to-hire-a-react-developer image

How Much Does it Cost to Hire an Experience React.js Developer in 2024

When you’re planning to build a dynamic web app or enhance an existing one, hiring a skilled React developer is essential. But how much does it cost to hire a React developer? According to Talent, hiring a React.js developer in the U.S. will set you back about $120,000 annually. The actual price tag depends on several factors, including whether you need a junior or senior programmer, as well as whether you’re hiring through a company or directly. In this article, we’ll break down the key elements that affect the React.js developer cost, helping you make the best decision for your project.

Oct 28, 2024
react-seo image

React SEO: Best Practices, Components, Optimization Tips

Building a React web app that's fast, user-friendly, and visible to search engines can be a bit tricky. While React offers a powerful framework for creating dynamic, interactive interfaces, it's not inherently SEO-friendly due to its reliance on client-side rendering. This can lead to issues like search engines missing important content, slower load times, and reduced search rankings. However, by focusing on React search engine optimization, techniques like implementation of server-side rendering (SSR), optimizing images, and improving load times, you can ensure your application performs well and ranks higher in search results. In this article, we'll dive into practical, technical strategies to make your React app more SEO-friendly.

Oct 18, 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
Book a call