All concepts
Fundamentals

Short vs Long Polling

Long polling cuts empty-receive cost and reduces latency.

Why it matters

Short polling returns immediately even if the queue is empty, generating wasted API calls. Long polling waits up to 20 seconds for a message to arrive.

Short polling (default)

ReceiveMessage with WaitTimeSeconds = 0 queries a subset of SQS servers (weighted random distribution) and returns immediately, even if no messages are found. A single request might not return all available messages.

  • Can return empty even when messages exist on other servers.
  • Subsequent requests eventually sample all servers.
  • Higher empty-response rate → higher cost and latency.

Long polling

When WaitTimeSeconds is 1–20, ReceiveMessage queries all servers and waits up to that duration for at least one message. An empty response is sent only if the wait time expires with no messages available.

  • Maximum wait: 20 seconds.
  • Set on queue (ReceiveMessageWaitTimeSeconds) or per request (WaitTimeSeconds).
  • Per-request value overrides queue default when set.
ReceiveMessage({
  QueueUrl,
  MaxNumberOfMessages: 10,
  WaitTimeSeconds: 20,  // long polling
})

Benefits

Long polling reduces empty responses, reduces false empty responses (messages exist but weren't sampled), and returns messages as soon as they become available — lowering cost and improving responsiveness for low-traffic queues.

In-flight limit interaction

With short polling, reaching the ~120,000 in-flight message limit returns an OverLimit error. With long polling, SQS returns no new messages until in-flight count drops — no error, but consumers appear idle.

Best practices

Set ReceiveMessageWaitTimeSeconds to 20 on all queues unless you have a specific reason for immediate returns. Ensure your HTTP client read timeout exceeds the polling wait time.

Gotchas
  • !Default is 0 (short polling) — explicitly set 20 unless you have a reason not to.
  • !Long polling wait must be less than the HTTP client read timeout, or you'll see false timeout errors.
  • !Rarely, long polling with a very low WaitTimeSeconds can still return empty when messages exist.
Try the Latency spike lab
Apply this concept to a broken system.
open →