157k views
2 votes
When should I use Amazon SQS long polling, and when should I use Amazon SQS short polling?

User Manishie
by
7.1k points

1 Answer

4 votes

Final answer:

Choose Amazon SQS long polling to reduce empty responses and costs in low-traffic systems, and receive messages as soon as available. Use short polling for a steady flow of messages and when immediate receipt is a priority.

Step-by-step explanation:

When deciding between Amazon SQS long polling and Amazon SQS short polling, it is crucial to understand the differences and when each is most effective. Amazon Simple Queue Service (SQS) provides two different message polling methods to receive messages from a queue: short and long polling.

Short polling occurs when the SQS‌ polling receive call checks only a subset of the servers (sqs queues) holding the messages and returns immediately, even if the queue being polled is empty. It is the default behavior for Amazon SQS and might lead to more frequent poll requests if messages are not available in the subset of servers checked. The benefit is that responses are instantaneous, providing faster message delivery when the system is passing messages regularly.

Long polling, on the other hand, is a technique that reduces the number of empty responses by waiting until a message is available in the queue before sending a response. It will wait for a set amount of time (up to 20 seconds) for messages to become available. Long polling makes it less likely to retrieve an empty response compared to short polling, thus reducing unnecessary network bandwidth consumption and API call charges.

Use long polling when you want to reduce the number of empty responses and save costs associated with polling for messages, especially in low-traffic systems. It is also the preferred choice when you want to receive messages as soon as they become available without over-polling the service.

Use short polling when expecting a steady flow of messages and when immediate message receipt is more important than the cost implications of polling frequently. This would typically apply to systems with higher message volumes or where latency in message delivery is a critical factor.

User Enzokie
by
7.7k points