Skip to content
- Serverless message queue
- 2 Types
Visibility Timeout
- When a message is received, it is made invisible to subsequent
ReceiveMessage
calls for a duration called “visibility timeout” - Consumer should delete processed messages, or the message will reappear after the timeout
- Can be set to 0 seconds to 12 hours, default 30 seconds
- Messages will be discarded after a retention period (can be set to 60 seconds to 14 days, default 4 days)
Polling
- Short polling
- SQS samples queue nodes and returns messages immediately
- May not return all messages as this is sample-based
- Cloud return empty results
Short polling sampling behavior
- Long polling
- SQS waits up to 20 seconds to in attempt to get at least 1 message (less empty responses)
- SQS query all queue nodes so no message in queue is missed
- Note: long polling API is still synchronous so make sure your application can keep connection open during timeout
- Short vs. long 🎓
- Return immediately vs. return after a given timeout or a message is received
- Sample some nodes vs. query all nodes
- More likely to return empty results vs. only return empty result after timeout and no messages received
- Technically they both use ReceiveMessage API, only the
WaitTimeSeconds
parameter in long polling is set to value larger than 1
- Because of long polling reduces number of requests, the cost of using long polling is lower than short polling
- SQS is billed by number of requests so it does not matter a request is short or long polling
- Use cases
- Use short polling when immediate return of result is needed
- Otherwise, use long polling
Like this:
Like Loading...