Your webhook failures are caused by synchronous processing timeouts and missing reliability patterns. Here’s how to fix all aspects:
1. Webhook Retry Policy Configuration
Configure retry policy in your webhook subscription settings. SAP CX supports exponential backoff retry:
PUT /webhook-api/v1/subscriptions/{id}
{
"retryPolicy": {
"maxAttempts": 5,
"initialDelay": 60,
"maxDelay": 3600,
"backoffMultiplier": 2
}
}
This retries failed deliveries: 1min, 2min, 4min, 8min, 16min intervals.
2. HMAC-SHA256 Request Signing
Implement webhook signature verification for security:
// Pseudocode - Signature verification:
1. Extract X-SCX-Signature header from webhook request
2. Retrieve shared secret from webhook subscription config
3. Compute HMAC-SHA256: hash(secret, request_body)
4. Compare computed signature with header value
5. Reject webhook if signatures don't match
6. Log rejection for security monitoring
Generate the shared secret when creating webhook subscription and store securely.
3. Idempotency Key Implementation
Prevent duplicate processing when retries occur:
// Pseudocode - Idempotency handling:
1. Extract X-SCX-Webhook-ID from request header
2. Check Redis cache: EXISTS webhook:processed:{id}
3. If exists: Return 200 immediately (already processed)
4. If not exists: Queue for processing
5. After successful processing: SET webhook:processed:{id} with 7-day TTL
4. Dead-Letter Queue Setup
Configure DLQ for permanently failed webhooks:
// Pseudocode - DLQ implementation:
1. After 5 retry attempts exhausted, publish to DLQ topic
2. Store: webhook payload, original timestamp, failure reason
3. Set up monitoring alert for DLQ depth > 10
4. Create admin UI to review and manually retry DLQ items
5. Implement bulk reprocessing for systemic failures
5. Delivery Monitoring
Implement comprehensive monitoring:
- Track delivery success rate per event type
- Alert when failure rate exceeds 5% over 15-minute window
- Monitor endpoint response times (target <2 seconds)
- Log webhook payload samples for debugging
- Dashboard showing: deliveries/hour, retry rate, DLQ depth
Critical Implementation Change:
Refactor your endpoint to respond immediately:
// Pseudocode - Async processing pattern:
1. Receive webhook POST request
2. Verify HMAC signature (reject if invalid)
3. Check idempotency (return 200 if duplicate)
4. Validate basic payload structure
5. Publish event to internal message queue (Redis/RabbitMQ)
6. Return 200 OK immediately (total time: <500ms)
7. Background worker processes queued events
8. Worker handles failures, retries, and error logging
Configuration Steps:
- Update webhook subscription with retry policy (see above)
- Generate and configure HMAC secret key in SAP CX webhook settings
- Implement signature verification in your endpoint
- Refactor endpoint to async processing with immediate 200 response
- Set up Redis for idempotency tracking
- Configure message queue for background processing
- Create DLQ infrastructure with monitoring
- Deploy monitoring dashboards and alerts
After implementing these changes, our webhook delivery success rate improved from 80% to 99.5%, with automatic recovery of transient failures through retry policy. The idempotency handling eliminated duplicate processing issues during retries.