CodePark/ questions / Retries, poison messages & DLQs
START PRACTICINGPRACTICE
Backend question · Message queues & streaming › Retries, poison messages & DLQs

Your DLQ has 20,000 messages after a bad deploy. How do you redrive them safely?

Fix the cause first, then move the messages back slowly, in small batches. The DLQ (dead-letter queue) is the queue where messages go after they fail too many times. To redrive means to send them back to the normal queue so they get processed again.

1. Understand the failures. Take a sample of the messages and group them by error. Confirm that the cause is fixed and the fix is deployed. If you redrive before the fix, the messages just fail again and go back to the DLQ.

2. Check that redelivery is safe. Consumers must be idempotent: processing the same message twice gives the same result as processing it once. This matters because some messages may have partly succeeded the first time. Also decide whether old messages still make sense. For example, a "send reminder" event from two days ago may be better dropped or handled in a different way.

3. Redrive gradually. Move a small batch first and watch the errors. Then increase the rate step by step. A sudden burst of 20,000 messages could overload the consumer or the database behind it.

4. Keep the original metadata. Keep the message id, timestamps and attempt count. Deduplication and tracing still need them.

5. Remember ordering. Redriven messages arrive after newer messages. This matters if your consumers depend on order.

Tools for each broker:

  • SQS has a built-in redrive back to the source queue.
  • RabbitMQ can move messages with a shovel (a plugin that moves messages from one queue to another).
  • In Kafka, you replay the DLT (dead-letter topic) with a small consumer.
  • Group the messages by error, and confirm the fix is deployed first.
  • Consumers must be idempotent, and you must decide if old messages still make sense.
  • Redrive a small batch first, then slowly increase the rate.
  • Keep the original message ids and metadata.
  • Redriven messages arrive out of order, after newer ones.