Overview
When a consumer requests messages and the queue has none yet, the consumer can wait for messages to arrive. This is long polling. As soon as a message arrives, it is sent to the consumer.
Benefits
- Fewer API calls to SQS, because each call is a long call (the consumer may ask the queue for, e.g., 10 seconds).
- Lower latency: a message is delivered as soon as SQS receives it, so the consumer gets it with the least lag.
Configuration
| Item | Value |
|---|---|
| Wait time | 1 to 20 seconds |
| Recommended | 20 seconds - the longer the wait, the more efficient and the fewer API calls |
| Queue level | Enable on the queue |
| API level | WaitTimeSeconds parameter |
Exam Pattern
Prefer long polling over short polling. Fewer API calls and lower latency. Enable at queue level or with WaitTimeSeconds.
Questions & Answers
Q1: What does long polling do?
Answer:
The consumer waits for messages to arrive when the queue is empty, which reduces API calls and latency.
Q2: What wait time can you set?
Answer:
1 to 20 seconds, 20 seconds is preferable.
Q3: How do you enable it?
Answer:
At the queue level or per request with the WaitTimeSeconds parameter.
Check yourself
Quiz
Flashcards
Click the card (or focus it), then use ← → to move and Space to flip.