Byte Ebi's Logo

Byte Ebi 🍀

A Bit everyday A Byte every week

[AWS Cloud Fundamental Notes] SQS

Introduction to SQS and its usage and operational mechanism

Ray

Amazon Simple Queue Service (SQS) serves as a task buffer, allowing tasks that do not require immediate processing to be placed in the queue for storage.
When the system has spare resources, it processes these tasks, which helps decouple applications.

graph LR;
MessageGeneration-->MessageStorage-->MessageConsumption;

Amazon SQS does not automatically delete messages, and it does not guarantee that consumers will actually receive messages.

Glossary

Producer

Responsible for converting user requests into messages and sending them to the queue.

Message

Task information transmitted between services.

Default maximum size is 256KB.
For large files, it is recommended to store them in S3 and record the file location in the message.

Queue

A message queue for storing tasks to be processed, provided for consumers to access.

Messages placed in the queue have a retention period. Once the time is up, SQS will delete them.
The default retention period is 4 days, with a range of 60 seconds to 1209600 seconds (14 days).

Consumer

Takes messages from the queue and processes tasks according to their content.

Types

Amazon SQS Queue Types

Consumers process messages in the queue in two ways:

  1. Standard: Scattered without considering order.
  2. FIFO: First in, first out.

Message Visibility

Prevents duplicate task processing and sets timeout times.

Invisibility

When the first consumer pulls a message, the message enters an invisible state.
This temporarily hides the message from other consumers to avoid duplicate retrieval.
After processing a message, it is important to send a Delete Message request to prevent duplicate processing.

Visibility Timeout

When one consumer receives a message, other consumers will not be able to see the message for a period of time.
If the task is not completed within the timeout period, other consumers will be able to see and process the message after the timeout. This means that a message may be sent multiple times.

The visibility timeout defaults to 30 seconds, with a minimum of 0 seconds and a maximum of 12 hours.

Polling Frequency

Amazon SQS Short and Long Polling

  • Short polling: Frequent access, default scenario.
  • Long polling: Lower access frequency, lower cost.

Recent Posts

Categories

Tags