Queues (queues) are useful in Node.js, which is asynchronous?

Asked

Viewed 550 times

0

I know that in languages like PHP, queues (queues) are often used to perform more "heavy" actions, such as sending a series of emails and the like.

Therefore, taking into account the asynchronous nature of Node.js, this type of approach is recommended in this environment?

For example: I need to send multiple emails. I should then look to use some queuing system, or I can leave the Event-loop native solve these tasks for me?

1 answer

3


Queues are not what you think they are (in a sophisticated mechanism). Fila is just a data structure very similar to a list and uses what is called FIFO (First In First Out) or in Portuguese PEPS (Primeiro a Entrar, Primeiro a Sair). He opposes the pile which is LIFO/UEPS (Last In, First Out). So, yes, this data structure is useful for various things and asynchrony has nothing to do with it.

Queues are used for numerous things. It can be used to create a collection of standardized actions such as sending emails, placing all messages that should be sent and the system knows that by using a queue you should get the first ones that entered this queue. It is possible to create more sophisticated systems that allow the queue to receive new items (it may be a scheduler that is perhaps calling a queue), that some object receives a notification that has a new object or that has changed its state from empty to containing some item, but the queue itself is just the data structure.

Even something sophisticated needs a data structure to store what must be processed into an algorithm of this type, the strategy of how to process is that it will determine the best structure. For example it is unlikely, but not impossible that a stack is interesting, in some cases a priority queue may be more interesting.

On the other hand this is a technique you use when you want a... queue! So in any technology you can do this without a queue, it just differentiates how hard each one makes it harder. Queue serves to organize data in a certain order.

Even asynchronmentalism is not magical, it is possible to obtain it virtually in any language, some easier or better than others. It can be pretty chaotic to do something without a queue, but it may be enough for you, and if you have easy asynchronism and do not require more control and have little volume, this solution may be enough to meet your demand. Not for any case. Asynchronmentalism serves to not block the application, that’s all.

Actually I’m curious to understand why the asymchronism could avoid such use since they are orthogonal, so there’s no dichotomy between them. The most that can happen is that the language library has an internal queue system to manage the work and you don’t need to know this. Again this has nothing to do with asynchrony, even though the two mechanisms may be together in the library.

The question I don’t know how to answer is whether Node has its own library that manages a queue of actions that you determine internally and exposes only its API. I can guarantee you have some library that does that.

Browser other questions tagged

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