DEV Community

Cover image for Concurrency in Web Development
thabang21
thabang21

Posted on

Concurrency in Web Development

Definition of Concurrency:

Concurrency is when two or more processes (or threads) run together, but not at the same time.

Methods of implementing concurrency:

  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

What role does asynchronous programming play in concurrency:

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.

How are web APIs related to implementing concurrency:

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.

Steps how handling Concurrent Requests in a RESTful API:

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.

What is the event-loop in JavaScript and how does it relate to concurrency:

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

Compare the way Oracle and MongoDB support database concurrency:

  • 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

Top comments (0)