Message Queuing vs. Load Balancing. I don't truly understand the difference [closed]

Help me to understand something. I've looked at several enterprise application architectures, and I've noticed that several of them use a Message Queue service, like ActiveMQ or RabbitMQ. I have surface-level knowledge of what message queuing servers do, but I don't really understand why I would choose to build an application infrastructure that uses one, versus a standard load balancing technology, like HAProxy, or the like.

What is the real difference between the two? Both seem to route traffic and/or messages to nodes that subscribe to the queue or pool. Are there pros/cons for each of these?


Solution 1:

As stated by Michael, these two are vastly different in function and capability.

Message Queuing Systems

The primary function of Message Queueing services is to permit asynchronous communication between different parts of an application. MQ servers typically allow one to configure an arbitrary number of routing rules, queues, etc. to which messages are published by parts of an application and subscribed to by other parts of the application.

Take, for instance, a video transcoding application. The basic functions needed are:

  1. user uploads a video file
  2. system transcodes video into a different format
  3. system makes transcoded video available for download

After step 1 completes, do you really want the user's browser session to hang for 45 minutes while the transcoding takes place? Nope, don't think so. So instead of performing the transcoding synchronously, you dump a message into a message queue that there is work to do. Then this message is picked up by the back-end processing part of your app, which performs the transcoding and then when complete, publishes an "I'm done!" message to a different queue, which triggers a third part of your application to email the user that their job is complete.

In addition to separating disparate parts of your application, MQ systems permit jobs to, well, queue. Say your hardware only allows you to process one video every 30 minutes, but during peak load, your users upload more than that. Using an MQ allows those jobs to queue up gracefully and be handled in sequence as the back-end is able to do so.

Load Balancing Systems

The primary function of load balancing is to field incoming requests from clients and distribute those requests one or more back-end application servers.

Conclusion

To put things another way, message queuing services focus on asynchronous communication between disparate application parts, while load balancing services focus on synchronous communication between clients and one or more of a pool of back-end servers.