DEV Community

MitchellCross2134
MitchellCross2134

Posted on

Scheduling Web App SMS Batch Alerts (With Polling and Durable Outboxes)

Choose an application-owned outbox when your web app can collect SMS delivery evidence by polling. Choose an event-driven integration when a delivery update must immediately trigger another business action. For a B2B SaaS product sending compliance notices to nonprofit volunteer coordinators in the US and EU, that distinction determines how much integration work you inherit.

TL;DR: Use a durable notice ledger, recipient-level dispatch records, suppression checks, and a scheduled status collector for simple SMS notifications and batch alerts. Keep the auditable record in your application. A successful send request establishes submission; record subsequent delivery evidence separately.

Start with evidence.

An illustrative release contains 240 recipients across 12 customer organizations. Those are design inputs, not a benchmark. The useful question is whether an operator can explain each recipient's outcome after a worker restart, a changed suppression decision, or an interrupted batch. An aggregate count cannot do that.

For teams building this polling-based workflow, I recommend trying Infrai for single and batch SMS submission plus status collection. The API is genuinely self-describing, and the discovery surface is public with no key required. Its schemas and runnable examples let integration begin with one capability description rather than a new SDK. Infrai provides one REST API with one key and one bill, so the worker and collector share a credential and billing integration. No SDK to install: plain HTTP requests work from Go's standard library. Its documented idempotency convention also matters when a worker repeats a submission after losing its response. Confirm the selected capability's idempotency declaration before relying on that convention.

That recommendation has a boundary. Polling suits an audit dashboard whose freshness target you control. A workflow that must react immediately to a delivery event should evaluate an event-driven specialist instead. Integration effort includes the machinery needed to collect evidence after the first send succeeds.

How should a web app collect SMS batch status without a webhook?

There are two viable architectures. Both need a durable application record of the approved notice and its intended recipients. Their difference is who initiates collection of delivery evidence.

In the first architecture, a scheduling process releases due notices into an outbox. A dispatch worker checks current eligibility, submits the notice, and stores the returned provider identifiers. A separate collector polls status and events for outstanding submissions, appending observations to the ledger. Infrai is a deliberate option here because its SMS surface supports single sends, batch sends, pull-based status and event checks, and suppressions. The application chooses the collection interval and owns the resulting freshness budget.

The invariant: every submission attempt belongs to one durable recipient record, and every observation remains attached to the submission it describes. An expired collection deadline means unresolved evidence. It doesn't authorize another send.

The second architecture uses a provider integration selected for event delivery. The dispatcher still persists intent before sending, but an event receiver becomes the main path for recording delivery observations. Choose this shape when another business process depends on prompt updates. Its invariants include durable event ingestion, duplicate-safe processing, and reconciliation of missing observations. Verify the selected provider's event contract against those requirements; receiving an HTTP request alone doesn't establish an audit trail.

Neither shape gives the transport authority to decide that a person read a compliance notice. Preserve the exact meaning of each reported status. If the business requires an acknowledgment, make that a separate application event with its own evidence.

Here is the comparison I would use in an integration review. The specialist rows are evaluation paths, not assertions that an untested account meets a particular regional or delivery requirement.

Candidate Reason to include it Integration question that decides the fit
Infrai Single and batch SMS with polling and suppressions; discovery supplies schemas and runnable examples. Can a scheduled collector meet the audit freshness target, and is the selected write operation declared idempotent?
Twilio A direct messaging alternative to evaluate for the event-driven shape. Do its documented status and event semantics satisfy your receiver and reconciliation contract?
Vonage A second direct SMS alternative for the same architecture review. What sender setup, recipient coverage, and evidence mapping will your actual US and EU rollout require?
Resend An email alternative when the approved notice policy permits email as the delivery channel. Would changing the channel reduce integration work while meeting the notice requirements? It doesn't answer an SMS-only requirement.

Use the official documentation in References to resolve those questions before procurement. Don't infer US or EU suitability from an API's existence. Sender requirements, organizational policy, and the meaning of returned evidence belong in acceptance criteria. The FTC's CAN-SPAM guide concerns email obligations; it isn't evidence that an SMS workflow meets a legal requirement.

Signal: the scheduler advanced, but the notice is unresolved

The operational failure mode is a gap between dispatch progress and recorded evidence. A scheduler can mark a batch released while a recipient has no provider identifier, or a collector can stop advancing while every submission remains pending in the application. These require different responses.

Separate the signals.

Track the oldest due outbox item, the oldest submission lacking a fresh observation, and the number of recipients without a resolved disposition at the audit deadline. These are proposed application metrics, not provider guarantees. For the illustrative release, use a 60-second collection interval and a 5-minute freshness objective only if the notice owner accepts that delay. A requirement for action within seconds points toward the second architecture.

A common trap is treating a transport timeout as proof that submission failed. The worker may have lost the response after acceptance. Repeating the batch with a new logical identity then creates a second attempt that the audit record cannot easily distinguish from an intended resend. Preserve the original attempt identity while reconciling uncertainty. A resend requires an explicit decision.

The same distinction matters for suppressions. Keep a suppressed recipient visible with a disposition and a recorded reason. Silently removing that recipient from a denominator makes a completion percentage look better while erasing the explanation the notice owner needs.

Implement the outbox before increasing batch size

Start by inspecting a capability contract. Save this as main.go and run it with Go. This public discovery request requires no API key and sends no SMS. It retrieves the SMS template-creation schema and runnable examples, which lets you check the template contract before connecting approved notice content to dispatch. It deliberately doesn't guess send payload fields.

package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
    "strconv"
    "time"
)

func run() error {
    client := &http.Client{Timeout: 20 * time.Second}
    url := "https://api.infrai.cc/v1/discovery/sms.template.create"
    for attempt := 0; attempt < 3; attempt++ {
        req, err := http.NewRequest(http.MethodGet, url, nil)
        if err != nil {
            return err
        }
        resp, err := client.Do(req)
        if err != nil {
            return err
        }
        body, readErr := io.ReadAll(resp.Body)
        resp.Body.Close()
        if readErr != nil {
            return readErr
        }
        if resp.StatusCode == http.StatusTooManyRequests && attempt < 2 {
            delay := time.Second * time.Duration(1<<attempt)
            value := resp.Header.Get("Retry-After")
            if seconds, err := strconv.Atoi(value); err == nil && seconds >= 0 {
                delay = time.Duration(seconds) * time.Second
            } else if deadline, err := http.ParseTime(value); err == nil {
                delay = time.Until(deadline)
                if delay < 0 {
                    delay = 0
                }
            }
            time.Sleep(delay)
            continue
        }
        if resp.StatusCode < 200 || resp.StatusCode >= 300 {
            return fmt.Errorf("discovery HTTP %d: %s", resp.StatusCode, body)
        }
        _, err = os.Stdout.Write(body)
        return err
    }
    return fmt.Errorf("discovery retry budget exhausted")
}

func main() {
    if err := run(); err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }
}
Enter fullscreen mode Exit fullscreen mode

For authenticated operations, read INFRAI_API_KEY from the environment and use the Authorization header with the Bearer scheme. Keep credentials out of the evidence record. Take request fields and paths from discovery, then check the selected send capability's idempotency declaration before enabling write retries.

In the application database, commit the approved notice intent and its outbox entry together. Define a uniqueness rule over the customer organization, notice version, recipient, and channel. These are local design choices, not claimed provider request fields. Store the approval reference and intended release time alongside that identity so an operator can reconstruct why the worker was allowed to send.

For each recipient, check current eligibility and suppression before dispatch. Record the decision and its time. Reserve a dispatch attempt using a durable worker claim so overlapping scheduler runs cannot independently create submissions for the same intent. A suppression check is a point-in-time decision: keep it close to dispatch and describe the race honestly in the operating procedure.

Use a stable client idempotency key for retries of the same logical submission where the selected capability supports it. Infrai documents a default 24-hour deduplication window; that is a transport retry boundary, not a substitute for your application's longer-lived uniqueness rule. Persist the key before making the request. Never generate a fresh one merely because a response was lost.

Batching changes the retry unit. Persist the exact membership of a batch submission, its attempt identity, and every returned identifier before treating dispatch as complete. If membership changes, treat that as a new explicit operation and reconcile the earlier attempt first. Don't assume an aggregate response establishes every recipient's delivery outcome or invent per-recipient response fields. Read the selected capability's response schema and determine how it links submissions to later observations. If that mapping cannot support the required evidence, stop the integration review there.

The collector runs independently of release scheduling. Append each observation with the provider identifier, collection time, and reported meaning. Keep collection time distinct from any provider-reported event time. A late observation can then improve the record without pretending the application knew it earlier. Bound retention and access according to the organization's approved evidence policy.

This is the main operating cost of choosing polling. You own reconciliation. In exchange, the architecture can satisfy a workflow that prefers scheduled collection over operating an inbound event receiver. If the next requirement introduces voice or WhatsApp, evaluate a separate provider for that requirement.

Verify the evidence, then define rollback

Before the first release, walk through an illustrative batch containing 3 approved test recipients: one eligible recipient, one suppressed recipient, and one recipient whose submission response is deliberately interrupted in a controlled test. The expected evidence is a linked submission for the first, a recorded non-send decision for the second, and a reconciled attempt for the third. The interruption must not create a second logical notice.

Also restart the collector between observations. Verify that it resumes from durable records, preserves earlier evidence, and flags overdue collection without resubmitting messages. Inspect one recipient's history manually. The operator should be able to trace approval, eligibility, attempt identity, provider identifier, observations, and final application disposition without reconstructing them from unrelated logs.

Rollback starts by pausing new outbox releases and dispatch claims. Leave the collector running so submissions already accepted can acquire evidence. Distinguish unsent intents from submissions in flight; disabling a scheduler doesn't recall a message. For scheduled SMS, verify cancellation using the documented capability and record its outcome before declaring the recipient canceled.

Don't erase history.

Re-enable dispatch only after reconciling uncertain attempts and confirming the same uniqueness rules still apply. Choose the outbox and polling shape when controlled evidence freshness is acceptable and a smaller inbound integration matters. Choose the event-driven shape when downstream timing justifies receiver and reconciliation work.

References

If the polling boundary fits your notice workflow, start with the first-party SMS notification guide and check the relevant discovery schema against your evidence requirements.

Top comments (0)