TechWriterDev
  • Cloud
    • AWS
      • 00_Doubts
      • CloudPractitioner
        • Cloud Computing
        • AWS Global Infrastructure
        • Introduction to AWS EC2
        • Elastic load balancer(ELB)
        • 04_Messaging_Queuing
        • Aditional Computing Service
        • Accessing AWS resources
        • AWS Networking
        • Storage
        • Amazon Database Solutions
        • Monitoring Tools
        • AWS Security
        • Distributed Denial Of Service Attacks
      • DeveloperAssociate
        • References
        • AWS DVA-C02 Services Index
        • Services
          • 00_IAM
            • Identity and Access Management (IAM)
            • Account Protection Mechanisms
            • Access Mechanism of AWS Resources
            • Security Tools
            • Responsibility Model
            • Advanced Concepts
          • 01_EC2
            • Elastic Compute Cloud (EC2)
            • EC2 Volume Types
            • Amazon Machine Image (AMI)
            • AWS charges for IPv4 address
          • 02_SecurityGroups
            • Security Groups
          • 03_Elastic_LoadBalancing
            • Terminology
            • Elastic load balancer
            • Features
            • Basics
          • 04_AutoScaling
            • Auto Scaling
          • 05_RDS
            • Relational Database Service (RDS)
            • Aurora
            • Security
            • RDS Proxy
          • 06_ElastiCache
            • Cache
            • Cache Offerings
          • 07_Route53
            • Basics of DNS
            • Route 53
          • 08_VPC
            • Virtual Private Cloud (VPC)
          • 09_S3
            • Simple Storage Service (S3)
            • S3 Features
            • S3 Encryption
            • S3 Features
            • S3 Bucket Policy and IAM Policy
          • 10_ECS
            • Elastic Container Service (ECS)
            • Elastic Container Registry (ECR)
            • AWS Copilot
          • 11_EKS
            • Elastic Kubernetes Service (EKS)
          • 12_SDK_CLI_Tips
            • Access AWS Resources
          • 13_CloudFront
            • Cloud Front
          • 14_Messaging
            • Simple Queue Service (SQS)
            • Simple Notification Service (SNS)
            • Fan Out Pattern
            • Kinesis
            • Compare and Contrast
          • 15_ElasticBeanStalk
            • Elastic Beanstalk
          • 16_CloudFormation
            • CloudFormation
            • Dynamic References
          • 17_Monitoring
            • AWS Monitoring
            • AWS CloudWatch
            • CloudWatch Alarms
            • Synthetics Canary
            • Amazon EventBridge (formerly CloudWatch Events)
            • X-Ray
            • OpenTelemetry
            • CloudTrail
          • 18_Lambda
            • Lambda
            • Lambda Integrations
            • Configuring Lambda
            • Lambda Layers
          • 19_API_Gateway
            • API Gateway
            • API Gateway Integrations
          • 20_DynamoDB
            • DynamoDB
            • Operations
            • Indexes
            • DynamoDB Accelerator (DAX)
            • DynamoDB Streams
            • Transactions
            • Integrations
          • 21_CICD
            • CICD
            • CodeCommit
            • CodePipeline
            • CodeBuild
            • CodeDeploy
            • CodeArtifact
            • CloudGuru
          • 22_SAM
            • Serverless Application Model (SAM)
          • 23_CDK
            • Cloud Development Kit (CDK)
          • 24_StepFunctions
            • Step Functions
            • Types of step function
          • 25_AppSync
            • AppSync
          • 26_Amplify
            • Amplify
          • 27_STS
            • Security Token Service (STS)
          • 28_DirectoryService
            • Active Directory
          • 29_KMS
            • Encryption
            • KMS API
            • Features
            • Cloud Hardware Security Module (HSM)
          • 30_SSM_Store
            • SSM Parameter Store
          • 31_SecretsManager
            • Secrets Manager
          • 32_Cognito
            • Cognito
      • Questions
        • AWS_Region
        • EC2
        • IAM
  • Database
    • MongoDb
      • Mongo db Basics
      • Mongo DB Atlas
      • Document
      • Import-Export based on Data Format
      • Mongo Shell Commands
      • Query Operators
      • Indexes
      • Upsert
      • MongoDB Aggregation Framework
      • Aggregation Framework Operators
    • PostgreSQL
      • POSTGRE SQL DataTypes
      • About table
      • Constraints
  • Technologies
    • RabbitMQ
      • RabbitMQ Concepts
      • Introduction to Exchanges
      • Introduction to Queues
    • Terraform
      • 00_Introduction
      • Configuration blocks
      • Commands
      • Variables
      • Terraform Cloud
      • Modules
  • Languages
    • Java
      • Logging
        • Getting Started
      • 00_Core
        • 00_Basics
          • Java Vs C++
          • Object oriented principles
          • Steps to compile a java program
          • JVM Internals
          • Understanding Java Development Kit
          • What is JIT Compiler?
          • Java data types
          • 07_identifiers_type_conversion
          • 08_references_and_packages
          • Steps for attaching scanner
        • Concurrency
          • 00_Threads
            • Threads
          • 01_ExecutorFramework
            • Executor Framework
            • Asynchronous Computation
      • 01_Backend
        • 01_HttpAndWebServerBasics
          • HTTP
          • Content Type
          • Web Server
        • 02_J2EE_Basics
          • J2EE_Basics
          • Why HttpServlet classs is declared as abstract class BUT with 100 % concrete functionality ?
        • 03_TomCatAndSession
          • What is a Session?
          • WebContainer
        • 04_PageNavigation
          • Cookies Additional Information
          • Page Navigation Techniques
        • 05_AboutServlet
          • CGI v/s Servlet
          • Executor Framework
          • Servlet Life cycle
          • SERVLET CONFIG
          • Servlet Context
          • Servlet Listener (web application listener)
        • 08_SpringBoot
          • Spring Boot
          • Some common annotations used in spring eco system
        • 09_SpringDataJPA
          • Spring Data JPA
        • Java_Language_Changes
          • JDK enhancement tracking reference
        • 06_ORM_Hibernate
          • readmes
            • Hibernate
            • Advantages of Hibernate
            • Hibernate Caching
            • Hibernate API
            • Hibernate Query API
            • Hibernate Annotations and JPQL
            • Entity and Value Type
        • 07_SpringFramework
          • bean_validation
            • Bean Validation
          • core
            • readme
              • Spring
              • Spring Framework Modules
              • Spring MVC Request flow
              • Dependency Injection
              • Spring Beans
              • 06_Spring_Framework_Annotations
      • 03_Tools
        • Maven
          • Maven
  • SoftwareEngineering
    • DesignPatterns
      • Notes
        • Basics
        • OOP
        • SOLID Principles
        • 03_Creational
          • Abstract Factory (aka Kit)
          • Builder
          • Factory Method (aka Virtual constructor)
          • Prototype
          • Singleton
        • 04_Structural
          • Adapter (aka Wrapper)
          • Bridge (aka Handle | Body)
          • Composite
          • Decorator (aka Wrapper)
          • Facade
          • Flyweight
          • Proxy (aka Surrogate)
        • 05_Behavioral
          • Chain of Responsibility
          • Command (aka Action | Transaction)
          • Iterator (aka Cursor)
          • Observer (aka Publish-Subscribe | Dependents)
          • Strategy (aka Policy)
    • Principles
      • REST
        • REST
  • Tools
    • Containers
      • Docker
        • Docker
        • Docker Image
        • Commands
        • Compose
        • Best Practices
      • Kubernetes
        • Kubernetes
    • VCS
      • Git
        • Quick reference of useful Git commands
Powered by GitBook
On this page
  • Icon
  • Basics
  • Message Visibility Timeout
  • Dead Letter Queue (DLQ)
  • Delay Queue
  • Long polling
  • SQS Extended Client
  • API Calls
  • Types of SQS Queues
  • Standard Queues
  • FIFO Queues
  • SQS Security
  • Access Control
  1. Cloud
  2. AWS
  3. DeveloperAssociate
  4. Services
  5. 14_Messaging

Simple Queue Service (SQS)

Previous14_MessagingNextSimple Notification Service (SNS)

Last updated 4 months ago

Icon

SQS Icon

Basics

  • One of the oldest offerings by AWS.

  • Fully managed service, used to decouple applications.

    1. Producer/s will send (produce) a message using SendMessage API offered by AWS SDK and put it in AWS SQS service queue.

    2. Message will be persisted in SQS untill a consumer deletes it.

    3. Messages will be retained as per retention policy of SQS.

      • Everytime a message is received for reprocessing the receive count is increased.

    4. Consumer/s will poll (consume) the message/s from SQS. Typically consumer can receive upto 10 messages at a time.

    5. Once a message is read/consumed by Consumer/s from the queue, they will be deleted using DeleteMessage API.

      • Consumers typically read more than one message per time, but by default it is 1 message per read.

      • Multiple consumers will receive different messages and process in parallel.

      • Consumers may be in an ASG and will be polling in an SQS group.

      • CloudWatch Metric can be set to trigger an CloudWatch Alarm, which in response may scale out the consumers.

Message Visibility Timeout

  • After a message is polled/consumed by a consumer, the message becomes invisible to other consumers. The time duration starts as soon as the ReceiveMessageRequest is returned by the SQS to consumer.

  • Once the timeout duration ends, the message is put back to the queue if the message doesnt get processed in that duration. Due to this the message may get duplicated and processed more than once by different consumers.

  • One can change the visibility timeout duration by calling the ChangeMessageVisibility API to get more time.

  • By default, the message visibility timeout is 30 seconds and can be increased up to 12 hours.

Dead Letter Queue (DLQ)

  • Once MaximumReceives threshold is exceeded, the message goes to dead letter queue.

  • Retention period should be set so that the messages dont get expired in DLQ.

  • DLQ of standard queue must be a standard queue and DLQ of FIFO queue must be a FIFO queue.

  • Maximum retention period is 14 days, as mentioned earlier.

Redrive

  • This feature helps messages in DLQ to be redriven back to source queue or any other queue or custom destination in batches without writing custom code.

  • Messages redriven from DLQ to Source will be as if new message has been received with receive count set to 1.

Delay Queue

  • Delay Queue offers a mechanism to delay the delivery of messages to consumer by some time period, by default it is 0 seconds (max 15 minutes).

  • DeliveryDelay parameter helps to configure the delay at queue level.

  • One can set the delay seconds value at send time by setting DelaySeconds parameter.

Long polling

  • Long polling allows consumers to wait for messages when no messages are available in the queue.

  • This reduces the number of API calls made to SQS while increasing efficiency and decreasing the latency of your application.

  • One can set wait time from 1 second to 20 seconds (preferrable) when long polling.

  • Long polling is preferrable to short polling.

  • Can be confugured at queue level or at the API level using ReceiveMessageWaitTimeSeconds.

SQS Extended Client

  • To send messages with size above 256 KB, one can use the SQS Extended Client (Java library).

  • The client sends the large message to S3 bucket and producer will send the metadata about S3 bucket and the message send to SQS queue.

  • This message will be consumed by consumer and retrieve the larger message (S3 Object) from S3 using the metadata and continue the process.

API Calls

API Name
Description

CreateQueue

To create queue. MessageRetentionPeriod parameter can be used to set the duration after which message is discarded.

DeleteQueue

To delete queue and messages in queue

PurgeQueue

To delete all messages in queue

SendMessage

To send messages, supports batch API. (DelaySeconds) parameter can be used to set the delay seconds.

ReceiveMessage

To receive messages

DeleteMessage

To delete messages once processed by consumer, supports batch API

MaxNumberOfMessages

Default 1, Max 10 (for ReceiveMessage)

ReceiveMessageWaitTimeSeconds

Long polling

ChangeMessageVisibility

To change message visibility timeout period, supports batch API

Types of SQS Queues

Standard Queues

Features

  • Unlimited throughput, unlimited number of messages in queue.

  • Default retention period of messages is 4 days, maximum of 14 days.

  • Low latency (< 10 ms on publish and receive).

  • Message size cannot exceed 256 KB.

  • Duplicate messages are possible i.e., a message may be delivered twice. But it aims for atleast once delivery.

  • Out of order messages may occur, as it offers best-effort ordering.

  • DLQ of a Standard queue must be Standard Queue.

FIFO Queues

  • Queue name should be suffixed with .fifo,

Features

  • Message ordering is preserved, first message coming into queue is the first to leave the queue. Hence, consumer process messages in order.

  • Limited throughput with 300 messages/seconds with out batching and 3000 messages/seconds with batching.

  • Messages are send exactly once, as it uses deduplication ID.

    • Optionally, it can do content-based deduplication as well.

Deduplication

  • Deduplication interval is 5 minutes, which enables a duplicate message received within this interval is refused.

Types of deduplication

  • Content based : Done by calculating SHA-256 SHA of message body.

  • Message deduplication ID based : Done by passing unique deduplication ID, is optional if Content based deduplication is enabled.

Message Grouping

  • If you specify same message group ID in SQS FIFO queue, you can only have one consumer, all the messages are in order.

  • Messages with common Message Group ID will be ordered with in the group, each group ID can have a different consumer (helpful for parallel processing).

  • Ordering across group is not guaranteed.

SQS Security

  • Offers in-flight encryption using HTTPS API.

  • Can also have at rest encryption using KMS keys.

  • Client-side encryption can also be done if the client wants to perform encryption/decryption itself.

Access Control

  • AWS IAM policies

    • Can be used to control access to SQS API.

  • SQS Access policy

    • Can also be used to control the access, which is useful when needed to make a cross account access or control access to write to SQS Queue by other AWS services.

A typical SQS based architecture flow will look in below diagram,

When message is not processed successfully within the period, as mentioned earlier they gets added back to the queue.

When these keeps on occurring for undeliverable messsage, could lead to failure loop. One can limit the number of times this reprocessing is being done, by adding a (DLQ).

dead letter queue
visibility timeout