Asynchronous messaging and event passing - Implementing Microservices on AWS

Asynchronous messaging and event passing

Asynchronous messaging allows services to communicate by sending and receiving messages via a queue. This enables services to remain loosely coupled and promote service discovery.

Messaging can be defined of the following three types:

  • Message Queues: A message queue acts as a buffer that decouples senders (producers) and receivers (consumers) of messages. Producers enqueue messages into the queue, and consumers dequeue and process them. This pattern is useful for asynchronous communication, load leveling, and handling bursts of traffic.

  • Publish-Subscribe: In the publish-subscribe pattern, a message is published to a topic, and multiple interested subscribers receive the message. This pattern enables broadcasting events or messages to multiple consumers asynchronously.

  • Event-Driven Messaging: Event-driven messaging involves capturing and reacting to events that occur in the system. Events are published to a message broker, and interested services subscribe to specific event types. This pattern enables loose coupling and allows services to react to events without direct dependencies.

To implement each of these message types, AWS offers various managed services such as Amazon SQS, Amazon SNS, Amazon EventBridge, Amazon MQ, and Amazon MSK. These services have unique features tailored to specific needs:

  • Amazon Simple Queue Service (Amazon SQS) and Amazon Simple Notification Service (Amazon SNS): As you can see in Figure 8, these two services complement each other, with Amazon SQS providing a space for storing messages and Amazon SNS enabling delivery of messages to multiple subscribers. They are effective when the same message needs to be delivered to multiple destinations.

    
            Diagram showing Message bus pattern on AWS

    Figure 8: Message bus pattern on AWS

  • Amazon EventBridge: a serverless service that uses events to connect application components together, making it easier for you to build scalable event-driven applications. Use it to route events from sources such as home-grown applications, AWS services, and third- party software to consumer applications across your organization. EventBridge provides a simple and consistent way to ingest, filter, transform, and deliver events so you can build new applications quickly. EventBridge event buses are well suited for many-to-many routing of events between event-driven services.

  • Amazon MQ: a good choice if you have a pre-existing messaging system that uses standard protocols like JMS, AMQP, etc. This managed service provides a replacement for your system without disrupting operations.

  • Amazon MSK (Managed Kafka): a messaging system for storing and reading messages, useful for cases where messages need to be processed multiple times. It also supports real-time message streaming.

  • Amazon Kinesis: real-time processing and analyzing of streaming data. This allows for the development of real-time applications and provides seamless integration with the AWS ecosystem.

Remember, the best service for you depends on your specific needs, so it's important to understand what each one offers and how they align with your requirements.