Prompt
transactional notification api with retries
Latest observation
Oct 13, 2026
OpenAI APIWeb search: off
Here’s a solid design for a transactional notification API with retries.
Goals
- Send notifications reliably after a business transaction succeeds
- Retry transient failures automatically
- Avoid duplicate sends
- Track delivery status
- Support email/SMS/push/webhooks, etc.
Core approach
Use the outbox pattern:
- Your application performs the business transaction.
- In the same DB transaction, write a notification record to an
outbox_notificationstable. - A background worker reads pending records and delivers them.
- On failure, retry with exponential backoff.
- Mark as delivered when successful, or dead-letter after max retries.
This avoids losing notifications if the app crashes after the business transaction commits.
API design
1) Create notification request
POST /notifications
{
"transactionId": "txn_12345",
"type": "order_confirmed",
"channel": "email",
"recipient": {
"email": "user@example.com"
},
"templateId": "tmpl_order_confirmed",
"data": {
"orderId": "ord_987",
"amount": 49.99
},
"idempotencyKey": "txn_12345-order_confirmed"
}
Response
{
"notificationId": "ntf_abc123",
"status": "queued"
}
Suggested status lifecycle
queuedprocessingretry_scheduleddeliveredfaileddead_lettered
Retry strategy
Retry on
- Network timeouts
- 5xx responses
- Rate limiting (
429) - Temporary provider outages
Do not retry on
- Invalid recipient
- Bad template/data
- 4xx permanent errors other than 429
Backoff
Use exponential backoff with jitter:
- Attempt 1: immediately
- Attempt 2: after 30s
- Attempt 3: after 2m
- Attempt 4: after 10m
- Attempt 5: after 1h
- Then dead-letter
Example formula:
delay = min(base * 2^attempt, maxDelay) + random_jitter
Data model
notifications
idtransaction_idtypechannelrecipienttemplate_idpayloadstatusattempt_countnext_retry_atlast_erroridempotency_keycreated_atupdated_atdelivered_at
notification_attempts
idnotification_idattempt_numberstatuserror_codeerror_messageprovider_message_idstarted_atended_at
Delivery worker flow
- Poll for notifications where:
status IN ('queued', 'retry_scheduled')next_retry_at <= now()
- Lock record for processing.
- Send to provider.
- If success:
- mark
delivered - store provider message id
- mark
- If transient failure:
- increment attempt count
- compute next retry time
- mark
retry_scheduled
- If permanent failure or max attempts exceeded:
- mark
failedordead_lettered
- mark
Idempotency
Important to prevent duplicates:
- Require
idempotencyKeyfrom client - Store and enforce uniqueness
- When retrying, use the same notification record
- If provider supports idempotency keys, pass them through
Example retry policy config
{
"maxAttempts": 6,
"baseDelaySeconds": 30,
"maxDelaySeconds": 3600,
"jitter": true,
"retryableStatusCodes": [408, 429, 500, 502, 503, 504]
}
Observability
Track:
- total queued
- delivered count
- retry count
- dead-letter count
- average delivery latency
- provider-specific error rates
Add structured logs and tracing with:
- notification id
- transaction id
- attempt number
- provider response code
Example endpoints
Get notification status
GET /notifications/{id}
{
"id": "ntf_abc123",
"status": "retry_scheduled",
"attemptCount": 2,
"nextRetryAt": "2026-10-13T12:30:00Z",
"lastError": "HTTP 503 from provider"
}
List attempts
GET /notifications/{id}/attempts
Common implementation stack
- API: Node.js / Java / Go / Python
- DB: Postgres
- Queue: SQS / RabbitMQ / Kafka / Redis Streams
- Worker: background job processor
- Scheduler: retry scanner or delayed queue
If you want strong reliability
Use:
- DB transaction + outbox table
- worker with distributed locking
- idempotency keys
- dead-letter queue
- provider failover
If you want, I can also provide:
- a full REST API spec
- a Postgres schema
- a Node.js/Express implementation
- a sequence diagram for the retry flow