Prompt
I'm building a system with retries fallback channels and webhook status updates
Latest observation
Here’s a solid way to think about a system with retries, fallback channels, and webhook status updates.
1) Core delivery flow
A good message delivery pipeline usually looks like this:
- Accept request
- Validate payload, recipient, channel preferences, auth, etc.
- Create delivery job
- Store a unique job/message ID.
- Set initial status:
queued.
- Attempt primary channel
- Example: SMS first, then email, then push.
- If failed, retry
- Use retry policy based on failure type.
- If still failing, fallback
- Move to next channel in priority order.
- Emit status updates
- Update internal status and send webhook notifications to the client.
2) Recommended statuses
Keep statuses explicit and machine-friendly:
queuedprocessingdeliveredfailedretryingfallbackingexpiredcancelled
You may also want reason codes:
provider_timeoutinvalid_destinationrate_limitedtemporary_errorpermanent_error
This helps clients understand whether to wait, retry, or intervene.
3) Retry strategy
Use different treatment for different error classes:
Retryable errors
- timeouts
- 5xx provider errors
- transient network issues
- temporary rate limits
Non-retryable errors
- invalid phone/email
- unverified destination
- blocked recipient
- malformed payload
Retry policy example
- exponential backoff with jitter
- max attempts: 3–5
- max retry window: 10–30 minutes
- per-channel timeouts
Example:
- Attempt 1 immediately
- Attempt 2 after 30s
- Attempt 3 after 2m
- Attempt 4 after 10m
4) Fallback channel design
Fallback should be based on a channel priority list, such as:
["sms", "email", "push"]
Rules:
- Only fallback after a channel is considered failed.
- Do not fallback on permanent failures that apply to all channels.
- Preserve delivery context and audit trail across channels.
Example:
- SMS times out after retries → fallback to email
- Email succeeds → stop
- All channels fail → final
failed
5) Webhook status updates
Webhooks should notify clients of lifecycle changes.
Events to send
delivery.queueddelivery.attempteddelivery.retryingdelivery.fallbackingdelivery.delivereddelivery.failed
Payload example
{
"event": "delivery.delivered",
"message_id": "msg_123",
"channel": "email",
"attempt": 2,
"status": "delivered",
"timestamp": "2026-11-03T12:00:00Z",
"failure_reason": null
}
6) Webhook delivery best practices
To make webhooks reliable:
- Sign requests with HMAC
- Include a timestamp to prevent replay attacks
- Make webhook delivery idempotent
- Retry webhook sends on failure
- Support event deduplication
- Give clients a way to verify delivery state via API
Webhook retry policy
- Retry 3–10 times
- Exponential backoff
- Stop retrying after a window
- Log dead-letter events if webhook endpoint remains unreachable
7) Idempotency and deduplication
Very important for both message delivery and webhooks.
For inbound requests
Require an idempotency key:
- prevents duplicate deliveries if client retries API call
For webhook events
Include an event ID:
- client can ignore duplicates safely
Example:
{
"event_id": "evt_456",
"message_id": "msg_123",
"event": "delivery.failed"
}
8) Data model idea
A simple schema might include:
messages table
idrecipientpayloadstatuscurrent_channelpriority_channelsattempt_countcreated_atupdated_at
message_attempts table
idmessage_idchannelattempt_numberstatusprovider_responseerror_codecreated_at
webhook_events table
idmessage_idevent_typepayloaddelivery_statusretry_countsent_at
9) State machine suggestion
A simple state machine helps prevent edge-case bugs:
queued
-> processing
-> retrying
-> fallbacking
-> delivered
-> failed
-> expired
-> cancelled
Rules:
- Only one terminal state:
delivered,failed,expired,cancelled - Retries don’t create new messages, only new attempts
- Fallback moves to the next channel only after the current one is exhausted
10) Operational concerns
Make sure you handle:
- rate limits
- provider outages
- dead-letter queue
- observability: logs, metrics, traces
- alerting on failure spikes
- audit trail for compliance
Track metrics like:
- success rate by channel
- retry rate
- fallback rate
- webhook delivery success rate
- average time to deliver
11) Suggested architecture
A practical setup:
- API service: accepts delivery requests
- Queue/worker system: processes delivery attempts
- Channel adapters: SMS/email/push providers
- State store: message status and attempts
- Webhook dispatcher: sends status updates
- Dead-letter queue: handles unrecoverable failures
12) Example sequence
- Client sends delivery request with channels: SMS → Email
- System stores message as
queued - Worker attempts SMS
- SMS provider times out
- Retry SMS twice with backoff
- SMS still fails
- System emits
delivery.fallbacking - Worker attempts Email
- Email succeeds
- System emits
delivery.delivered - Webhook sent to client with final state
If you want, I can help you next with one of these:
- a full API design
- a database schema
- a state machine diagram
- a Python/Node implementation
- a webhook event contract