Fetch SMS delivery status events through a bounded reconciliation worker, and keep its evidence separate from the payment settlement record. For a B2B SaaS order receipt, the operational rule is straightforward: a settled payment can authorize a receipt, but an unconfirmed receipt must never cause the collector to settle the payment again or silently send another message.
TL;DR: Persist the receipt-to-message correlation before collecting status, limit each collection pass, and advance the checkpoint only after the fetched evidence is durable. If the collection budget expires, retain an unresolved receipt and resume later. This is the reliability contract to establish before writing a Node.js code example for fetching SMS delivery status events via API.
Keep evidence separate.
There is a source boundary here: RFC 7208 specifies SPF for email sender authorization; it does not define an SMS event API, its status vocabulary, pagination, or delivery guarantees. The implementation below therefore uses an illustrative internal contract in Go. A Node.js service can implement the same collection sequence, but an executable JavaScript integration requires the selected API's documented authentication, response schema, cursor semantics, and status definitions. Guessing those fields would produce a convincing example with an unverified reliability claim.
When should receipt code start fetching SMS delivery status events?
Put the receipt into reconciliation after the application has a durable association between its settled order and the message identifier returned by its sending integration. Treat the payment record as the authority for payment state, and the receipt record as the authority for notification work. This is a proposed application invariant, not a claim about a particular messaging service. It gives an operator two independent questions to answer: did the payment settle, and what evidence exists for the receipt?
For an illustrative fixture, use order order-260, settlement reference settlement-260, receipt receipt-260, and message message-260. Those are invented test identifiers. Store the relationship in the application; do not expect an SMS event to reconstruct a business transaction from a phone number or message body. A second receipt for the same order needs its own identity so an operator can distinguish an intentional resend from repeated observations of the original message.
The signal that warrants investigation is an aging unresolved receipt.
Define its age from the application's recorded eligibility time, then compare it with the receipt SLO chosen by the business. Keep collection health visible alongside that age: a worker that has stopped fetching and a worker that keeps fetching without finding conclusive evidence require different investigations.
An empty page settles neither question.
Before mapping a remote status into a local terminal state, obtain the API's definition of that status and decide what evidence the business actually needs. This runbook deliberately assigns no universal meaning to words such as accepted or delivered. If the contract does not establish that a status proves the required outcome, preserve the status as evidence and leave the business outcome unresolved.
Bound the fetch before granting it production capacity
The collector should have a deadline, a page budget, and a limit on concurrent receipt jobs. These are separate controls. A deadline bounds elapsed time for a cooperative fetch implementation; a page budget bounds iteration; concurrency bounds how many jobs can consume the collection pool together. None of them, by itself, specifies how much data a single API response may contain. Require a response-size limit in the adapter too.
Don't hide retries.
Consider a proposed test configuration of 4 concurrent jobs and at most 3 pages per pass. One full wave can initiate at most 12 page fetches if each page uses one request and the adapter performs no hidden retries. That is arithmetic for this configuration, not a provider quota or a throughput benchmark. Request latency, payload size, and persistence time still determine how quickly the queue drains. Capacity planning should count any adapter retries against the same request allowance, otherwise the number written in the runbook describes only the outer loop.
Reserve capacity for newly eligible receipts while old unresolved work is being reconciled. A large historical queue should not consume the entire receipt-processing budget. An SLO for receipt timeliness is difficult to defend if the only scheduling policy is to keep retrying the oldest item forever, especially when that item's evidence remains inconclusive. Choose an expiry or escalation policy explicitly, and preserve the reason for that decision.
Polling has limitations: it is not suitable for an SLO that requires evidence sooner than the configured collection interval permits. The trade-off is explicit scheduling and replay control versus delayed observation and repeated request work. Evaluate an authenticated event-push interface if the selected API documents one and the receipt SLO requires it; retain reconciliation only where its additional recovery coverage justifies the operational load.
Implement a durable collection pass
The following code defines application interfaces, not a real remote endpoint. The Source implementation must translate documented API behavior into this contract, honor cancellation, enforce response limits, and account for retries. Its empty next cursor means that this pass has reached the end of available pages. The Store implementation must atomically persist events and the next cursor; a failed commit must leave the previous checkpoint usable. Serialize passes for each message, or enforce checkpoint concurrency in storage.
package receipts import ( "context" "errors" "fmt" ) type Event struct { ID string Status string } type Page struct { Events []Event Next string } type Source interface { Fetch(ctx context.Context, messageID, cursor string) (Page, error) } type Store interface { CommitPage(ctx context.Context, messageID, cursor, next string, events []Event) error } var ErrPageBudget = errors.New("collection page budget exhausted") func Collect( ctx context.Context, source Source, store Store, messageID, cursor string, maxPages int, ) error { if messageID == "" || maxPages < 1 { return errors.New("message ID and positive page budget required") } if _, ok := ctx.Deadline(); !ok { return errors.New("collection deadline required") } seen := map[string]bool{cursor: true} for n := 0; n < maxPages; n++ { if err := ctx.Err(); err != nil { return err } page, err := source.Fetch(ctx, messageID, cursor) if err != nil { return fmt.Errorf("fetch receipt evidence: %w", err) } if page.Next != "" && seen[page.Next] { return errors.New("pagination cursor repeated") } if err := store.CommitPage( ctx, messageID, cursor, page.Next, page.Events, ); err != nil { return fmt.Errorf("persist receipt evidence: %w", err) } if page.Next == "" { return nil } seen[page.Next] = true cursor = page.Next } return ErrPageBudget } A nil return means that the bounded pass persisted all pages it reached through the contract. It does not mean the receipt was delivered. Keep that distinction in the caller, where the evidence is evaluated against an explicit status mapping. Likewise, ErrPageBudget means collection needs another scheduled pass using the durable checkpoint; it is not permission to resend the receipt.
The difficult implementation is CommitPage. Under the proposed contract, replaying a fetched page must not create duplicate business actions, and committing the cursor without its evidence is forbidden. If the chosen API documents stable event identifiers, the adapter can expose them for deduplication. If it does not, decide how repeated observations will be stored before shipping the adapter; the ID field above does not manufacture a remote uniqueness guarantee. Store the raw status alongside any normalized interpretation so a mapping change remains auditable. Consider a recovery fixture in which receipt-260 has a committed starting position, the next fetch returns two observations, and the process stops before the storage transaction commits. On restart, the expected result is the old position and neither new observation; the next fetch is allowed to replay that work. Now move the simulated stop to immediately after commit. The expected result changes to both observations and the new position. A state containing the new position but neither observation fails the acceptance criterion, because the application has acknowledged collection progress without retaining the evidence it was supposed to collect. This example specifies a test, not an incident or a guarantee about a remote API.
Make that transaction boring.
There is another boundary the loop cannot solve: whether a saved cursor remains valid for a later pass. Verify that in the API documentation. If pagination cursors are temporary, implement a documented replay strategy with a durable reconciliation position instead of persisting an unusable token. The code is a small contract to review, not evidence that every SMS API supports it.
Decide what to buy and what to own
For the platform roadmap, separate transport operation from the application policy that connects a settled payment to receipt evidence. Evaluate both managed and self-hosted designs against the same acceptance criteria. A short setup path does not answer who handles an unresolved receipt during an on-call shift.
| Decision | Managed transport evaluation | Self-hosted transport evaluation | Application responsibility |
|---|---|---|---|
| Status evidence | Require documented meanings, retrieval, and retention | Budget implementation and operation of those contracts | Map evidence to the receipt SLO |
| Recovery | Verify replay and cursor behavior | Design and test replay behavior | Persist correlation and checkpoints |
| Capacity | Verify documented limits and retry rules | Plan worker, storage, and queue capacity | Reserve capacity for fresh receipts |
| Operational ownership | Establish escalation and evidence access | Assign deployment and on-call ownership | Define resend authority and audit decisions |
This is a buy-vs-build checklist, not a product ranking. Compare engineering time, on-call coverage, retention needs, and the effort required to replace an adapter. The useful boundary is one that lets the application retain its receipt evidence and policy while changing how that evidence is fetched; whether a candidate actually meets that boundary requires its technical documentation and a recovery test.
Verify recovery, then deploy with a reversible boundary
Test the settlement-to-receipt fixture before a rollout. Return a page twice and verify that persistence preserves the evidence without triggering another send. Fail persistence after fetching a page, then restart from the last committed checkpoint. Feed the collector a repeated cursor and confirm it stops. Supply more pages than its budget permits and verify that the next scheduled pass uses the saved position. These are proposed acceptance tests, not reported production results.
Test silence too. An empty page must not mark receipt-260 delivered, and a fetch error must not alter settlement-260. Include cancellation and an undocumented status in the fixture set. The expected result for unfamiliar evidence is preservation and an unresolved outcome until an approved mapping exists.
No automatic second send.
Deploy collection separately from automatic resend decisions. First observe it with permission to record evidence, then enable reviewed status mappings for a limited cohort. Track oldest unresolved receipt age, pending count, fetch failures, persistence failures, and budget exhaustion. Define the SLO numerator using the receipt outcome the business approved, rather than the number of successful HTTP requests. A collector can fetch successfully while every receipt remains unresolved.
Rollback should disable the new collector or mapping while preserving its evidence, checkpoints, and payment correlation. Drain or cancel active jobs before changing checkpoint ownership; restarting two collectors against the same message requires the concurrency protection described above. Resume only after replaying the recovery fixtures against the replacement implementation.
The release decision is concrete: ship when a settled order can survive a failed collection pass and recover its receipt evidence without creating another payment action or an unauthorized resend. That is a useful reliability threshold for an API example, and a much stronger one than a successful fetch on the happy path.
References
- RFC 7208, Sender Policy Framework (SPF): email sender authorization scope; it does not specify SMS status retrieval. https://datatracker.ietf.org/doc/html/rfc7208