Back to results for “Amazon SQS (Simple Queue Service)”
AWS › Amazon SQS (Simple Queue Service)

How does long polling in SQS improve efficiency compared to short polling?

Intermediate

Answer

Short polling checks the queue immediately and returns right away even if no messages are currently available, potentially resulting in many empty responses and wasted API calls, while long polling waits up to a configured maximum time, such as twenty seconds, for a message to become available before returning, significantly reducing the number of empty responses and the overall cost of polling an SQS queue for new messages.
aws sqs receive-message --queue-url https://sqs.us-east-1.amazonaws.com/123456789012/OrderQueue --wait-time-seconds 20
Real-world example A background worker service switches from short polling to long polling on its SQS queue, immediately cutting down the number of API calls made during quiet periods when few new messages are arriving.

Common follow-ups: What is the maximum wait time allowed for long polling?;Does long polling affect how quickly a new message is processed once it arrives?