Concurrency in Web Development

"Concurrency in Web Development”... 👀

Welcome to my blog page where I'll be shedding some more light on
 
"Concurrency in Web Development”...

Firstly, What exactly is concurrency? 

Well in short, it is the ability to multitask, handling multiple requests or tasks at once. I used the image above to best describe my understanding of concurrency, it handles traffic flow of multiple user requests at once. 

What are the methods to implementing concurrency?

There are various ways of implementing concurrent programs, such as implementing each computational execution as an operating system process, or implementing the computational processes as a set of threads within a single operating system process.

A concurrent language can be implemented parallel or sequentially. So in other word you have two operations, A & B. Operation A is executed and only once operation A is complete, will operation B start. This operation is therefor run sequentially.

With parallel implementation, operations will run simultaneously which means that they can both start and finish at the same time.

Concurrent operations will jump between A and B asynchronously while the operation is being run. 

There is message passing & shared memory: Message passing would be like sending an email to someone where the mail is copied between the sender to the receiver & then shared memory where all changes are available for all users to see at once because it is being shared.

To be a bit more specific, let's look at how concurrency can be implemented using Node.js:

Node has a different approach to handling multiple requests at one time by using one thread to handle all operations instead of using a new thread for each operation.

Node has two ways of handling this in the form of I/O operations like HTTP requests, database operations etc.

I/O operations can be blocking(synchronous) or non-blocking(asynchronous).

So in other words operations will run in a particular order and operation B cannot be dealt with until operation A is done.= Synchronous approach.

Else with the asynchronous approach, the process of handling operations A and B can be dealt with a lot quicker because operation B does not have to wait for operation A to be done.

What role does asynchronous programming play in concurrency?

It allows multiple operations or requests to be handled simultaneously or at a convenient time and possibly reducing any issues or bugs along the way.

It will handle the volume of user requests with much better ease opposed to not making use of concurrency.

What are API's related to implementing concurrency?

An API allows a client to fetch a copied version of a resource which can be manipulated locally and post the updated resource to a specified endpoint.

When multiple users require the same resource to manipulate and make changes at the same time, it could overlap and cause endless issues. Implementing concurrency strategies carefully could potentially reduced the problems that will be encountered by handling the crossover requests accordingly.

The event-loop in JavaScript:

JavaScript has a concurrency model based on how a event loop operates which handle the code, collects and processes events and executing queued sub-tasks.

 An event-loop runs asynchronously and will execute an operation when given the right opportunity to do so using a callback function which will then loop through all the operations in the loop and handle them one by one within the stack.

A comparison of how Oracle and MongoDB support concurrency:

Oracle maintains has a particular process in place, steps need to be followed in a particular order for it to function properly.

MongoDB makes use of collections to store all data but a collection is not a must-have before creating a document which makes a MongoDB database a lot more flexible to use. It doesn't have as strict measures in place.

MongoDB doesn't apply strict rules on schemas designs which allows more room for continuous improvement and adjustments.

In terms of concurrency, MongoDB allows multiple users to  both read and write the same data. To ensure consistency, MongoDB uses concurrency strategies such as locks and other concurrency control measures to prevent multiple users from modifying the same data at once.  

Oracle makes use of data- concurrently and consistency. Data concurrently allows users to access the same data at a time and data consistency that allows users to have a consistent view of data, including visible changes of the users themselves as well as the change of other users.

 The End...until next time!

Comments

Popular Posts