Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Choosing the right asynchronous-messaging infrastructure for the job

July 31, 2020
Bilgin Ibryam
Related topics:
JavaMicroservicesEvent-Driven

Share:

    The term asynchronous means "not occurring at the same time." In the context of distributed systems and messaging, this term implies that request processing will occur at an arbitrary point in time. Asynchronous interactions hold many advantages over synchronous ones, but they also introduce new challenges. In this article, we will focus on specific considerations for choosing the asynchronous-messaging infrastructure for your event-driven systems.

    We will start by looking at the subtle differences between asynchronous interaction styles based on the business value and semantic type of the messages being delivered. Considering these differences helps us to identify messaging patterns, which we can use to determine the kind of messaging system that we need.

    Note: At Red Hat, we love any open source technology, so I use three open source messaging frameworks—Apache Qpid, Apache ActiveMQ Artemis, and Apache Kafka—for my examples. Red Hat AMQ is our flexible messaging platform that includes all three frameworks, making it easy to choose the right tool for your needs.

    The business value of different message types

    Not all messages are created equal. Some are valid and valuable only for a short period and become obsolete later. Some are valuable until they are consumed, regardless of how much time has passed. And some messages are valid and useful for repeated consumption. By considering the validity and value of messages relative to time and consumption rate, we can qualify interaction styles between services into three categories, as described in Figure 1.

    Figure 1: Understanding the business value of different message types.
    Figure 1: Understanding the business value of different message types.
    Figure 1: Understanding the business value of different message types.">

    Let's consider each of these categories.

    Volatile

    Messages in a volatile messaging system are ephemeral, and the value of the message is time-bound: They are valuable now, but soon they will not be. There is no point in storing events that will soon be useless. For this type of event, a volatile messaging system yields the best performance with the lowest possible latency as writing to the disk is skipped. In this type of scenario, the messaging system is aware of consumers and disseminates events to all consumers who are online at the time of publication. When consumers disconnect from the system, the messaging system forgets about them. This type of system is vital for its ability to handle a large number of dynamic clients that have low-latency interaction needs, such as Internet-of-Things (IoT) devices.

    Durable

    This more traditional type of message system knows about registered consumers and stores messages durably until every registered consumer has read them. This type of system works well for scenarios where the consumer might be disconnected when the event is published. The system holds on to the messages until every consumer has re-connected and consumed the relevant events. Once an event has been fully consumed, the message broker discards the messages. The goal is to offer reliable messaging among services with strong ordering and delivery guarantees.

    Replayable

    Here, the messaging system is not aware of consumers or event registrations. It merely stores events and publishes them to a stream for a given period, or until capacity is reached. In this type of system, an existing or new consumer can join at any time, connect and consume events, and even replay the stream from the beginning. Consumers can move back and forth in the stream as required. The driving force for this type of messaging system is scalability, combined with the ability to replay messages.

    Message semantics

    Apart from the technical characteristics of messages, it is essential to distinguish the language that we use—i.e., the semantic aspects—and the intent of the interactions. Some messages are targeted for a specific consumer and demand concrete actions. Some query the latest state of a system without requiring a state change, and some notify the world about a change that has happened in the source system. From a messaging-semantics perspective, there are three message types, as described in Figure 2.

    A graphic showing three message types based on semantics: Command, query, and event.
    message_semantics
    Figure 2: Understanding message types based on semantics.

    Let's consider each of these message types.

    Command

    A command is a request for action that usually leads to a state change on a known target system. Typically, a response indicates that the action was completed, and there might even be a result associated with the response. When a response is expected, commands are typically implemented over synchronous protocols such as HTTP. It is also possible to apply request-and-response or fire-and-forget command styles over asynchronous messaging systems. Command-based asynchronous messages require coupling between the source system and the target system, in the form of command semantics.

    Query

    A query is like a command, but it is a read-only interaction that does not lead to a state change. By nature, a query expects a response. It is common to see synchronous implementations of this message type, but asynchronous and non-blocking implementations over messaging systems are also typical. Even fire-and-forget interactions for long-running operations, where a response is written to a different location, are not unusual.

    Event

    An event is a notification that something has changed. A system sends event notifications to notify other systems of a change in its domain. An event is different from a command in that often the event-emitting system doesn't expect a response. In addition to being asynchronous, event messages are not targeted to a specific recipient, which makes further decoupling possible. Similar to other asynchronous interactions, events are implemented as messages on queues, which are often called streams.

    Note: See Martin Fowler's presentation, "The many meanings of event-driven architecture," for in-depth coverage of the different types of events in a messaging system.

    Choosing a messaging system

    The Law of the instrument approach defined by Abraham Maslow says, "If the only tool you have is a hammer, treat everything as if it were a nail." Following that approach, you could certainly use a classic message broker such as Apache ActiveMQ Artemis to implement the different interaction styles described in this article. The technology is familiar to many, which would make it easy to use from the start. On the other hand, it would be challenging to develop use cases such as replayable messaging with a classic message broker.

    On the other end of the extreme, you could try using something like Apache Kafka for every messaging scenario. Kafka would require a more substantial amount of hardware resources and human effort to manage, but use cases requiring replayable messaging or extreme scalability would be covered.

    While both of the above approaches are fine in some cases, when you have a large number of services with different messaging needs, using the right tool for the right job is a better option. Mapping the previously described messaging patterns is a useful tool for deciding what messaging infrastructure you need. In Figure 3, I have mapped the characteristics of three different types of message broker system to the different messaging scenarios and types of messages we've discussed.

    A chart for comparing messaging systems based business needs and message semantics.
    messaging_infrastructures
    Figure 3: Mapping messaging characteristics to messaging infrastructures.

    Each of the three frameworks in Figure 3 is effective for a different type of messaging scenario and need. As I mentioned at the beginning of this article, Red Hat AMQ packages all three of them—Apache Qpid, Apache ActiveMQ Artemis, and Apache Kafka—so that you can choose the right tool for the right job.

    Conclusion

    There are many aspects to consider when choosing the right event-messaging infrastructure for your needs. I hope that the considerations and the mapping tool presented in this article will help you get one step closer to deciding.

    Last updated: July 28, 2020

    Recent Posts

    • Why Models-as-a-Service architecture is ideal for AI models

    • How to run MicroShift as a container using MINC

    • OpenShift 4.19 brings a unified console for developers and admins

    • 3 steps to secure network segmentation with Ansible and AWS

    • Integrate vLLM inference on macOS/iOS using OpenAI APIs

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue