JavaScript, NoSql and CAP Theorem

Anjana Dinethra
3 min readMar 17, 2022

--

JavaScript

JavaScript Callbacks

In JavaScript we can consider functions as objects in object-oriented programming. We know that we can pass objects to functions as parameters. So, in JavaScript functions we can pass other functions as parameters and use those functions.

Not like in Java, JavaScript is a Single threaded language, so it executes only one statement at a time (Asynchronous). By using Callbacks in JavaScript, we can wait for a function to finish its execution and then start a new function after that. For example, we can consider database operations.

Example:

Fig1:Example for a callback function

JavaScript Promises

In JavaScript Promises are used to call Asynchronous operations. In promises there are three states. In the start of the program promise is in the pending state. Promise is moving to resolved state when it is successful and when it is unsuccessful it is moving to rejected state.at the end of the program promise again moves to pending state. For Resolved state we have then () method and for Rejected state we have catch() method.

Example:

Fig2:Example for a Promise

NoSQL

What is NoSQL?

NoSQL is also known as not only SQL. In NoSQL databases, data is stored differently than in relational databases. NoSQL databases replaces the traditional concepts of storage and querying in relational databases.

Why NoSQL over SQL?

NoSQL databases have many benefits when comparing to SQL databases. Flexible Data models is one of them. Also, there are advantages like Horizontal scaling and having incredibly fast queries.

Disadvantages of using NoSQL

  • Compatibility Issues with SQL instructions.
  • Scalability Challenges.
  • NoSQL databases doesn’t always follow ACID properties.
  • Limited Query Functionality.

CAP Theorem

Consistency

Every Client In each node should be able to view same data at the same time. Connected node shouldn’t be matter. Once data is written to a node that data must be transferred and written to all the nodes. For example, when we see a success message after data input data should be written to all the nodes.

Availability

Every Client who is making requests for should get a valid response.it doesn’t matter if one or many nodes down. Clients shouldn’t get an exception when making a data request.

Partition Tolerance

Partition can be also known as Communication break. Which is losing the connection between two nodes in the database. Partition Tolerance means communication break must not affect the operations of the database it should be able to carry out the database tasks.

Fig3:CAP Theorem

--

--