Loading MQ::STREAM...
“When processing fails, immediate retries can hammer a recovering service. A robust strategy uses exponential backoff retry queues (e.g. retry-10s, retry-1m) and ultimately shunts unrecoverable poison-pill messages into a Dead-Letter Queue (DLQ) for human inspection.”
Handle poison-pill messages and downstream outages without stalling topic processing.
// Exponential Backoff with DLQ Router
async function processWithRetry(message, attempt = 0) {
try {
await sendPaymentToStripe(message);
} catch (error) {
if (attempt < 3) {
const delayMs = Math.pow(2, attempt) * 1000 + Math.random() * 500; // Jitter
console.log(`Retry attempt ${attempt + 1} scheduled in ${delayMs}ms`);
await sleep(delayMs);
return processWithRetry(message, attempt + 1);
} else {
console.error('Max retries exceeded. Routing to DLQ:', message.id);
await producer.send({ topic: 'payments-dlq', messages: [message] });
}
}
}Full jitter ($Backoff = ext{random}(0, ext{base} imes 2^{ ext{attempt}})$) distributes retry attempts across time, preventing cascading server collapses.