Complete guide to webhooks, debugging, and real-time event monitoring with HookMetry
Most webhook providers automatically retry failed webhook deliveries. Understanding retry behavior is crucial for building reliable integrations.
Retry delays increase exponentially: 1s 2s 4s 8s 16s...
Retry at regular intervals: every 5 minutes, every hour, etc.
// Using Redis for deduplication
const redis = require('redis');
const client = redis.createClient();
async function handleWebhook(req, res) {
const eventId = req.body.id;
// Check if we've already processed this event
const processed = await client.get(`webhook:${eventId}`);
if (processed) {
console.log('Duplicate webhook, skipping:', eventId);
return res.status(200).json({ message: 'Already processed' });
}
try {
// Process the webhook
await processPayment(req.body);
// Mark as processed (expires after 7 days)
await client.setex(`webhook:${eventId}`, 604800, 'processed');
res.status(200).json({ message: 'Processed successfully' });
} catch (error) {
console.error('Processing failed:', error);
// Return 5xx to trigger retry
res.status(500).json({ error: 'Processing failed' });
}
}