Based on the content provided, here's a summary of best practices and considerations for handling webhooks in a robust manner:
Key Concepts
- Delivery Idempotency: Ensuring that receiving the same webhook event multiple times does not create duplicate business operations.
- Business Idempotency: Guaranteeing that a specific business operation is executed only once, regardless of how many times the webhook is delivered.
Implementation Details
Webhook Receipt Table
Create a table to track incoming webhooks:
sql1CREATE TABLE webhook_deliveries ( 2 id BIGINT PRIMARY KEY, 3 provider VARCHAR NOT NULL CHECK (provider IN ('github', 'stripe')), 4 external_id UUID NOT NULL, 5 event_type VARCHAR NOT NULL, 6 payload JSONB NOT NULL, 7 created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, 8 UNIQUE(provider, external_id) 9);
Controller Logic
Handle webhook receipt and enqueue jobs:
ruby1def create 2 request = Request.new(raw_body: params[:raw_body]) 3 delivery_id = request.headers["X-GitHub-Delivery"].presence 4 event_type = request.headers["X-GitHub-Event"].presence 5 6 return head :bad_request unless 7 8[Read the full article at DEV Community](https://dev.to/rob__race/your-webhook-endpoint-is-a-tiny-distributed-system-p71) 9 10--- 11 12**Want to create content about this topic?** [Use Nemati AI tools](https://nemati.ai) to generate articles, social posts, and more.



