Difference between a blocking language and a non-blocking language

Asked

Viewed 1,859 times

7

In practice, what is the difference between a blocking language and a non-blocking language?

What differences can we see in both front-end and back-end?

Using an example, let’s imagine an endpoint of an API where something is written in a database and is returned to the client any response.

If several requests are made at the same time for this endpoint, in practice how would a system behave with a blocking architecture and other non-blocking?

  • 3

    Is it language or algorithm? I’ve never seen the term used for a language.

  • @bigown thought that this term was used as a characteristic of a language. It would be interesting to begin by explaining that this is a mistake. This question arose because I started studying Nodejs.

1 answer

4

Explanation

In a blocking system the requisitions would be queued and then processed one by one, so it would not be possible to process several of them at the same time. That is, the client who has the newest request will only have its request processed after the oldest requests have been processed in full.

And on the non-blocking ones we will have to allow the request of the newest client to be processed (or at least a part of it) before all requests that the server received before it are processed.

Example

Assuming that the example is a Petshop system, and that the request is intended to add an Animal that belongs to an Owner to the Database and add that Owner if it is not in the Database.

Blocker

The Customer who sent the oldest request will only have the Animal and the Owner in the Database after all other requests have been processed. In the worst case we will have an I/O operation that takes hours, and so the younger client will not have his response to your request anytime soon.

Nonblocking

The Customer who sent the oldest request may have at least the Animal registered in the Database even if it still has older requests being processed. In this case even if I/O delays the system will still meet other requests.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.