Backend Development 12 min read

Understanding Message Middleware: Core Concepts, Patterns, and Protocols

This article explains what message middleware (or message queues) is, the problems it solves such as decoupling, ordering, routing, asynchronous processing and peak shaving, and details its components, patterns, advantages, common protocols, and popular implementations.

Architecture & Thinking
Architecture & Thinking
Architecture & Thinking
Understanding Message Middleware: Core Concepts, Patterns, and Protocols

1 About Message Middleware

1.1 What is Message Middleware?

Message middleware refers to the foundational software that handles sending and receiving messages in distributed systems. It is also called a Message Queue (MQ) and provides an efficient, reliable message delivery mechanism for platform‑agnostic data exchange, enabling integration of distributed systems. In short, it is commonly used in Internet scenarios for message routing, publish/subscribe, asynchronous processing, and relieving system pressure.

1.2 What pain points does it solve?

1. Decoupling: System A can delegate tasks to System B without a direct relationship by placing messages in a queue that B subscribes to.

This is typical, e.g., an order system (A) and an inventory system (B) use a queue to reduce inventory after an order. If multiple systems need to handle the same event, the advantage becomes even clearer.

2. Ordering: FIFO principle ensures first‑in‑first‑out processing, useful when requests arrive while a long‑running task is in progress.

Business scenarios requiring strict order and consistency, such as multiple entry points using the same bank card, need ordered processing to avoid data inconsistency.

3. Message Routing: Rules direct messages from one queue to other queues.

Different colored requests are sent to appropriate services, achieving traffic segmentation by business.

4. Asynchronous Processing: A task with steps A, B, C can execute A synchronously and let B, C run asynchronously, improving throughput.

Login example: A handles authentication, B records logs, C stores user info and token; A returns to the homepage while B and C process in the background.

5. Peak Shaving: Non‑critical steps can be offloaded to the queue during peak periods.

2 Message Middleware Execution Principles

2.1 Components

Broker: Message server providing core services. Producer: Message producer that sends messages to the broker. Consumer: Message consumer that retrieves messages from the broker and processes them. Topic: In publish/subscribe mode, a unified destination for messages from multiple producers, broadcast to subscribers. Queue: In point‑to‑point mode, a specific queue for a producer and consumer. Message: The message body, a data packet encoded according to a communication protocol.

Example with Kafka: Kafka uses Zookeeper for cluster configuration and leader election; producers push messages to brokers, consumers pull messages from brokers.

producer – produces messages

consumer – consumes messages

broker – message server handling core processing

zookeeper – registers and discovers producers and consumers

2.2 Middleware Patterns

2.2.1 Point‑to‑Point (PTP)

Uses a queue as the transport. Producers send messages to a queue; consumers retrieve and consume them. Once consumed, the message disappears, and only one consumer can process a given message. Multiple consumers can exist, but each message is delivered to only one.

Features:

Each message has a single consumer.

Sender and receiver are temporally decoupled.

Receiver must acknowledge successful receipt.

FIFO guarantees order.

2.2.2 Publish/Subscribe (Pub/Sub)

Uses a topic as the transport. Producers publish to a topic, and multiple consumers subscribe and receive the same message. Unlike PTP, a message can be consumed by many subscribers.

Features:

One message can have multiple consumers.

Publishers and subscribers have temporal dependency.

Subscribers must create a subscription before consuming.

Subscribers must stay running to receive messages.

2.3 Advantages

System decoupling, improved response time by offloading non‑critical tasks to queues, and support for big‑data processing architectures.

2.4 Common Protocols

AMQP, MQTT, STOMP, XMPP, and other custom TCP/IP‑based protocols.

2.4.1 AMQP

Advanced Message Queuing Protocol – an open standard for message‑oriented middleware, offering reliability and security.

2.4.2 MQTT

Message Queuing Telemetry Transport – lightweight protocol suitable for IoT, low bandwidth, and embedded systems.

2.4.3 STOMP

Streaming Text Oriented Messaging Protocol – simple text protocol for message‑oriented middleware.

2.4.4 XMPP

Extensible Messaging and Presence Protocol – XML‑based, used for instant messaging and near‑real‑time operations, highly extensible but bandwidth‑heavy.

2.5 Popular Middleware

Common solutions include RabbitMQ, RocketMQ, Kafka, etc., with detailed comparisons and selection guidance provided elsewhere.

distributed systemsmiddlewareprotocolsMessage Queueasynchronous processingPub/Sub
Architecture & Thinking
Written by

Architecture & Thinking

🍭 Frontline tech director and chief architect at top-tier companies 🥝 Years of deep experience in internet, e‑commerce, social, and finance sectors 🌾 Committed to publishing high‑quality articles covering core technologies of leading internet firms, application architecture, and AI breakthroughs.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.