This is a continuation of a series of articles in which I briefly cover the main points of a specific topic in system architecture design. The previous article can be read here and the full guide you can find on my github.

Message queues are a form of asynchronous service-to-service communication. They are important in enhancing a system's scalability, reliability, and maintainability.

The list of key features:

  1. Asynchronous Communication: Allows different parts of a system to communicate without needing to respond immediately, leading to more efficient use of resources.
  2. Decoupling of Services: Enables services to operate independently, reducing the system's complexity and enhancing maintainability and scalability.
  3. Load Balancing: Distributes messages evenly across different services or workers, helping to manage workload and improve system performance.
  4. Order Preservation: Some message queues can ensure that messages are processed in the order they are sent, which is crucial for specific applications.
  5. Scalability: Facilitates easy scaling of applications by adding more consumers or resources to handle increased message flow.
  6. Rate Limiting and Throttling: Controls the rate at which messages are processed, which is important for managing resources and preventing system overloads.
  7. Fan-out Capability: Message queues often include a fan-out mechanism, which allows a single message to be delivered to multiple consumers or services simultaneously.
  8. Data Persistence: Offers the ability to store messages on disk or in memory until they are successfully processed, ensuring data is not lost in case of system failures.
  9. Message Filtering and Routing: Allows messages to be routed or filtered based on specific criteria or content, enabling more targeted and efficient processing.

Components

In the context of message queues, the concepts of producers, consumers, and messages form the core of how these systems operate.

  1. Producer is an application or service responsible for creating and sending messages to the message queue. It does not need to be aware of who will process the message or when it will be processed.
  2. Consumer is an application or service that retrieves and processes messages from the queue. It acts on the data sent by producers.
  3. Messages are the data packets sent from producers to consumers. They can vary in size and format, ranging from simple text strings to complex data structures like JSON or XML.
  4. Message Broker is a middleware tool that facilitates communication between different applications or services by receiving messages from a sender and routing them to the appropriate receiver. It typically provides features like message queuing, routing, transformation, and delivery assurance.

Messaging Models

Globally, there are two types of messaging: Point-to-Point and Publish-Subscribe.

Point-to-Point

Publish-Subscribe

However, some messaging protocols and the brokers that support them use an additional Exchange component for routing. In that case, messages are published to an exchange in the broker first. The Exchange, acting as the routing agent, forwards these messages to the appropriate queue using its routing rules.

The following exchange operating modes are distinguished:

Direct exchange

Topic exchange

Fanout exchange

Header exchange

Dead letter

Protocols

Message brokers are responsible for delivering messages from producers to consumers. They use specific protocols that define the rules and formats for messaging.

The most popular protocols in this domain are:

AMQP (Advanced Message Queuing Protocol)

A binary protocol designed for message-oriented middleware with robustness, security, and interoperability. Ideal for complex and reliable enterprise messaging systems.

MQTT (Message Queuing Telemetry Transport)

A lightweight, publish-subscribe network protocol optimized for high-latency or unreliable networks, ideal for IoT scenarios.

JMS (Java Message Service)

A Java-based messaging standard offers interfaces for point-to-point and publish-subscribe messaging patterns in Java applications.

STOMP (Simple Text Oriented Messaging Protocol)

A simple, text-based protocol that is easy to implement, suitable for scenarios where advanced messaging features are not a priority.

Kafka Protocol

Associated with Apache Kafka, a distributed streaming platform capable of handling high-throughput data streams.

ZMTP (ZeroMQ Message Transport Protocol)

The underlying protocol for ZeroMQ is a high-performance asynchronous messaging library for building scalable, distributed applications.

Brokers

ActiveMQ

RabbitMQ

Kafka

ZeroMQ

Written in

Java

Erlang

Scala

C++

Cross-platform

yes

yes

yes

yes

Opensource

yes

yes

yes

yes

Multiple languages

yes

yes

yes

yes

Protocols

AMQP, AUTO, MQTT, OpenWire, REST, RSS and Atom, Stomp, WSIF, WS Notification, XMPP, WebSocket

AMQP, STOMP, MQTT, HTTP

Binary over TCP

TCP, UDP, inproc, PGM, IPC, TIPC, NORM, SOCKS5

QoS

at-least-once at-most-once

at-least-once at-most-once

at-least-once at-most-once exactly-once

at-least-once at-most-once

Message patterns

Queue, Pub-Sub

Queue, Pub-Sub, RPC

Pub-Sub

Request-Reply, Pub-Sub, Push-Pull, Dealer and Router, Pair, Exclusive Pair, etc

Persistence

Disk, DB

Mem, Disk

Disk

-

ActiveMQ

Apache ActiveMQ is an open-source, multi-protocol, Java-based message broker designed by Apache. It's known for its robustness and flexibility, supporting various messaging protocols and clients, making it a versatile choice for integrating disparate systems.

Architecture Features:

Scenarios for Use:

Pros:

Cons:

RabbitMQ

RabbitMQ is an open-source message broker software known as a message-oriented middleware. It's written in Erlang and is built on the Open Telecom Platform framework for clustering and failover. RabbitMQ is widely used for handling asynchronous processing, enabling communication between distributed systems through various messaging protocols, primarily AMQP (Advanced Message Queuing Protocol).

Architecture Features:

Scenarios for Use:

Pros:

Cons:

Kafka

Apache Kafka is an open-source stream-processing software platform developed by LinkedIn and later donated to the Apache Software Foundation. It's designed to handle high volumes of data and enable real-time data processing. Kafka is a distributed, partitioned, and replicated commit log service.

Architecture Features:

Scenarios for Use:

Pros:

Cons:

ZeroMQ

ZeroMQ (ØMQ, 0MQ, or ZMQ) is a high-performance asynchronous messaging library for distributed or concurrent applications. It's not a message broker but a library that abstracts socket communication into a message-oriented middleware, making it easier to implement complex communication patterns in a scalable way. Developed in C++, ZeroMQ can be used in various programming languages through bindings.

Architecture Features:

Scenarios for Use:

Pros:

Cons: