SQS Essentials:
SQS provides the ability to have hosted/highly available queues that can be used for messages being sent between severs.
This allows for the creation of distributed/decoupled application components.
SQS is used to create decoupled application environments.
Messages between severs are retrieved through polling.
Two types of polling
- Long Polling (1-20 seconds):
- Allows the SQS service to wait until a message is available in a queue before sending a response, and will return all messages from all SQS service.
- Long polling reduces API requests (over using short polling).
Short Polling:
SQS samples a subset of servers and returns messages from just those servers.
Will not return all possible messages in a poll.
Increases API requests (over long polling), which increases costs.
Other important SQS facts:
- Each message can contain up to 256KB of text (in any format).
- Amazon SQS offer two different types of queues:
- Standard Queue: Guarantees delivery of each message at least once BUT DOES NOT guarantee the order (best effort) in which they are delivered to the queue.
- First-in-first-out (FIFO) Queue: Designed for applications where the order of operations and events are critical, or where duplicates can't be tolerated.
- SQS is also highly available and redundant - means AWS will back up and replicate the messages across multiple AZs within a region.
SQS Workflow
- Generally a "worker" instance will "poll" a queue to retrieve waiting messages for processing.
- Auto Scaling can be applied based off of queue size so that if a component of your application has an increase in demand, the number of worker instances can increase.
Using SQS to Build Decoupled Application Architectures:
Decoupled Architecture:
- Tightly Coupled System:
- A system architecture of components that are not just linked together but are also dependent upon each other.
- if one component fails all components fail.
- Loosely Coupled/Decoupled Systems:
- Multiple components that can process information without being connected.
- Components are not connected - if one fails the rest of the system can continue processing (fault tolerant/highly available).
- AWS Services that are used for distributed/decoupled system architectures:
- SWF (Simple Work Flow Service)
- SQS (Simple Queue Service)