Quick Response Pattern
The most critical rule for webhook handling: respond immediately, process asynchronously. Lettr waits up to 30 seconds for your endpoint to respond. If processing takes longer, the webhook is considered failed and will be retried.Idempotency
Webhooks may be delivered more than once due to retries, network issues, or edge cases. Your handler must be idempotent—processing the same event twice should have the same effect as processing it once.Using Event IDs
Every webhook event has a uniqueid. Store processed event IDs to detect and skip duplicates:
Database-Based Idempotency
For applications without Redis, use your database:Idempotency with Business Logic
Sometimes you need idempotency at the business level, not just event level:Queue-Based Processing
For high-volume applications or complex processing, use a message queue to decouple webhook receipt from processing:Error Handling
Proper error handling ensures you don’t lose events and can debug issues effectively.Categorizing Errors
Graceful Degradation
When external dependencies fail, don’t block the entire webhook:Handling Inbound Emails
Inbound email webhooks (relay.relay_delivery) require special consideration for attachments, threading, and routing.
Processing Attachments
Attachment URLs are temporary. Download them promptly:Routing Inbound Emails
Route emails to different handlers based on recipient address:Threading Conversations
Use email headers to thread conversations:Handling Multiple Recipients
When an email is sent to multiple addresses on your domain, handle each appropriately:Monitoring and Observability
Track webhook processing health with metrics and logging:Framework-Specific Examples
Next.js App Router
Express with TypeScript
Related Topics
Authorization
Secure your endpoints with authentication
Retries
Understand retry behavior and failure handling
Event Types
Complete reference of all webhook events
Testing
Test webhooks in development and production