Skip to main content
This guide covers production-ready webhook handlers with error handling, logging, and best practices.
New to webhooks? Start with our Webhook Quickstart for a complete end-to-end tutorial.

Production Requirements

Your production webhook handler should:
  • ✅ Handle POST requests with JSON payloads
  • ✅ Return 2xx status codes for successful processing
  • ✅ Acknowledge promptly after verifying and durably accepting the event
  • ✅ Handle retries gracefully (deduplicate repeated deliveries)
  • ✅ Log events for debugging and monitoring
  • ✅ Verify signatures for security

Retry Behavior

Automatic Retries: Network failures, timeouts, and non-2xx responses cause Magic Hour to schedule another delivery attempt:
  • Pattern: Scheduled delays of 1, 2, 4, 8, … minutes, capped at 60 minutes
  • Expiry: Events more than 24 hours old are marked as failed and are no longer delivered
  • Security headers: The timestamp and signature are regenerated for each delivery attempt
These are scheduled delays, not guaranteed delivery times. The expiry is measured from event creation, not the first failed attempt. Disabled Webhooks: Pending events are rescheduled without delivery and retain the same expiry. Re-enabling the webhook allows pending deliveries to resume before expiry.

Production Handler Examples

These examples omit signature verification. Before accepting events, verify the signature and timestamp against the raw body. Save the verified event to a database or durable queue before returning 2xx. A restart can lose in-process background tasks after Magic Hour considers delivery complete.

Best Practices

1. Deduplicate Webhook Deliveries

Magic Hour may retry delivery, so detect and skip repeated events:
Use an atomic database claim or unique constraint for the deduplication key so concurrent deliveries cannot both process it. Apply job-state changes transactionally and avoid replacing a terminal state with a delayed started event.

2. Quick Response Times

Acknowledge promptly after signature verification and durable acceptance. Run long processing from the saved event. The abbreviated timing examples below do not implement those production requirements:

3. Comprehensive Logging

Log all events for debugging:

4. Error Handling

Handle errors gracefully:

Local Testing

Test your handler locally before deploying:

Deployment Considerations

Load Balancing

If using multiple servers, ensure webhooks can reach any instance:

Health Checks

Add a health check endpoint:

Monitoring

Monitor webhook delivery and processing:

Next Steps

Secure Your Handler

Add signature verification for production security

Event Types Reference

Complete list of webhook events and payloads

Webhook API Reference

Detailed webhook API documentation

Quickstart Guide

New to webhooks? Start with our quickstart

Common Issues

Webhook timeouts?
  • Return 2xx promptly after signature verification and durable acceptance
  • Process long-running work from a durable queue or saved event, not only in-process background tasks
  • Check server resources and scaling
Missing events?
  • Verify webhook is enabled in Developer Hub
  • Check endpoint URL is correct and accessible
  • Review server logs for errors
Duplicate events?
  • Deduplicate deliveries using the project ID and event type
  • Store processed deduplication keys
  • Handle retries gracefully
Need help? Contact support@magichour.ai