In Amazon SQS, messages either get processed and deleted or eventually expire. Those aren’t the only two ways a message gets removed from the queue, though. SQS also supports dead letter queues, where you can send messages that refuse to process properly.
Implementing a dead letter queue requires two things:
What’s a Redrive Policy? Basically, when you define a Redrive Policy, you tell SQS how many times a single message is allowed to be received before being considered dead. Next, you tell your queue which other queue to send dead messages to. If you get a message in your queue that your processing application can’t properly parse, using a dead letter queue will prevent and endless cycle of receiving, crashing, and the message becoming visible in the queue again.
Not only is this great because it prevents excessive compute usage by your processing application, it also provides an excellent hook for notifications. You can use a CloudWatch alarm, coupled with an SNS topic, to receive notifications when there is activity in your dead letter queue. That’s a bit beyond the scope of an SQS overview, but maybe I’ll write up a separate post about it at some point.