Concurrency in Web Development

Concurrency in Web Development

Concurrency

Concurrency is everywhere in modern programming, whether we like it or not, for example: multiple computers in a network, multiple applications running on one computer and even multiple processors in a computer.

But ... what is concurrency

Concurrency simply relates to an application that is processing more than one task at the same time. 

Concurrency is essential in modern programming:

  • Web sites must handle multiple simultaneous users
  • Mobile apps need to do some of their processing on servers (“in the cloud”)

  • Graphical user interfaces almost always require background work that does not interrupt the user

Concurrency is crucial in the field of Web Development, as highlighted above, websites must be able to handle multiple simultaneous users. Whilst browsing a website, users will demand a number of requests from the web servers and these web servers need to support these requests at any given moment. 

This is made possible through the use of concurrency!

There are various methods to implementing concurrency however, multiprocessing and multithreading or an approach that uses both are the most common ways of implementing concurrency.

Node.js

Now, we will take a deeper dive and see how concurrency is implemented with Node.js an open source development platform for executing JavaScript code server-side (backend).

As opposed to multiprocessing or multithreading as seen above, Node.js has another approach to concurrency. 

Node.js uses the I/O operations model that uses asynchronous non-blocking I/O calls to implement concurrency, which means that multiple actions are taken at the same time while executing a program. 

The Event Loop is what allows Node.js to perform non-blocking I/O operations despite the fact that JavaScript is single-threaded. 

One can think of the Event Loop as some kind of “manager” to be able to handle asynchronous operations. That’s precisely what the Event Loop does. Javascript executes all operations on a single thread, but using a few smart data structures, it gives us the illusion of concurrency.

For example, if there are two endpoints that follow one another in the program, the server will move one to make a request to the second endpoint without waiting for the first to return data. 

Therefore although API's need to wait for a response to be able to deliver data or information, this illusion of concurrency allows a user to go about their business in an application, while processes run in the background.

All this is possible thanks to Node’s events loop mechanism, which helps the server to get a response from the previous API call. This is the asynchronous programming model in a nutshell, where asynchronous programming plays the role of aid in executing operations at the same time without having to wait for each operation to be completed which further allows for the proper functioning of web API's on the website!

Oracle and MongoDb

Lastly, we will how Oracle's and MongoDB's approach to supporting database concurrency compare.

It is imperative for a database to support concurrency due to the fact that different users and administrators access the same data all the time. 

Problems could arise if a user makes use of a CRUD (Create, Read, Update and Delete) operation now and then and the database is not able to handle the issue if attempts are made to modify a specific piece of data at the same time.

Thus Oracle's approach to this issue is by use of an isolation model called serialisability. The serialisable mode of transaction behaviour or tries to ensure that transactions run in such a way that they appear to be executed one at a time, or serially, rather than concurrently. 

Oracle offers two isolation levels, providing application developers with operational modes that preserve consistency and provide high performance.

Whereas MongoDB makes use of locking and other concurrency control measures to prevent multiple clients from modifying the same piece of data simultaneously. Writes to a single document occur either in full or not at all, and clients always see consistent data. 

These concurrency control ensures that database operations can be executed concurrently without compromising correctness.

Thank you for taking the time to read my blog! 

References








HyperionDev Class Notes (2021)







Comments

Popular posts from this blog

Big O Notation Basics for Web Developer

Interfaces in Object Oriented Programming Languages and Prototype-based Languages