Concurrency in Web Development
Tags: multitasking
Published: 2021-01-28 17:22:30

<h3><b>Definition of Concurrency:</b></h3>
Concurrency is when two or more processes (or threads) run together, but not at the same time.

<h3><b>Methods of implementing concurrency:</b></h3>

1. Multiprocessing, in computing, a mode of operation in which two or more processors in a computer simultaneously process two or more different portions of the same program (set of instructions).

2. Multithreading is the ability of a program or an operating system process to manage its use by more than one user at a time and to even manage multiple requests by the same user without having to have multiple copies of the programming running in the computer

<h3><b>What role does asynchronous programming play in concurrency:</b></h3>

In Node.js, I/O often refers to reading/writing files or network operations. Network operations get external information into your application, or send data from your application out to something else.
Asynchronous programming in Node. js. Asynchronous I/O is a form of input/output processing that permits other processing to continue before the transmission has finished. In the following example, I will show you a simple file reading process in Node.

<h3><b>How are web APIs related to implementing concurrency:</b></h3>

APIs that are subject to a high volume of unsafe requests must be designed with control strategies that can gracefully handle situations when multiple requests attempt to update a single resource.


<h3><b>Steps how handling Concurrent Requests in a RESTful API:</b></h3>

a. User A requests resource 1 via a GET endpoint.
b. User B requests resource 1 via a GET endpoint.
c. User A makes changes on resource 1 and saves its changes via a PUT request.
d. User B makes changes on resource 1, on the same fields as user A, and saves its changes via a PUT request.

<h3><b>What is the event-loop in JavaScript and how does it relate to concurrency:</b></h3>


The event loop is what allows Node. js to perform non-blocking I/O operations despite the fact that JavaScript is single-threaded. The loop, which runs on the same thread as the JavaScript code, grabs a task from the code and executes it. When one of these operations completes (this is an event), the kernel tells Node

<h3><b>Compare the way Oracle and MongoDB support database
concurrency:</b></h3>

- MongoDB uses multi-granularity locking(see wired tiger) that allows operations to lock at the global, database or collection level, and allows for individual storage engines to implement their own concurrency control below the collection level

- The Concurrency Oracle metric allows simultaneous access of the same data by many users. A multi-user database management system must provide adequate concurrency controls, so that data cannot be updated or changed improperly, compromising data integrity.

Reference:
-http://berb.github.io/diplomathesis/original/023_concurrency.html
-https://whatis.techtarget.com/definition/multithreading
-https://attacomsian.com/blog/reading-writing-files-nodejs
-https://www.geeksforgeeks.org/node-js-event-loop
-https://docs.oracle.com/cd/B19306_01/server.102/b14220/consist.ht