Amazon SQS

Short vs Long Polling

Cut empty-receive cost and latency by waiting for messages instead of hammering the queue.

When a consumer calls ReceiveMessage, SQS can respond in two modes. Short polling (WaitTimeSeconds=0) queries a subset of servers and returns immediately, even if no messages are found — which means frequent empty responses, more API calls, and higher cost. Long polling (WaitTimeSeconds 1–20) tells SQS to wait up to that many seconds for a message to arrive before responding, querying all servers.

Short polling is repeatedly opening the fridge every few seconds to check for food — wasteful and you might miss the back shelf. Long polling is asking someone to tap you the moment food appears, up to 20 seconds — fewer trips, faster notice.

Key Concepts

1
Long polling is almost always preferred: it dramatically reduces the number of empty receives (and thus billed API requests), lowers latency (a message is returned as soon as it appears, not on the next poll), and reduces false-empty responses caused by SQS's distributed nature. AWS recommends enabling it nearly everywhere.
2
You set it per-receive with WaitTimeSeconds or as a queue default with ReceiveMessageWaitTimeSeconds.
3
What the interviewer is probing.
What the interviewer is probing.
4
1. "What is the difference?" *Probing:* the mechanics. *Stalls:* "Timing." *Moves up:* short polling samples a subset of servers and can return empty with messages present; long polling waits up to 20 seconds for a message.
1. "What is the difference?"
5
2. "Why does long polling cost less?" *Probing:* the commercial angle. *Stalls:* "It does not." *Moves up:* you are billed per request, and empty short-poll responses are billable requests that found nothing.
2. "Why does long polling cost less?"
6
3. "When would short polling be right?" *Probing:* the honest exception. *Stalls:* "Often." *Moves up:* almost never — only when you must return immediately whether or not a message exists.
3. "When would short polling be right?"
7
4. "How do you enable it?" *Probing:* the detail. *Stalls:* "A flag." *Moves up:* ReceiveMessageWaitTimeSeconds on the queue, or WaitTimeSeconds per request.
4. "How do you enable it?"