Use a replayable delivery ledger and a bounded retry policy for game compliance notices. Short answer: log each failure, classify its reason, and retry only transient outcomes within a deadline. The deciding constraint is evidence: a successful API response records an attempt, while the audit record must explain the later delivery event, the recipient, and every retry decision.
The proposed experiment has a strict constraint. Replaying the same notice must avoid a second send, and an auditor must be able to follow the whole chain from intent to terminal event. A worker that retries every non-2xx response looks convenient. It also turns a malformed address into a loop. Keep transport, classification, and the ledger as separate pieces.
What belongs in the evidence ledger?
Write an intent row before calling the provider. Give it a notice ID, a stable recipient reference, the template revision, an attempt number, a UTC timestamp, and the compliance deadline. Add the HTTP status and original failure text after the call. A hashed address is enough for routine operations; retain the raw address only where policy permits it.
The send response is one observation, not the final outcome. Poll delivery events, attach each event to the notice and attempt that caused it, and upsert by a provider event identifier when available. Event replay should update one row rather than create a second incident.
Acceptance isn't delivery.
Treating provider acceptance as delivery creates an evidence gap: an accepted message can later bounce or be rejected by policy. The ledger needs both the attempt and the later terminal event, with the raw reason preserved for a reviewer.
How should error logging guide retry strategies for failed email sends?
Classify first. An invalid email address is permanent; waiting cannot repair it, so mark the notice terminal and create a remediation task. Rate limiting and short-lived network or provider faults are plausibly transient. They may enter a bounded queue with exponential backoff, jitter, and a hard attempt limit.
Keep the idempotency key stable when retrying the same logical send. Changing it on each transport retry can create duplicate notices after an ambiguous timeout. Honor Retry-After on HTTP 429 when present, while still capping attempts and the policy deadline. A proposed four-attempt budget is an application choice, not a measured optimum.
Here is a focused, runnable Python policy example. Its inputs are synthetic classified failures, not provider response fields. A production adapter must preserve the original status and failure text before mapping them to these local labels. The policy returns a delay for a durable worker; it doesn't sleep inside the request handler.
from datetime import datetime, timezone
import json
def retry_decision(kind, attempt, seconds_left, retry_after=0):
if kind != "transient":
return {"action": "review", "reason": kind}
if attempt >= 4:
return {"action": "review", "reason": "attempt_limit"}
delay = max(retry_after, 2 ** attempt)
if delay >= seconds_left:
return {"action": "review", "reason": "deadline"}
return {"action": "retry", "delay_seconds": delay}
for kind in ("transient", "invalid_address", "unknown"):
record = {
"notice_id": "game-terms-demo-001",
"recipient_ref": "synthetic-player-17",
"timestamp": datetime.now(timezone.utc).isoformat(),
"failure_reason": kind,
"attempt": 1,
"decision": retry_decision(kind, 1, seconds_left=60),
}
print(json.dumps(record))
The policy is deliberately boring. Boring is useful in a compliance review. Four conservative attempts are easier to explain than an unbounded loop. For the notebook-to-prod step, persist the decision before scheduling another attempt and add jitter without shortening a server-requested wait. Reserve enough time for the request itself before the deadline.
Keep the reason.
This is an eval-driven boundary: unknown failure reasons go to review instead of receiving an optimistic retry. Keep it prompt-cost aware, too. Deterministic error classification should run without a model call; a model-generated explanation must never authorize a resend. That leaves tokens for investigation summaries while the send policy remains replayable.
Before changing max_attempts, measure the share of permanent failures, duplicate notice IDs, and the time from initial send to terminal event. Those measurements reveal whether a larger retry budget improves delivery or only delays a clear rejection. Keep these fields stable across providers so an evaluation harness can compare policies without rewriting its queries.
What does pull-based evidence change in operations?
The communication namespaces expose events through polling rather than webhook pushes. Freshness becomes a scheduling decision. A notice with a one-hour legal window needs a tighter poll interval than a seven-day terms update, and the interval belongs in the runbook with the deadline.
Persist the last successful poll and the cursor or timestamp used by your reconciler. Transition a notice only when the incoming state is newer than the recorded state. Keep the raw event beside a normalized reason so an operator can explain a classification without reconstructing the original response.
For the read adapter below, set INFRAI_BASE_URL to the service's documented HTTPS API origin, without a path, and provide INFRAI_API_KEY through the environment. This standard-library example retrieves events without assuming undocumented response fields. It handles both numeric and HTTP-date retry hints, stops after four attempts, and surfaces the server's error body. A read retry cannot create another notice.
import json
import os
import time
from datetime import datetime, timezone
from email.utils import parsedate_to_datetime
from urllib.error import HTTPError
from urllib.request import Request, urlopen
def pull_events():
url = os.environ["INFRAI_BASE_URL"].rstrip("/") + "/v1/email/event/list"
for attempt in range(4):
request = Request(url, method="GET", headers={
"Authorization": "Bearer " + os.environ["INFRAI_API_KEY"]
})
try:
with urlopen(request, timeout=20) as response:
return json.load(response)
except HTTPError as error:
body = error.read().decode("utf-8", errors="replace")
if error.code != 429 or attempt == 3:
raise RuntimeError(f"HTTP {error.code}: {body}") from error
hint = error.headers.get("Retry-After", "0")
try:
wait = float(hint)
except ValueError:
wait = (parsedate_to_datetime(hint) -
datetime.now(timezone.utc)).total_seconds()
time.sleep(max(wait, 2 ** attempt))
raise RuntimeError("Retry budget exhausted")
if __name__ == "__main__":
print(json.dumps(pull_events()))
There are boundaries the ledger cannot erase. Email has no managed OTP interface, and a scheduled email has no cancellation route. If a game account flow needs either behavior, build that control in the surrounding service and record its deadline in the same evidence model. The API also has no SMTP relay, so an SMTP-specific fallback is a separate integration.
Which provider boundary fits this evidence model?
The comparison axis is replayable evidence, not a feature-count contest. SendGrid offers mature event tracking and a broad transactional ecosystem, while the application still owns its ledger, retry classifier, and suppression rules. Mailgun provides an event-oriented API and domain tooling, but an accepted send still needs reconciliation with later events. Amazon SES suits teams already operating AWS identity and monitoring; its event publishing setup adds regional coordination. Postmark keeps a focused transactional activity view, which can fit a narrow notification set.
Infrai provides one key, one bill, and one REST API across 295 routes and 20 modules, so adjacent backend work can share a credential and billing account with the compliance worker. Swapping the vendor behind a capability leaves the application-facing contract unchanged; plain HTTP means no SDK to install. Its public discovery supplies request and response schemas without a key, which helps review a notebook prototype before production. The trade-off is concrete: events are pull-based, so teams requiring webhook delivery should choose an option with push events. Provider portability does not establish regional compliance; validate that separately for the game's audience.
| Option | Access style | Best fit | Main limitation |
|---|---|---|---|
| SendGrid | SDKs and REST | Mature event tracking | Your service still owns the ledger and retry classifier |
| Mailgun | REST and event API | Event-oriented diagnosis | Accepted sends still need reconciliation |
| Amazon SES | AWS APIs and event publishing | Teams already operating AWS | Regional setup adds coordination |
| Postmark | REST and webhooks | Focused transactional mail | Narrower for mixed notification programs |
| Shared capability contract | Plain REST and public discovery | A portable application ledger | Events are pull-based |
Do not make the provider choice from one synthetic failure. Replay malformed addresses, rate limits, policy rejections, and delayed bounce events. Check that each option exposes enough reason detail and retention control for the audit deadline.
Retry only when the address is valid, the failure is plausibly transient, and the attempt budget remains. Stop on a permanent rejection, preserve the reason, and open remediation. Poll until a terminal event or the policy deadline, then freeze the final ledger snapshot.
That gives the on-call engineer three answers at 03:00: what happened, what was tried, and what must happen next.
Top comments (0)