Sobes.tech
Senior

How many retry attempts should be made before sending a message to the DLQ?

sobes.tech AI

Answer from AI

The number of retry attempts before sending a message to the Dead Letter Queue (DLQ) depends on the specific architecture and system requirements. Usually, it is recommended to:

  • Retry 3 to 5 times.
  • After unsuccessful attempts, the message is sent to the DLQ for further analysis and processing.

This helps avoid infinite retries and prevents losing messages that could not be processed.

The actual number of attempts should be configured based on:

  • The reliability of external services.
  • The importance of the message.
  • Processing time constraints.

An example of configuration in code might look like this:

const maxRetries = 5

for i := 0; i < maxRetries; i++ {
    err := sendMessage(msg)
    if err == nil {
        break
    }
    if i == maxRetries-1 {
        sendToDLQ(msg)
    }
}