Amazon SQS

Sourabhmiraje
5 min readMar 7, 2021

Many times when you buy something on e-commerce website and as soon as you order gets placed successfully you receive a message about your order. even if you are offline it wait for you to come online and as soon as you come online you get the message.

but have you ever wondered who is sending this kind of message to you, how they are waiting for you to come online.

So, Hey guys in this article we are going to know how this kind of message delivering service works. We are going to see What is Amazon SQS and how it is useful.

So let’s start…

What is Amazon SQS?

Amazon Simple Queue Service (SQS) is a managed message queue service offered by Amazon Web Services (AWS). It provides an HTTP API over which applications can submit items into and read items out of a queue. The queue itself is fully managed by AWS, which makes SQS an easy solution for passing messages between different parts of software systems that run in the cloud.

How does SQS work?

So lets see what happen when sender device is connected directly with receiver device.

We have a device A and Device B and no one is there in between. suppose A sent some message to B but before message reaching to the B, B device goes down. but according to A message has sent already but B never receives it as it was not up at that time and message is lost.

So this kind of service can creates so much confusion, but how we can overcome this problem ? who will wait for device B to come online and then send the message ?

So here the role of middleware comes in.

So we use one middleware in between A and B. whatever message A want to send to the B it will send to the middleware and from middleware its device B’s responsibility to check for the message for it.

and this middleware is known as the Message Queue server.

The benefits of using SQS :

For Server less developers, using SQS generally provides a wealth of benefits, which you can read about below.

Scalability Your SQS queues scale to the volume of messages you’re writing and reading. You don’t need to scale the queues; all the scaling and performance-at-scale aspects are taken care of by AWS.

Pay for what you use When using SQS, you only get charged for the messages you read and write (see the details in the Pricing section). There aren’t any recurring or base fees.

Ease of setup Since SQS is a managed service, so you don’t need to set up any infrastructure to start using SQS. You can simply use the API to read and write messages, or use the SQS <-> Lambda integration.

Options for Standard and FIFO queues When creating an SQS queue, you can choose between a standard queue and a FIFO queue out of the box. Both of these queue types can be useful for different purposes.

Automatic deduplication for FIFO queues Deduplication is important when using queues, and for FIFO queues SQS will do the work to remove any duplicate messages for you. This makes FIFO queues on SQS suitable for tasks where it’s critical to have each task done exactly once.

A separate queue for unprocessed messages This feature of SQS is useful for debugging. All messages that couldn’t be processed are sent into a “dead-letter” queue where you can inspect them. This queue has all the usual integrations enabled, so you can subscribe to it using an AWS Lambda event, for example, to send a notification when an item can’t be processed.

Disadvantages of using SQS

Using SQS can also create challenges for Serverless developers, as described hereafter.

High cost at scale With pay per use pricing, if the number of messages you send is very high, your SQS bill can be quite significant. Part of SQS pricing is data transfer charges, and those can add up if you send larger messages, or if you process messages from outside the main AWS region in which the queue is located. In some cases, when running at scale with millions of messages processed every day, the cost of using SQS might be higher than the cost of operating your own queue system, even including the overhead to manage your own solution.

Lack of support for broadcast messages With its “exactly once” delivery, SQS doesn’t support a way for multiple entities to retrieve the same message, making SQS not so useful for one-to-many broadcasts.

To address this, in the cases where one-to-many delivery is important, developers can use SQS alongside SNS.

Reduced control over performance When running a message queue system at scale, something you may well end up wanting to do is to fine-tune its performance to suit your needs. With SQS this isn’t an option: the service is fully managed, and you don’t get to look under the hood.

What is SQS used for?

Decoupling microservices. In a microservice architecture, messages represent one of the easiest ways to set up communication between different parts of the system. If your microservices run in AWS, and especially if those are Serverless services, SQS is a great choice for that aspect of the communication.

Sending tasks between different parts of your system. You don’t have to be running a microservices-oriented application to take advantage of SQS. You can also use it in any kind of application that needs to communicate tasks to other systems.

Distributing workloads from a central node to worker nodes. You can frequently find messaging systems in the flows of distributed large workloads like map-reduce operations. For these kinds of operations, it’s essential to be able to maintain a queue of all the tasks that need to be processed, efficiently distribute the tasks between the machines or functions doing the work, and guarantee that every part of the work is only done once.

Scheduling batch jobs. SQS is a great option for scheduling batch jobs for two reasons. First, it maintains a durable queue of all the scheduled jobs, which means you don’t need to keep track of the job status — you can rely on SQS to pass the jobs through and to handle any retries, should an execution fail and your batch system returns the message to the queue. Second, it integrates with AWS Lambda; if you’re using AWS Lambda to process the batch jobs, SQS automatically launches your Lambda functions once the data is available for them to process.

So thus its very important to use Message queue in order to guarantee the message delivery to the target device. thus there are lots of other use cases as well.

Do let me know about the article in the comment. any suggestion are appreciated.

LinkedIn profile…

--

--