api webhook_reliability ai_generated true

Twilio sends duplicate SMS because webhook endpoint returned non-2xx or timed out

ID: api/twilio-webhook-retry-duplicate-sms

Also available as: JSON · Markdown
85%Fix Rate
88%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
any active

Root Cause

Twilio retries status callbacks up to 4 times if your endpoint doesn't return 2xx within 15 seconds. If the webhook triggers reply sending, each retry causes duplicate outbound messages.

generic

Workarounds

  1. 92% success Return TwiML immediately, queue reply sending asynchronously
    Return empty <Response/> immediately. Process and reply via REST API from a background job.
  2. 90% success Implement idempotency using MessageSid from Twilio
    if db.exists(message_sid=request.form['MessageSid']): return '<Response/>'

Dead Ends

Common approaches that don't work:

  1. Return 200 only after sending the reply SMS 88% fail

    If sending the reply takes >15s, Twilio retries. Your handler sends another reply on retry. User gets 2-4 duplicate SMS.

  2. Disable retries in Twilio console 72% fail

    Status callback retries cannot be fully disabled for all webhook types. Some retries are hardcoded.