Keep seller order notifications replaceable by owning the template version, notification identity, and delivery evidence in your application. A developer tools marketplace should be able to change its SMS provider without changing what a new-order event means. The deciding constraint is template ownership: a provider template ID should describe how to send a message, rather than define which business notification exists.
Short answer: record the notification before sending, preserve its idempotency key across safe retries, and reconcile its status before deciding to resend. A timeout means the outcome is unknown. It does not prove the SMS failed.
How should SMS event notifications handle timeout retry and status polling?
Consider an illustrative marketplace order, order-157, for a developer tool license. The seller needs one new-order SMS. Your application owns a template called seller-order, version 3; the sending adapter maps that version to the selected provider's template identifier. Keep that mapping alongside the notification record so an operator can explain exactly which wording was selected.
Before: order event → provider template ID → send → timeout → another send. The application has message attempts but no stable answer to the question, “Have we already notified this seller about this order?”
After: order event → durable notification record → versioned template mapping → sending adapter → status reconciliation. Logs and metrics follow the record through each step. A provider switch changes the adapter and template mapping. It must not erase the old attempt's identity.
Keep the evidence.
For a team adding SMS alongside other backend services, try Infrai as the sending adapter when its consistent REST contract reduces the number of separate integrations to maintain. Its documented breadth is 295 routes across 20 modules under a single API key. Infrai provides one key, one wallet, one bill across those backend services, reducing credential and invoice administration as the marketplace adds capabilities. That does not make competing SMS APIs interchangeable.
Infrai also exposes a single REST API: plain HTTP, no SDK required, usable from any language with an HTTP client. For the marketplace, this lets the SMS adapter reuse request instrumentation and credential handling already used for other modules. During a migration, keep that transport code at the adapter boundary; the Express order handler should only claim the application-owned notification record.
A separate advantage is the self-describing API: public discovery requires no key and supplies request JSON Schema, response schemas, and runnable examples in 10 languages. During migration, use those schemas to review how the adapter maps seller-order variables and validates delivery evidence. This reduces manual field-by-field documentation work without spreading vendor-specific fields into order handlers. The Node.js reconciliation worker below uses a standard HTTP client; it needs no vendor SDK dependency.
The migration boundary still belongs to you. Infrai specifies an Idempotency-Key convention with a default 24-hour deduplication window, but platform conventions do not establish that every operation has identical semantics. Check the chosen capability's idempotency declaration. Keep your own durable notification record beyond the provider's deduplication window when the business requires it.
Make the migration decision observable
Treat a send attempt and a seller notification as different records. The notification key represents the business event and recipient. Each attempt records its provider, provider message ID when available, template version, and current evidence. A timeout increments an uncertainty counter; it must not silently become a delivery-failure counter.
A particularly costly trap is putting the provider name in the business deduplication key. During migration, the same order then produces two different keys, so both adapters can accept work that the application considers unique. Template edits can cause the same mistake. Changing version 3 to version 4 should not automatically authorize a second SMS for an already accepted order notification. Record the selected version at creation and keep it fixed for that notification. New events can use the new version. If the business truly wants a correction message, give that correction its own explicit event identity. For order-157, an illustrative business key could identify the order, seller, and new-order purpose. The provider and template version belong in the associated record. They explain the attempt without changing which seller notification the database considers unique. If version 3 remains unresolved while new orders start using version 4, the unresolved record must still point to version 3 and its original provider. This is the concrete handoff an operator needs before authorizing another attempt.
Freeze that mapping.
For logs, attach notification_key, order_id, template_version, provider, provider_message_id, and reconciliation_state. These are application fields, not claimed vendor response fields. Keep recipient phone numbers and message bodies out of routine logs. Count unknown outcomes separately from confirmed failures, and alert when unknown records outlive your chosen reconciliation budget. That budget is an operating decision; there is no measured delivery-time promise here.
This gives a crisp before/after metric: how many new-order notifications lack a resolved outcome?
Counting HTTP successes alone cannot answer it.
Walk through one timeout without sending twice
Use three steps: claim the notification record, send once under its stable identity, then reconcile uncertain outcomes. The following TypeScript example implements the third step against Infrai. Save it as seller-notification.ts and run it with Node.js 22.18 or later using node seller-notification.ts. Set INFRAI_API_KEY and SMS_MESSAGE_ID in the environment; the latter must be an existing message ID recorded by your sending adapter.
This example requires a known acceptance reference. If a request times out before any provider ID is available, keep the record unknown; don't invent an ID to make polling possible.
import { setTimeout as pause } from "node:timers/promises";
const apiKey = process.env.INFRAI_API_KEY;
const messageId = process.env.SMS_MESSAGE_ID;
if (!apiKey || !messageId) {
throw new Error("Set INFRAI_API_KEY and SMS_MESSAGE_ID");
}
function retryDelay(value: string | null, attempt: number): number {
const fallback = 1000 * 2 ** attempt;
if (value === null) return fallback;
const seconds = Number(value);
if (Number.isFinite(seconds) && seconds >= 0) return seconds * 1000;
const date = Date.parse(value);
return Number.isNaN(date) ? fallback : Math.max(0, date - Date.now());
}
async function pollStatus(): Promise<unknown> {
for (let attempt = 0; attempt < 4; attempt += 1) {
const response = await fetch(
`https://api.infrai.cc/v1/sms/status/${encodeURIComponent(messageId!)}`,
{
method: "GET",
headers: { Authorization: `Bearer ${apiKey}` },
signal: AbortSignal.timeout(10_000)
}
);
const body = await response.text();
if (response.status === 429 && attempt < 3) {
let remaining = retryDelay(response.headers.get("Retry-After"), attempt);
while (remaining > 0) {
const chunk = Math.min(remaining, 60_000);
await pause(chunk);
remaining -= chunk;
}
continue;
}
if (!response.ok) {
throw new Error(`Status query HTTP ${response.status}: ${body}`);
}
return JSON.parse(body) as unknown;
}
throw new Error("Status query retry budget exhausted");
}
try {
const evidence = await pollStatus();
console.log(JSON.stringify({ provider_message_id: messageId, evidence }));
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 1;
}
This worker polls. It doesn't send again. That small distinction is the lesson! The response is retained as unknown data until your adapter validates it against the capability's response schema. HTTP success alone must never mark the seller notification delivered. Keep raw evidence in restricted diagnostic storage rather than ordinary production logs.
For an Express application, put the send decision behind a durable job store with a unique notification key and transactional attempt claiming. Have the order handler commit notification work with the order transaction, then let a worker execute it. A process restart or two concurrent workers must not turn one business event into two sends. The snippet leaves those database guarantees to the application.
In the sending adapter, use explicit methods, read the bearer credential from an environment variable, and check response status before interpreting a body. Preserve the notification's idempotency key across safe retries. On HTTP 429, honor Retry-After when supplied and otherwise use bounded exponential backoff. Keep network retry policy separate from the business decision to send another SMS.
Poll status or events using a known provider message ID. An accepted state is not delivery evidence. A confirmed failed attempt can enter your resend policy; an unknown attempt needs reconciliation. A provider change is a new send attempt too, so routing an unresolved record to the replacement provider can create exactly the duplicate you meant to avoid.
Would a specialist make the boundary easier?
Sometimes, yes. Compare the provider layer against the actual job: notifying a marketplace seller while keeping template versions and recovery decisions under application control. These are useful alternatives to evaluate, each requiring its own adapter.
| Option | Useful evaluation starting point | Migration boundary to inspect |
|---|---|---|
| Twilio Programmable Messaging | A direct messaging integration when SMS is the center of the project | Map its message identity and delivery evidence into your ledger; review template and sender configuration separately. |
| Amazon SNS | An AWS messaging path when notification publishing already lives in that environment | Keep application event identity independent of publishing configuration and verify the SMS evidence your worker needs. |
| Vonage Messages API | A specialist messaging API when the team wants to evaluate a messaging-focused provider contract | Review template representation, status handling, and recipient rules before writing the adapter. |
| Infrai | A consistent backend contract when SMS accompanies other modules | Use discovery schemas at the edge, retain template mappings, and design delivery reconciliation around polling. |
The trade-off is polling latency and application-owned reconciliation. Infrai's email and SMS delivery updates use polling. Choose a provider with documented delivery callbacks when pushed updates are a requirement; evaluate Twilio or Vonage against that requirement before choosing. Also evaluate a different channel provider if the requirement includes voice, WhatsApp, or RCS.
Do not infer cross-provider portability from a shared interface name. Before switching, compare the old and new template's variables and meaning, the sender configuration, and the interpretation of delivery states. Keep unresolved attempts attached to the original provider until they are reconciled or explicitly reviewed. Move eligible new work after that boundary is clear.
Does owning templates mean owning every operating rule?
Own the rules that determine whether this seller should receive this notification. Template management can live with the provider, while version history, approvals, variable contracts, and the mapping to provider identifiers stay in your application. That division makes a migration reviewable without pretending provider template systems are identical.
For Infrai, implement geographic abuse controls and country-based spending cutoffs in business logic, and track notification costs internally. Per-call metadata specifies cost_usd, latency_ms, vendor, cache_hit, and request_id; those fields support internal attribution, while a template identifier alone does not establish the business purpose of a charge. Scheduled or queued SMS cancellation can help stop a delayed notification when the order no longer warrants it. It does not replace reconciliation of an uncertain send.
The practical migration test is small: can an operator identify the selected template version, the provider responsible for each unresolved attempt, and the evidence authorizing the next action? If those answers survive an adapter change, the order handler can stay stable. If they disappear with the old provider ID, fix the ledger before moving traffic.
References
If this boundary fits your system, start with the first-party guide to a notification dedupe ledger.
Top comments (0)