When building web applications, there are many different tools that developers can use to optimise performance. One important group of tools are message brokers, such as RabbitMQ. But what is RabbitMQ, and how does it help performance?

Well, before we look at the benefits of using a Rabbit MQ server, we must first understand what a distributed computing system and broker is and how they interact.

What is distributed computing?

Unlike standard computing models, a distributed computing model is one where multiple computers operate in a network. This allows them to interact with each other as well as share tasks and components.

Machines in this network communicate by passing messages, and one way of doing this is through message queues. These queues use what's called a message broker to quickly and easily managed the demand between computers for maximum efficiency.

What is a message broker?

In simple terms, a message broker ‘sits’ between the machines in a distributed computing system process flow. Instead of each machine passing messages directly to each other, the messages are first sent to a message broker, like RabbitMQ, which then orders the messages into an optimised queue. These messages are then passed on to the relevant receiving machines when those machines are ready to process the messages.

In this context, a message might be a command to process an order, run a specified task, pull requests made to a database, or to simply send an email.

Within this network, the machine that sends the original message is called the ‘producer’, while the machine that receives the message is the ‘consumer’. The 'broker' is the bit in the middle, the machine that brings the 'producer' and 'consumer' together.

This entire messaging process is controlled by the Advanced Message Queueing Protocol (AMQP). AMQP is a set of standards which covers the entire messaging process, and allows the 'conversations' between the message broker systems that RabbitMQ facilitates. This is unlike 'broker-less' models which send requests directly from the machine to the web server.

What is RabbitMQ?

As stated above, RabbitMQ (Rabbit Message Queue) is just one example of a message broker model. The RabbitMQ server sits between the machines and manages the queue. Tasks are added to the queue by the message broker and it’s up to the consumers to connect to Rabbit and specify that they are ready to receive and execute tasks from a particular queue.

Why use RabbitMQ?

Distributed computing systems and other message broker models are incredibly useful on their own, providing numerous benefits over other 'broker-less' setups. Below are some of the key benefits provided by the RabbitMQ server and other message broker models.

Compatibility

Firstly, RabbitMQ allows multiple different programming languages and platforms to work together. Thanks to RabbitMQ, a message can be written in C# by the producer, but handled in Java by the consumer. The two machines are essentially trying to talk to each other in different languages that they don’t both understand. But, through the multilingual broker RabbitMQ server as a proxy, they can communicate without any issues. Messages can be written and received in languages such as C#, Java, PHP or Perl, but are usually passed around by the broker in XML/JSON/plaintext format.

Decoupling

On its own, separating a producer from its consumers has many advantages. The producer of the message doesn’t need to know anything about the consumer, which means it doesn’t need to bloat itself by learning how to connect to or communicate with it. The producer just sends a message to the message broker, in this case RabbitMQ, and the consumer picks it up. Because they are decoupled, it doesn’t matter to the producer if a consumer moves to a new server or is replaced by a different process, they can continue to seamlessly communicate via the RabbitMQ server.

Availability

If a consumer is unavailable for any reason (e.g. for server maintenance), messages sent from the producer can simply be held in the queue until the consumer is available again, at which point it can quickly process them all.

This has the added benefit of allowing the producer to continue with its own work until the consumer is back up and ready to process messages from the broker. Without the message queue the producer would have to wait around until the consumer was ready and then send all its requests in one go.

So, instead of overloading the consumer with a workload it can’t handle, RabbitMQ allows the consumer to pick up the work as and when it's ready to process it.

Scalability

Similarly, if there are too many messages for a consumer to handle while active, the messages can just remain in the queue to be consumed later. Or, more consumers can be added to handle the messages coming from the queue. This will improve processing times and allows developers to see which machines in the network are doing a lot of work and when consumers can’t keep up with producers. The RabbitMQ server can then be used to help with scaling up those frequently used parts.

Alternatives to RabbitMQ

RabbitMQ is just one of several message broker systems that make use of message queues, but there are plenty of other RabbitMQ alternatives that are viable options. For example, Apache Kafka and ActiveMQ are similar tools to RabbitMQ, and even Redis provides message queueing functionality.

But whichever message broker system you choose for your projects, you'll need a powerful and scalable platform to host it on. Visit the Fasthosts website for more information on how our flexible Cloud Servers can help your business.

And for further information on web hosting, and other tips and tricks to help you navigate the internet safely, you can head over to our blog.