tldr;
An Event Hub is a cloud computing architecture designed to collect, store, and process large volumes of event data. Azure Queue is a cloud computing service aimed at providing scalable messaging solutions. Queues are generally used when there is no need to preserve the order of the events/messages and event hubs are used when there is a need to preserve the relative order of events/messages.
Message Storage Order
Let’s take another example, say John has 100 bucks in his bank account and then he follows the below steps
Withdraws 200 bucks
Deposits 100 bucks
For ease sake, we can do (100+100) -200 i.e. 0 bucks finally in the account and we can also do (100-200) i.e. 200 cannot be debited from the account with a balance of 100 bucks. Answer depends on the order of execution. This is the case with Queues. In queues, the message order can be jumbled and the relative order of the messages can change depending on the computation time of the message.
If you look at the steps, it is clear that John shouldn’t be allowed to withdraw 200 bucks in the first step as his balance is lesser than this. This is a perfect use case for using Event Hubs. Event hubs are used when the ordering of the messages matter and any mishaps in the ordering is not acceptable
Message Passing and Receiving Mechanism
The message passing/listening mechanism that queues use is called as polling. In polling the listener function keeps on asking the queue whether there is a new message or not. This increases the latency and also is costly. An advantage of using queue is that a message is only removed from the queue when the listener function asks for it which ensures the availability of the listener function.
In case of an event hub, a pub/sub model is what it uses to pass the messages. In thus type of communication event hub send the newly entered message to all it’s subscribers without them asking. This is done using a unidirectional channel. It is relatively cheaper as compared to polling and also it ensures real time data.
Fig 1.2 and 1.3 shows the message transfer mechanism in case of queues and event hubs respectively. How the relative positioning of is and there makes such a huge difference.
Message Processing Mechanism
Both queues and event hubs follow a batch processing mechanism with the batch size depending on the computing capacity of the listener function.
But, there is and always will be a but. In case of queues, a task is started processing as soon as it finds a thread. Where as in case of event hubs, a task won’t be taken for execution until and unless the task before it is completed because of the nature of event hubs to keep the order of the messages consistent.
Conclusion
Azure queues and azure event hubs are two different service for a reason. They both have different use cases to meet. There is no one size fits all and every pros has it’s own cons. So do your own thorough research before choosing between queues and event hubs.
PS: I did mine before choosing between them in my project.