With modern cloud architecture applications are now decoupled into smaller, independent building blocks that are easier to develop, deploy and maintain, but the applications should also deal with connecting system components for the seamless flow of information among these components.
The message queue is a powerful way of combining application components. Message queue not only simplifies coding of decoupled applications, it also improves performance, reliability and scalability.
Message queues allowÂ different parts of a system to communicate (send and receive messages) and process operations asynchronously by providing a lightweight buffer to store messages, and endpoints temporarily. A message is sent to the queue by a component called a producer and it is stored in the queue until another component called a consumer retrieves the message and processes it.
This messaging pattern is often called one-to-one, or point-to-point, communications because many producers and consumers can use the queue, but each message is processed only once, by a single consumer.
What is Amazon SQS?
Amazon Simple Queue Service (SQS) is a secure, durable, fully managed and available hosted queue that offers to integrate and decouple distributed software systems and components by allowing transmitting data between distributed application components. SQS eliminates the complexity and burden associated with managing and operating message-oriented middleware and empowers developers to focus on differentiating work. Using SQS, messages can be sent, stored, and received between software components at any volume, without losing messages or requiring other services to be available.
Use cases-Application integration, Allocation of tasks to multiple worker nodes, Decouple live user requests from intensive background work, Decoupling microservices, Batch messages for future processing
An Amazon SQS message has three basic states:
- Sent to a queue by a producer
- Received from the queue by a consumer and
- Deleted from the queue.
Between state 1 and state 2, message is stored in queue and available for use while in between in state 2 and state 3, message is in flight and not available for use for the other consumers.
When a consumer receives and processes a message from a queue, Amazon SQS doesnâ€™t delete the message automatically because SQS is a part of a distributed system, thereâ€™s no guarantee that the consumer receives the message (for example, due to a connectivity issue, or due to an issue in the consumer application). This need to be done by the event handler function at the consumerâ€™s side after receiving and processing message. If the message is not deleted during the defined period (called visibility timeout), the message becomes again visible for the other consumers
Benefits of Amazon SQS
- Administrative overhead– It eliminates administrative overhead and AWS SQS will manage all the operations that are currently underway and infrastructure which is required to scale and run message queuing. There is no requirement to install and configure messaging software as well as maintenance of infrastructure.
- Security-Amazon SQS can be used to exchange sensitive data between applications using server-side secret writing (SSE) that offers to transmit sensitive data by protecting the contents of messages in queues using keys managed in AWS Key Management Service (AWS KMS). It also allows to control who can send messages to and receive messages from an Amazon SQS queue.
- Durabilityâ€“ To ensure the safety of your messages, Amazon SQS stores them on multiple servers though only for a limited. (Max.- 14 days)
- Availabilityâ€“ Amazon SQS stores data on different servers and usesÂ redundant infrastructureÂ to provide highly-concurrent access to messages.
- Scalabilityâ€“ Amazon SQS allows to dynamically increase read throughput by scaling the number of tasks reading from a queue and requires no pre-provisioning or scale-out of AWS resources. Â It easily scales to handle a large volume of messages, without user intervention. SQS buffers requests to transparently handle increase in load.
- ReliabilityÂ â€“ It locks your messages during processing so that a message is consumed only once by a single consumer. It also enables multiple producers can send and multiple consumers can receive messages at the same time.
- CustomizationÂ â€“ Amazon SQS allows customization in multiple ways, from modifying the queue attributes to integrate with other AWS services in an order to build scalable and more flexible applications. It is compatible with other Amazon Web Services, includingÂ Amazon Relational Database Service,Â Amazon Elastic Compute CloudÂ andÂ Amazon Simple Storage Service.
Amazon SQS queues
Amazon SQS offers following two types of queues:
1. Standard Queue
- Availability in regions-All regions.
- Unlimited Throughputâ€“Supports a nearly unlimited number of transactions per second (TPS) per action.
- At-Least-Once Deliveryâ€“ It guarantees a message to be delivered at least once. SQS stores copies of messages on multiple servers for high availability and redundancy. On rare occasions, the copy of the message isnâ€™t deleted on any of the servers might be due to unavailability of that server during deletion. This may result in the message delivered more than once.
- Use Case– It can be used in any scenarios, as long as the application can handle messages which might be out of order or duplicate
- Best-Effort Orderingâ€“ A standard queue makes a best effort to preserve the order of messages, but occasionally, messages might be delivered in an order different from which they were sent
2. FIFO Queue
- Availability in regions– US East (Ohio), Asia Pacific (Tokyo), US East (N. Virginia), US West (N. California), Asia Pacific (Seoul), Asia Pacific (Singapore), Asia Pacific (Sydney), Asia Pacific (Mumbai), Canada (Central), US West (Oregon), EU (Frankfurt), EU (Ireland), EU (London), EU (Paris), and South America (SÃ£o Paulo) regions.
- The name must end with theÂ .fifo
- High Throughputâ€“FIFO queues support up to 3,000 messages per second withÂ batching. FIFO queues support up to 300 messages per second, per action (SendMessage,Â ReceiveMessage, orÂ DeleteMessage) without batching.
- Exactly-Once Processingâ€“ A message is delivered once and remains available until a consumer process and deletes it. Duplicates aren’t introduced into the queue.
- Use Case-Designed to enhance messaging between applications when the order of operations and events is critical,Â or where duplicates canâ€™t be permitted.
- First-In-First-Out Deliveryâ€“ The order of the messages in which messages are sent and received is maintained.
Message queue plays an important role in distributed systemÂ to for the communication and coordination among components. As you saw Amazon provide one such service called Amazon SQS which is intended to provide a highly scalable hosted message queue. Apart from benefits it provides like scalability, security, etc, it also provides two types of queue well-suited for different use cases.