What if you have a service having heavyweight processing requests? Or maybe it has a very spiky workload? There could be multiple ways of handling that. And one of those could be using a message queue. So here in this blog, I’ll be summarizing the message queue for you. I will be covering what and why of it today and in the next blog you get to learn about the Simple Queue Service provided by AWS. Let’s begin!
What is Message Queue?
In the modern world, we have moved to microservices and serverless architectures. Here, the services are decoupled into smaller independent blocks making it easy to develop, deploy and maintain. Message queues provide communication and coordination for these distributed applications.
A message queue stores the messages temporarily until they are deleted. It also has the information regarding the endpoint so any service can connect to the queue. A message can be a request, error message or anything else. There is a concept of sender and receiver when we talk about queues. A sender sends the message to the queue and a receiver retrieves the message from the queue asynchronously.
Generally, while working with message queues, one service puts messages in the queue and the messages stay there until they are deleted. Then the service that processes those messages retrieves them from the queue and after processing, delete the messages from the queue. Many queues have a retention period. The retention period is the time till when the messages are stored in the queue and deleted after that.
Benefits of Message Queue
Messages can safely wait till the time the receiving application is ready to process them.
Consider, you have a microservice that gets a request which will take longer for processing(a heavyweight process). Practically you can’t keep waiting for the processing of the request. You can’t keep other requests waiting and make your application slow. Even if requests are asynchronous you can’t keep your client waiting or load the service with so many messages which can eventually consume a lot of resources. Here come queues to the rescue. Just send your requests as messages to the queue and fetch them later on according to the processing capability of your service.
Another scenario, where a microservice send requests to another microservice. But what if the other microservice is not ready at that time to process those requests. Queues make it convenient for services to process requests at their ease and availability. Just fetch the message from the queue and process it.
Reliable Message Delivery
As messages are stored in queues, they make sure that no messages are lost while sending to an application. And also will only be sent to the recipient. This makes message delivery reliable.
Making Service More Resilient
As messages are available in the queue and no message is lost, so even if one application stalls or one component fails, other components can still interact with the queue and continue the work.
So this was a summary of the message queue, just some key points to give you a start. In the next blog, I’ll start with AWS SQS i.e. Simple Queue Service. See you there!