Scaling workflows – message queues and task queues

One important aspect of scalability is to reducing coupling between systems. When two systems are tightly coupled, they prevent each other from scaling beyond a certain limit.

For example, a code written serially, where data and computation is tied into the same function, prevents the program from taking advantage of the existing resources like multiple CPU cores. When the same program is rewritten to use multiple threads (or processes) and a message passing system like a queue in between, we find it scales well to multiple CPUs. We've seen such examples aplenty in our concurrency discussion.

In a much similar way, systems over the Web scale better when they are decoupled. The classic example is the client/server architecture of the Web itself, where clients interact via well-known RestFUL protocols like HTTP, with servers located in different places across the world.

Message queues are systems that allow applications to communicate in a decoupled manner by sending messages to each other. The applications typically run in different machines or servers connected to the Internet, and communicate via queuing protocols.

One can think of a message queue as a scaled-up version of the multi-threaded synchronized queue, with applications on different machines replacing the threads, and a shared, distributed queue replacing the simple in-process queue.

Message queues carry packets of data called messages, which are delivered from the Sending Applications to the Receiving Applications. Most Message Queues provide store and forward semantics, where the message is stored on the queue till the receiver is available to process the message.

Here is a simple schematic model of a Message Queue:

Scaling workflows – message queues and task queues

Schematic model of a distributed message queue

The most popular and standardized implementation of a message queue or message-oriented middleware (MoM) is the Advanced Message Queuing Protocol (AMQP). AMQP provides features such as queuing, routing, reliable delivery, and security. The origins of AMQP are in the financial industry, where reliable and secure message delivery semantics are of critical importance.

The most popular implementations of AMQP (version 1.0) are Apache Active MQ, RabbitMQ, and Apache Qpid.

RabbitMQ is a MoM written in Erlang. It provides libraries in many languages including Python. In RabbitMQ, a message is always delivered via exchanges via routing keys which indicate the queues to which the message should be delivered.

We won't be discussing RabbitMQ in this section anymore, but will move on to a related, but slightly different, middleware with a varying focus, namely, Celery.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.141.75