Communication Models
Explore the communication models for asynchronous communication.
Communication models
Message queues and event logs can enable two different forms of communication, known as point-to-point and publish-subscribe.
The point-to-point model
The point-to-point model is used when we need to connect only two applications.
Note: Point-to-point refers to the number of applications, not the actual servers. Every application on each side might consist of multiple servers that produce and consume messages concurrently.
The publish-subscribe model
The publish-subscribe model is used when more than one application might be interested in the messages sent by a single application.
For example, suppose a customer made an order might be needed by an application sending recommendations for similar products, an application that sends the associated invoices, and an application that calculates loyalty points for the customer.
Using a publish-subscribe model, the application handling the order can send a message about this order to all the applications that need to know about it, sometimes without even knowing which these applications are.
Implementing point-to-point and publish-subscribe models
These two models of communication are implemented slightly differently depending on whether an event log or a message queue is used. This difference is due to the fact that the consumption of messages behaves differently in each system:
Using message queue
Point-to-point communication is pretty straightforward when using a message queue. Both applications are connected to a single queue, where messages are produced and consumed.
In the publish-subscribe model, the producer application can create and manage one queue, and every consumer application can create its own queue. There also needs to be a background process that receives messages from the producer’s queue and forwards them to the consumers’ queues.
Note: Some systems might provide facilities that provide this functionality out of the box. For example, this is achieved in ActiveMQ via a bridge and in Amazon SQS via a separate AWS service, called Amazon Simple Notification Service (SNS).
Using event log
When using an event log, both models of communication can be implemented in the same way. The producer application writes messages to the log, and multiple consumer applications can be consumed from the log concurrently the same messages maintaining independent offsets.
This difference in implementing these models using the message queue and the event log is shown in the following illustration:
Get hands-on with 1400+ tech skills courses.