Hmm, the user wants a comprehensive design for a secure webhooks platform covering retries, signatures, rotation, replay UI, and quotas. This is a multi-faceted system design question requiring both security and operational considerations.
First, I need to structure the response around core pillars: security (signatures, rotation), reliability (retries), observability (replay UI), and resource management (quotas). The user likely expects production-grade patterns, not just theoretical concepts.
I should start with foundational security - HMAC signatures with key rotation are non-negotiable. Then address delivery guarantees via exponential backoff with jitter. The replay UI needs to balance debugging needs with security risks, so it must include authentication and audit trails. Quotas should be tiered with burst capacity.
The response should avoid over-engineering but demonstrate depth - for example, mentioning secret management integration (Vault) and dead-letter queues shows operational maturity. I'll explicitly call out trade-offs like replay window limitations to show nuanced understanding.
The tone should be authoritative yet explanatory, assuming the reader is a senior engineer. I'll use concrete examples (SHA256, 48h replay window) to ground the design. The conclusion should tie all pillars together as an integrated system rather than disjointed features.
Secure Webhooks Platform Design
1. Architecture Overview
┌─────────────┐ ┌──────────────┐ ┌──────────────┐
│ Senders │───▶│ Webhook │───▶│ Consumer │
│ (3rd party) │ │ Platform │ │ Endpoint │
└─────────────┘ └──────────────┘ └──────────────┘
│ │ │
▼ ▼ ▼
┌──────────────┐
│ Storage │
│ + Metrics │
└──────────────┘
2. Core Pillars
A. Request Signing & Verification
- HMAC Signature:
X-Webhook-Signature: sha256=<signature>
- Signature =
HMAC-SHA256(secret, payload + timestamp)
- Include
X-Webhook-Timestamp header to prevent replay attacks
- Secret Management:
- Per-customer or per-webhook secrets (customer-specific)
- Secrets stored encrypted (AWS KMS/Hashicorp Vault)
- Rotation without downtime (versioned secrets)
B. Secret Rotation
┌─────────────┐ ┌──────────────┐ ┌─────────────┐
│ Old Secret │────▶│ Dual Verify │────▶│ New Secret │
│ (v1) │ │ (Accept both)│ │ (v2) │
└─────────────┘ └──────────────┘ └─────────────┘
│ │
▼ ▼
┌─────────────────┐
│ Gradual Rollout│
│ - v1→v2 (24h) │
│ - v2 only (7d) │
└─────────────────┘
- Process:
- Generate new secret (versioned)
- Accept both old/new signatures for 24-48h
- Notify customers of rotation
- After grace period, reject old secret
- Audit all rotation events
C. Delivery Guarantees & Retries
Level 1: Immediate retry (1-2s delay) × 3
Level 2: Exponential backoff (15s, 30s, 60s) × 2
Level 3: Daily batch retry (once/day for 7 days)
Level 4: Dead-letter queue (manual intervention)
- Retry Policy: Configurable per webhook (critical vs. informational)
- Circuit Breaker: After
N consecutive failures (configurable), pause delivery
- Idempotency:
X-Webhook-ID header for deduplication (UUID v4)
D. Replay UI
┌─────────────────────────────────────────────┐
│ Replay Dashboard │
├─────────────────────────────────────────────┤
│ Filters: │
│ • Date range │
│ • Status (failed/success) │
│ • Webhook type │
├─────────────────────────────────────────────┤
│ Webhook List (paginated) │
│ ┌─────────────────────────────────────────┐ │
│ │ ID │ Type │ Status │ Timestamp │ Replay ││
│ ├─────────────────────────────────────────┤ │
│ │ 123│order│failed │ 10:23 AM │ [Replay]││
│ │ 124│user │success│ 10:22 AM │ [-] ││
│ └─────────────────────────────────────────┘ │
├─────────────────────────────────────────────┤
│ Replay Controls: │
│ • Select multiple → bulk replay │
│ • Modify payload (for testing) │
│ • Route to staging endpoint │
│ • Force redelivery (bypass retry limits) │
├─────────────────────────────────────────────┤
│ Audit Trail: │
│ • Who replayed what │
│ • Original vs. replayed payload diff │
│ • IP address & user agent │
└─────────────────────────────────────────────┘
Security Controls for Replay:
- RBAC: Only
admin/operator roles can replay
- Rate-limited replay operations (max 10/min per user)
- All replays logged with full context
- Can only replay events ≤ 30 days old (configurable)
E. Quotas & Throttling
┌─────────────────────────────────────────────┐
│ Customer Quota Profile │
├─────────────────────────────────────────────┤
│ • Monthly Events: 100,000 (soft limit) │
│ • Peak Rate: 100/sec (burst to 200) │
│ • Concurrent Connections: 50 │
│ • Payload Size: ≤ 5MB │
├─────────────────────────────────────────────┤
│ Enforcement: │
│ 1. Token bucket algorithm per customer │
│ 2. HTTP 429 with `Retry-After` header │
│ 3. Grace period 10% over quota │
│ 4. Alerting at 80% utilization │
├─────────────────────────────────────────────┤
│ Billing Tiers: │
│ • Free: 1,000 events/month │
│ • Pro: $0.01 per 1,000 events │
│ • Enterprise: Custom │
└─────────────────────────────────────────────┘
3. Data Model
-- Webhook events (write-optimized)
CREATE TABLE webhook_events (
id UUID PRIMARY KEY,
webhook_id UUID REFERENCES webhooks(id),
event_type VARCHAR(100),
payload JSONB NOT NULL,
signature_verified BOOLEAN,
delivery_attempts INT DEFAULT 0,
last_attempt_at TIMESTAMPTZ,
next_retry_at TIMESTAMPTZ,
status ENUM('pending','delivered','failed','permanently_failed'),
consumer_response_code INT,
consumer_response_body TEXT,
created_at TIMESTAMPTZ DEFAULT NOW(),
replay_of UUID REFERENCES webhook_events(id) -- for audit trail
);
-- Retry queue (separate table for processing)
CREATE TABLE retry_queue (
event_id UUID PRIMARY KEY,
scheduled_at TIMESTAMPTZ,
attempt_number INT,
backoff_seconds INT
);
-- Replay audit log
CREATE TABLE replay_audit (
id UUID PRIMARY KEY,
event_id UUID,
replayed_by UUID REFERENCES users(id),
replayed_at TIMESTAMPTZ DEFAULT NOW(),
modified_payload JSONB, -- if payload was edited
destination_override TEXT, -- if routed elsewhere
original_status VARCHAR(50)
);
4. Security Checklist
In Transit
- TLS 1.3 mandatory for all endpoints
- HSTS headers on webhook receiving endpoint
- CORS restricted to known consumer domains
At Rest
- Payloads encrypted at rest (AES-256)
- Secrets encrypted with KMS
- Database connection encryption
Access Control
- API keys with scopes (
webhooks:read, webhooks:replay)
- IP whitelisting for webhook endpoints (optional)
- Mutual TLS for sensitive customers
Monitoring & Alerts
alerts:
- signature_failure_rate > 5% (5min)
- consecutive_failures > 5 (same webhook)
- quota_usage > 90%
- replay_activity (anomaly detection)
- secret_rotation_failure
5. Implementation Considerations
Stateless Receivers
- Webhook ingestion endpoint should be stateless
- Immediately queue for processing (Kafka/SQS)
- Respond
202 Accepted within 100ms
Consumer SDKs
Provide SDKs in popular languages with:
- Automatic signature verification
- Built-in retry logic
- Idempotency handling
- Quota awareness
Compliance & Retention
- Configurable data retention (30-365 days)
- GDPR "right to be forgotten" support (anonymize events)
- SOC2 Type 2 audit trail (all actions logged)
6. Scalability Patterns
Sharding Strategy
# Shard by customer_id for isolation
shard_key = customer_id % NUM_SHARDS
# Hot customer mitigation:
# - Separate high-volume customers
# - Dedicated processing pool
Processing Pipeline
[Receiver] → [Queue] → [Verifier] → [Delivery Pool] → [DLQ]
│
└→ [Metrics] → [Monitoring]
7. Disaster Recovery
- Multi-region deployment (active-active preferred)
- Secrets replicated across regions (encrypted)
- Replay capability from backup storage (30-day retention)
- Failover: DNS-based with health checks
- Backfill: Replay events from S3/Blob storage if DB lost
8. Trade-offs & Limitations
| Decision | Trade-off |
|---|
| 30-day replay window | Storage cost vs. debugging utility |
| HMAC signatures | Shared secret model vs. asymmetric (more complex) |
| Eventual consistency | Replay UI might show stale data by ≤5s |
| Soft quotas | Possible abuse during grace period |
| Manual replay only | No automated replay to prevent loops |
Summary: This design balances security (signatures, rotation), reliability (retries, idempotency), observability (replay UI), and resource management (quotas). The key is defense in depth—multiple layers where failure of one doesn't compromise the system, plus operational tooling for debugging and management.