For failed seller-order email deliveries, use error logging to establish what the API actually confirmed before choosing a retry. Authorize another attempt only with a documented reason, a remaining time budget, and an evidence record that survives the worker. For a logistics marketplace, the operational goal is to explain each notification without turning an uncertain submission into duplicate messages.
TL;DR: Separate submission failures from delivery outcomes, record each decision against one durable notification identity, and bound retries by the order's useful notification window. Treat an ambiguous API result as a reconciliation task. Keep permanent failures out of the retry queue.
The evidence matters. SPF defines a way to authorize hosts to use a domain in SMTP identities; it does not establish that a seller read an order notification. A compliance review needs an explicit boundary between authentication evidence, submission evidence, and whatever delivery evidence the integration actually supplies. Calling all three “sent” makes a dashboard easier to build and an audit harder to defend.
What should error logging capture before retrying failed email deliveries?
Start the runbook with the marketplace order, seller reference, and notification identity. Ask which observation is missing before choosing a retry action. An API response recorded by a worker is evidence about that submission; design the application so that it cannot silently promote that observation to recipient delivery or seller acknowledgment. If acknowledgment is the business requirement, represent it as a separate event with its own source.
Consider an illustrative order, order-4827, and notification seller-order-4827-v1. The worker attempts submission and loses the response. The useful question is whether the receiving system accepted that identity, not whether the worker can send the request again. Unless the integration has a documented deduplication or lookup contract, a second submission introduces a duplicate risk that the incident record must preserve.
Unknown stays unknown.
Don't convert uncertainty into a convenient success flag.
Use distinct application states for queued work, attempts in progress, confirmed acceptance, uncertain submission, observed delivery, and terminal failure. These are proposed internal states, not names to assume an external API implements. Retain the raw external outcome separately from its internal classification, together with the classifier version; otherwise a future policy change can make yesterday's decision impossible to reproduce.
SPF deserves similarly precise handling. RFC 7208 distinguishes results such as fail, softfail, temperror, and permerror. Preserve the result if an authenticated source actually reports it, but do not infer it from an unrelated API error or assume it is a complete delivery diagnosis. The RFC describes SPF processing; it is not the contract for your notification API. An authentication configuration investigation and an application retry decision need separate evidence.
Record the decision before scheduling another attempt
Use an append-only application event record as the proposed audit model. Each event should carry the notification identity, order reference, attempt number, observation time, source, correlation identifier, normalized outcome, policy version, and decision reason. Include the next eligible attempt time or the reason processing stopped. Keep the original observation time distinct from the time your service received the event so delayed evidence does not rewrite the apparent sequence.
Be selective about payloads.
A seller's email address and full order contents rarely help explain why a scheduler authorized attempt 3. Prefer an access-controlled seller reference in routine logs, with a separately governed lookup when an investigation needs the destination. Define retention, access, deletion, and integrity requirements with the people responsible for compliance; an append-only label by itself proves neither legal sufficiency nor protection against alteration.
The important implementation boundary is the durable scheduling transaction. Persist the decision and the next queue item together, or use an outbox consumed by a dispatcher. If the event write fails, stop advancing this notification and surface that failure to the operator. A later dashboard export cannot reconstruct a decision that was never recorded. Concurrent workers also need a lease or conditional state transition so they cannot both authorize the same next attempt.
Store a sanitized diagnostic category rather than indiscriminately copying response bodies into logs. Preserve enough restricted evidence to investigate a classification dispute, and make redaction part of the write path. Auditability and unlimited logging are different requirements.
Make retry policy small enough to inspect
The following Go example is a pure decision function for an illustrative policy. It deliberately receives an already classified observation: a separate adapter must map documented integration behavior into these categories. In particular, no numeric HTTP status alone is treated here as proof that a duplicate submission is safe.
package notification
import "time"
type Outcome uint8
const (
Accepted Outcome = iota
Retryable
Permanent
Uncertain
)
type Decision struct {
Action string
Reason string
Delay time.Duration
}
func Decide(outcome Outcome, attempts int, remaining time.Duration) Decision {
if attempts < 1 {
return Decision{Action: "review", Reason: "invalid_attempt_count"}
}
switch outcome {
case Accepted:
return Decision{Action: "observe", Reason: "submission_accepted"}
case Permanent:
return Decision{Action: "stop", Reason: "permanent_failure"}
case Uncertain:
return Decision{Action: "reconcile", Reason: "acceptance_unknown"}
case Retryable:
if attempts >= 3 {
return Decision{Action: "stop", Reason: "attempt_budget_exhausted"}
}
delay := 30 * time.Second
if attempts == 2 {
delay = 2 * time.Minute
}
if remaining <= delay {
return Decision{Action: "stop", Reason: "notification_window_exhausted"}
}
return Decision{Action: "retry", Reason: "transient_and_within_budget", Delay: delay}
default:
return Decision{Action: "review", Reason: "unrecognized_outcome"}
}
}
Here, attempts counts completed submission attempts, including the initial one. The maximum of 3 attempts and delays of 30 seconds and 2 minutes are example policy choices, not recommended universal defaults or external service limits. Choose the useful window with marketplace operations: an email arriving after the seller's dispatch decision may require escalation instead of another automatic attempt.
This function does not submit mail, persist evidence, implement jitter, or reserve capacity. The caller must do those things before authorizing production work. Persist the actual scheduled time after applying bounded jitter and any documented integration scheduling constraints, then check the deadline again. Recheck eligibility immediately before sending too; queue delay can consume a window that was available when the decision was made.
A retry after an observed delivery failure needs its own policy. For this runbook, require an explicit decision about whether to create a replacement submission, and link that replacement to the original notification. Otherwise two independent retry paths can grow around one seller order: an application scheduler for submission and another scheduler reacting to later delivery evidence.
Budget queue capacity and ownership together
Capacity planning starts with multiplication. Under this illustrative three-attempt policy, 1,000 new notification identities could authorize at most 3,000 submissions if every identity consumes its full budget, before any explicitly approved replacements. That is a planning bound, not a measured workload. Reconciliation reads, incoming evidence events, and audit writes need separate budgets.
Reserve capacity for fresh orders, cap retries independently, and track the oldest eligible queue age. A flood of old retries should not consume the entire useful window of new seller notifications. Define an SLO for timely submission separately from the objective for evidence completeness, then measure delivery outcomes only where an attributable signal exists. An unknown outcome belongs in the denominator you disclose, rather than disappearing from a success chart.
The buy-versus-build decision should follow the evidence boundary:
| Approach | Evidence question to resolve | Operational trade-off |
|---|---|---|
| Managed submission with an internal decision ledger | Can the team retain and correlate the required submission and outcome evidence? | Less transport ownership, with an external contract and retention boundary to verify. |
| Self-operated submission and evidence pipeline | Can the team operate both delivery processing and the required audit controls? | More direct control, with capacity planning and on-call responsibility inside the team. |
| Managed transport with internally owned scheduling | Can external observations be reconciled against internal retry decisions? | More policy control, with an adapter and reconciliation workflow to maintain. |
Treat these as evaluation questions, not assurances that either operating model satisfies a particular regulation. The trade-off is greater control versus more on-call work: choose internal scheduling only if the team can own reconciliation, because its audit value depends on someone resolving unknown outcomes. Team capacity is part of the design: evidence exports, access reviews, and ambiguous-submission investigations all need named owners.
Verify the evidence chain, then rehearse rollback
Before deployment, exercise the proposed policy with deterministic cases: transient failure followed by acceptance, permanent failure, a lost submission response, an unknown outcome category, and a deadline crossed while the notification waits in the queue. Inject an audit-store write failure and concurrent worker claims as well. Verify both the decision and its durable record; a test that checks only the returned action misses the compliance boundary. Replay delayed and duplicate outcome events. The expected result is preserved evidence without a second automatic replacement submission. Test a quiet pipeline too: an absence of outcome events should become visible as missing evidence, rather than counting as successful delivery. Use a controlled test destination and synthetic order data so the exercise cannot notify a real seller about a fictitious order.
Roll out the new classifier in observation mode first, comparing its proposed decisions with the active policy without submitting additional messages. Once differences are explained, enable a bounded cohort and watch queue age, retry volume, uncertain submissions, missing evidence, and audit-write failures. Set the cohort limit and rollback thresholds before enabling it.
Rollback must preserve history.
Pause new retry dispatches, retain queued identities and recorded decisions, and restore the previous policy version for future evaluations. Do not reset attempt counts or erase uncertain states to make the backlog look clean. Reconcile work already accepted by the transport before releasing paused items. The operational finish line is a traceable decision for each seller-order notification, including the ones that stopped, expired, or still need investigation.
References
- RFC 7208: Sender Policy Framework (SPF), including result definitions and processing limits: https://datatracker.ietf.org/doc/html/rfc7208
Top comments (0)