Event Driven Apps | Communication Basics
Event Driven App as the name suggests are entirely dependent on Events. How the events are delivered or how Applications Communicate has to be thought through. Adopting proper communication technique can make your Application Reliable and Scalable.
Did you choose right Event Delivery Mechanism??
Send Mails vs Distributing Flyers
Applications need to notify each other of their status; notifying each other is not too different from persons notifying one another.
Notify someone Known
When a Person needs to notify another person, and person knows the other person’s address, Mail to the receiving person is sent.
This scenario is the basic premise of using Queues for application integration needs. When source application only wants to notify one Application for any event; then it should use Queue for sending the notifications. Expectation here is that Source Application is aware of the receiving Application’s address.
Notification sent to a Queue will be available, even if the Target Application is down when notification was sent. Target Application will get the Message whenever it comes online.*
— Mail is available to be read, even when the recipient is not in front of their mailbox when mail arrives.
If multiple applications decide to read from same Queue Address, only one of the application will get the message.
Mails are deleted after one takes it from the mailbox.
When a person needs to notify many Strangers, quickest way is to distribute Flyers.
This scenario is the basic Premise of Messages using Topics. When Source Application does not know about Applications those may be interested in getting the message, Source Application just send the message to a Topic.
Interested Applications, can get the messages from the Topic.
Flexibility is the key here; messages can be delivered to complete strangers (unknown applications). Source Application doesn’t know about who will / will not get the messages.
— Sender does not know who will take the Flyers. Its completely on the receiver’s interest.
If an application is not online , when message was published; application may never get the message ever.
— Person needs to be available when Flyers were being distributed, or else person will never get the Flyer; ever.
Choose Queue, when application is aware of who to send messages/notifications to (one-on-one); and the receiver need not be available when the message is published.
Choose Topic when Application is not aware of how many and which applications would decide to receive the message. The receiver has to be available when message is published, or else the receiver may never get the message.
Whatever I just mentioned above are the basic principles. You should choose your messaging principles based on these basic Premise.
I will share exceptions/ more details in following blogs. If you have any questions/ feel free to write.