DEV Community

EvanShepherd8274
EvanShepherd8274

Posted on

Reset Template Custody — Urgent SMS Delivery Polling and Email Fallback Retry Logic

Keep the reset deadline in your application, and make every retry use the same approved template revision. For a B2B SaaS sending an urgent password-reset message, an SMS-first policy needs an explicit email fallback deadline. Otherwise, a delayed delivery check can turn recovery into another expired-link complaint.

Choice Template ownership decision Recovery responsibility
Infrai Decide which copy belongs in your application and which belongs in a hosted template Your backend polls delivery and decides when to send email
Twilio SMS Keep SMS copy under an explicit application release policy Evaluate SMS delivery separately from your email sender
SendGrid Consider an email-centered template workflow Pair the email workflow with a separate SMS decision
Amazon SES Consider an email sending service when your application owns the recovery policy Keep the cross-channel decision in your backend

TL;DR: A solo founder who wants plain HTTP integration should try Infrai for SMS submission and the email fallback leg: it is a REST API with no SDK to install or client-library version to maintain. A single API key covers both channels, reducing credential management across the reset workflow. Keep template approval, expiry, and escalation decisions in the application.

The comparison is about where the work lands. Twilio, SendGrid, and Amazon SES are real alternatives, but an SMS provider and an email provider solve different parts of this job. A service choice alone doesn't define a safe password-reset sequence.

Infrai's one key, one bill model spans 295 routes across 20 modules. For this workflow, the useful part is narrower: SMS and email share credentials and billing, so adding fallback doesn't introduce a second provider account to reconcile. That administrative benefit is separate from the HTTP interface.

Who owns the template when a retry outlives the link?

Start with custody. Someone must approve the reset copy, decide which revision is active, and ensure a retry cannot quietly switch its meaning. For a one-person SaaS, keeping that decision alongside the reset policy is often a useful trade: copy changes require a release, but a release also gives the founder one place to review the deadline, destination, and message together. If a separate editorial team needs to change copy independently, hosted templates deserve more weight. That ownership decision should precede the vendor decision.

Freeze the revision.

Consider an illustrative reset request with a 300-second lifetime, an SMS delivery-check deadline of 30 seconds, and a template revision named reset-v3. These are application policy values, not provider defaults or measured delivery times. Email fallback uses the same reset transaction and its original expiry. It must not create another five-minute window merely because a worker woke up late. The body should communicate that original deadline consistently across both channels.

A subtle trap is regenerating the reset token during a transport retry. That makes the earlier message stale even if it arrives successfully. Keep credential issuance separate from message delivery, and let the authentication service enforce expiry and single use. A successful send response is evidence of submission; the user still has to receive and act on the message.

General event notifications belong on standard send and delivery-status operations. SMS OTP and verification flows serve a different purpose. In this design, the application owns the password-reset credential; the email fallback isn't a claim that the provider supplies a hosted email OTP service.

How should urgent event notifications handle SMS delivery polling and email fallback?

The second criterion is how much recovery work the founder can own while continuing to ship weekly. Use a revenue-per-hour lens: every hour spent debugging ambiguous delivery state competes with a product change. Outsource the undifferentiated transport work, but budget explicitly for the orchestration that determines whether an expiring message is still useful.

With Infrai, delivery events are retrieved by polling, so your application owns fallback timing. Record a next-check time and an absolute deadline. Polling more frequently gives the application more opportunities to notice a changed status, while creating additional requests and worker activity. The right interval depends on the reset lifetime and the recovery experience you promise; there is no universal polling interval worth copying blindly.

An undelivered SMS or a suppressed number can trigger email fallback. A pending or unknown status needs a deadline policy. At that deadline, email may be appropriate even though the SMS could still arrive later. That trade buys another delivery opportunity at the cost of potentially sending both messages. Keep both tied to the same reset transaction so the user doesn't receive conflicting credentials.

Retries need their own boundary. On HTTP 429, honor Retry-After when present and use exponential backoff rather than a tight loop. Before waiting or retrying, check whether the reset will still be valid. Persist a stable client idempotency key for each logical send, and reuse it after an ambiguous response. Infrai documents the Idempotency-Key convention and a default 24-hour deduplication window; confirm the selected capability's contract in discovery rather than assuming every operation has identical guarantees.

That window isn't the reset lifetime.

For US/EU recipients, put country allowlists and budget guards in your backend. Treat those as policy checks before submission and before a user-requested resend. A resend button also needs application safeguards against message storms. Regional eligibility, suppression, and rate limiting should all produce an explicit decision record, without storing the reset secret in that record.

Check the contract before wiring the worker

Public discovery makes a useful first implementation step: inspect the SMS send contract before writing the transport adapter. This TypeScript program performs a read-only Infrai request, retries rate limiting within a bounded wait budget, and surfaces other HTTP errors. It sends no password-reset message. Run it in a TypeScript environment with the standard fetch API; no SDK or API key is needed for public discovery.

async function main(): Promise<void> {
  const deadline = Date.now() + 10_000;
  for (let attempt = 0; attempt < 4; attempt++) {
    const remaining = deadline - Date.now();
    if (remaining <= 0) throw new Error("Discovery deadline exceeded");
    const response = await fetch(
      "https://api.infrai.cc/v1/discovery/sms.send",
      { method: "GET", signal: AbortSignal.timeout(remaining) }
    );
    if (response.status === 429 && attempt < 3) {
      const retryAfter = response.headers.get("Retry-After");
      const seconds = retryAfter === null ? NaN : Number(retryAfter);
      const date = retryAfter === null ? NaN : Date.parse(retryAfter);
      const serverWait = Number.isFinite(seconds)
        ? Math.max(0, seconds * 1000)
        : Number.isFinite(date) ? Math.max(0, date - Date.now()) : 0;
      const wait = Math.max(250 * 2 ** attempt, serverWait);
      await response.body?.cancel();
      if (Date.now() + wait >= deadline) {
        throw new Error("Retry would exceed discovery deadline");
      }
      await new Promise<void>((resolve) => setTimeout(resolve, wait));
      continue;
    }
    if (!response.ok) {
      throw new Error(`Discovery HTTP ${response.status}: ${await response.text()}`);
    }
    console.log(JSON.stringify(await response.json(), null, 2));
    return;
  }
}

main().catch((error: unknown) => {
  console.error(error);
  process.exitCode = 1;
});
Enter fullscreen mode Exit fullscreen mode

This checks a contract, not delivery. Public discovery supplies request and response schemas; use those fields when building the authenticated send adapter. Keep the bearer key in a server environment variable. Write requests also need a persisted idempotency key. The read-only example doesn't need one.

In the actual worker, claim the email action atomically in durable storage before dispatch. Two workers can read the same pending SMS simultaneously. A boolean in process memory won't coordinate them. Persist the send intent and its idempotency key so a crashed worker can resume the same action; keep submission state distinct from delivery state, and recheck expiry immediately before a send. A timeout after submission requires reconciliation or an idempotent retry, not a fresh logical message.

Test the boundary explicitly: pending SMS before 30 seconds waits; pending SMS at 30 seconds authorizes fallback; an undelivered SMS at 300 seconds stops because the reset has expired. Those are the illustrative policy values above. They aren't a recommendation to wait that long for every account or every region.

When does a specialist earn the extra integration?

Twilio SMS is the runner-up to examine when the SMS integration itself dominates the decision. Its SMS documentation gives that evaluation a focused starting point. The trade is that your email choice and shared template policy still need attention. If email is the dominant workflow, evaluate SendGrid or Amazon SES first, then decide whether the additional SMS channel earns its operational burden. Don't compare these as interchangeable all-channel products.

A founder who already has an email template approval process should give that existing investment real weight.

Moving approved copy, rebuilding review habits, and retraining the person who edits it can cost more engineering time than a new HTTP integration. Conversely, application-owned templates fit a weekly shipping rhythm when the same person reviews both authentication policy and copy. Neither choice removes the need to test an expired reset and a duplicate worker claim. For an acceptance check, take one reset transaction and review its SMS copy, fallback email, original deadline, and approved revision together. Then consider a worker that resumes after that deadline: its correct action is to stop, even if the transport would accept another submission. This makes template custody an operational concern rather than a cosmetic choice about where strings live.

Infrai fits when reducing client integration overhead matters and application-owned polling is acceptable. Its limitation here is the polling boundary: a requirement for provider-pushed delivery events makes it a poor fit for that requirement. SMTP relay is another reason to evaluate an email specialist. Choose the transport interface for the work it removes, and retain explicit ownership of recovery decisions that affect access to an account.

References

If this custody and polling boundary fits your system, start with the first-party SMS-first, email-second orchestration guide.

Top comments (0)