Introduction to Amazon SQS
The following article provides an outline on Amazon SQS. In a software architecture queues are a powerful way of combining all together. Queues useful when the throughput of the different systems is unequal, they allow the system to communicate asynchronously. Amazon offers the same services that can be used as queues i.e, Amazon SQS (Simple Queue Service).
Amazon SQS is a queueing service offered by Amazon Web Services. It’s similar to other services offered by AWS in way of scalability, accessibility and other benefits of AWS cloud services. Amazon SQS is a distributed queue system where one component produces messages which will be consumed by another component in a system and a queue acts as a temporary repository for messages that are waiting for processing.SQS enables components of a system to run independently and communicating through message management.
Messages can be json, bytes, xml or simple text format and can go up to 256kb. Any component can retrieve the stored messages in the AWS queue using SQS Api. The Queue solves the problem when the one component is producing data at very fast but another component can’t process it at that rate, then queue holds the data so that consumers can anytime read and process the data.
The queue acts as a buffer between the component producing and saving data, and the component receives the data for processing. We can use the auto-scaling functionality for queue processing when the messages reach over a certain limit we can configure an autoscaling group that will launch another EC2 instance to process the messages and do the job faster.
How the Queue System Works?
For example, let’s take a scenario: Where we have two systems communicating asynchronously.
System 1 Producer: Produces data or say messages periodically at a very high rate.
System 2 Consumer: Consumes message at its own pace but slower than the producer.
A queue would allow System 1 to produce messages as fast as its own pace, and System 2 would consume messages at its own pace i.e, slower than System 1.
Queues have always played an important role in software architecture for decades. Queues are useful in today’s world where people are adapting microservice architecture, these microservices talk to each other through a way called Application Programming Interface. This made queues more important than ever in today’s trend.
Need and Use of SQS in Real World
Let’s see a scenario of a real-world system where it processes the real-time feed coming from the camera. Its a video processing system whose sole work is to processes the video and get the important data and show in the dashboard. This system can be a face recognition, traffic analyzer or a license plate recognition system.
- The role of the producer would be to read the feed and get the important frames and push them to the queue system.
- The job of consumers would be to take the frames from the queue and do the necessary processing and upload it to the desired location with metadata.
- Here the job seems simple but the producer can push frames at a very high rate but consumers can’t process it at that rate.
- If our consumer breaks down still we won’t lose the job as it will be always available in the queue.
We can see how the queue is playing an integral role in this architecture.
AWS offers two types of queues:
- Standard Queues (default)
- FIFO Queues (First-In-First-Out)
1. Standard Queues
- Standard Queues are the default queues offered by SQS.
- In the standard queue, we can have an unlimited number of transactions per second.
- Messages would be delivered at least once, that’s the sole job of the standard queue and it guarantees that messages would be delivered, but however sometimes we see the redundancy in messages. It doesn’t guarantee that it will deliver only one instance of a message sometimes more than one copy of a message might get delivered. The redundant message would be out of the order.
- Standard queues provide best-efforts in order that the messages would be in order. But it’s not guaranteed that it will happen sometimes a message can come out of order.
2. FIFO Queues (First-In-First-Out)
- The FIFO Queue is like advancement over standard queues.
- The order of the messages is maintained in FIFO i.e, you will receive the message in the same order in which you have sent.
- There is no problem with the redundancy of a message. Only one message will be available to consume and it will remain in the queue till it’s consumed by the consumer.
- FIFO guarantees of ordering, uniqueness of messages (no redundancy).
- It allows grouping multiple ordered messages within a single Queue.
- FIFO has a limited number of transactions per second i.e, 300, unlike standard queues where you can have any number of transactions.
SQS Visibility Timeout
- This is the amount of time the message will be invisible in the SQS after a component has read and performed the job.
- If processing is done before the timeout expires, the message then will be deleted from the Queue.
- If the job is not done then the message will be visible again and some other component can take up the job and the same message would be introduced twice.
- The default visibility is 30 seconds.
- Visibility timeout can be increased up to 12 hours.
Advantages of Amazon SQS
- Automatic Scaling: In a case where the volume increases AWS will take care of the scaling and your job will be performed at the same pace.
- Infinite Scaling: Although there is some kind of limit yet AWS claims that it can support any level of messages in the queue.
- Server-Side Encryption: Messages can be secured using AWS SSE( server-side encryption).
Conclusion – Amazon SQS
Consumer and produces is not a new world problem it was there from the beginning of a complex system. There can be numerous cases where we need a queue to handle the incoming traffic and we don’t want to lose any of the data. Even in the real world system where people stand in a queue to get tickets for the show, or travel is also some kind of queue processing system. With AWS SQS we get the queue management system over the cloud with security, scalability and other AWS features.
This has been a guide to Amazon SQS. Here we discuss the introduction, how the queue system works?SQS visibility timeout, types, and advantages. You may also have a look at the following articles to learn more –