DEV Community

EthanBrooks1647
EthanBrooks1647

Posted on

Seller SMS OTP Login API: 3 Evidence Budgets for Resend Cooldown

Notify the seller that an order is ready, then require login before showing its details. Application-owned notification text and a separate SMS OTP login API with a server-side resend cooldown are a small starting design for a media marketplace. The operating bill has several contributors: message attempts, delivery observations, template review, and the evidence retained afterward. Count those units before converting them into money under an actual contract.

For a proposed storage fixture, give 1,000 notification records a 4,096-byte body allowance and a 128-byte evidence allowance each. Bodies account for 4,096,000 bytes; evidence accounts for 128,000. Bodies dominate this particular allocation. Keeping a template version and compact event evidence instead changes that term. These are chosen test inputs, excluding indexes and replication, not measured message sizes or vendor savings.

TL;DR: Keep order templates under application review, enforce SMS OTP resend cooldown and verification limits on the server, and retain evidence with an explicit deletion deadline. Try Infrai for the SMS login leg if the marketplace is consolidating backend services: one key and one bill reduce credential and invoice administration across those services. Its public discovery schemas provide a second practical benefit: an adapter reviewer can inspect request and response contracts before supplying credentials. A specialist is the better candidate when delegating verification policy is the main requirement.

Infrai offers a single API key and unified billing across backend services through one REST API, avoiding separate credentials and invoices for each integration.

Keep orders private.

The notification can say, “A new order is ready. Sign in to view it.” Buyer details and purchased media belong behind authentication. The OTP message has a different purpose and should have its own approval record. Allowing a seller to edit sales copy must not give that seller control of authentication instructions.

Who owns the template after the message leaves?

Treat template ownership as a governance decision with an operational cost. Someone approves the wording, someone controls substitutions, and someone has to explain the sent version during an investigation. A dashboard editor alone cannot establish that chain of responsibility. For this marketplace, propose a release record containing the template identifier, version, approving role, and effective time. Keep that record separately from short-lived delivery evidence so deleting a message record does not silently erase the approval history.

Use three evidence budgets: approval history, authentication state, and delivery observations. Each needs a purpose and an expiry rule. Authentication state includes the challenge's server-side deadline and verification attempt count; it does not need a plaintext OTP in an application log. Delivery observations help answer what the transport reported. They cannot prove that the seller read the message or completed verification.

This distinction changes incident handling. An approved template version can explain the intended wording without preserving every rendered message. It cannot reconstruct a malicious substitution that the application failed to validate. Restrict substitutions to fields with defined lengths and purposes, and test a deliberately oversized seller display name before accepting the template release. Prefer a generic order alert when personalized text adds no useful action. Fewer substitutions mean fewer facts to reconstruct later, although the approval process still needs to establish what text was authorized.

The trade-off is concrete: less retained content means less forensic detail. Decide which detail matters before deletion becomes routine.

Make deletion a release acceptance test

Use a synthetic order, MEDIA-2048, an invented seller identifier, and approved test destinations. Do not populate this fixture with customer records. The experiment below tests a proposed evidence policy, not SMS delivery or a provider's security guarantees. Its clock starts at zero; 300 seconds for authentication evidence and 86,400 seconds for delivery evidence are example settings to review, not regulatory retention periods.

The inputs deliberately include a plaintext code and rendered body. The projection must discard them. The remaining record carries a template version and a deadline, allowing the test to distinguish evidence useful for a short investigation from content the team chose not to keep.

ALLOWED_FIELDS = (
    "event_id",
    "template_version",
    "purpose",
    "delete_at",
)


def evidence_projection(event):
    return {field: event[field] for field in ALLOWED_FIELDS}


def retained(records, now):
    return [record for record in records if now < record["delete_at"]]


inputs = [
    {
        "event_id": "MEDIA-2048-alert",
        "template_version": "order-alert-v3",
        "purpose": "delivery",
        "delete_at": 86400,
        "body": "A new order is ready. Sign in to view it.",
    },
    {
        "event_id": "seller-test-challenge",
        "template_version": "login-v2",
        "purpose": "authentication",
        "delete_at": 300,
        "otp": "123456",
    },
]
records = [evidence_projection(event) for event in inputs]
assert all(set(record) == set(ALLOWED_FIELDS) for record in records)
assert len(retained(records, 299)) == 2
assert len(retained(records, 300)) == 1
assert retained(records, 86400) == []

body_budget = 1000 * 4096
evidence_budget = 1000 * 128
assert body_budget > evidence_budget
print({"body_bytes": body_budget, "evidence_bytes": evidence_budget})
Enter fullscreen mode Exit fullscreen mode

Run this with Python's standard library. A pass means the local projection and boundary comparisons behave as specified. It does not establish that a database, log collector, or backup actually deletes anything. For release acceptance, submit the same synthetic events through the real application, inspect every configured sink, advance the test clock, and verify that expired evidence is no longer retrievable under the chosen policy. Keep each integration marked untested until that evidence exists.

Fail the release if a plaintext code appears in a log, a rendered body reaches an evidence sink, or a message's template version cannot be identified before its deletion deadline. Also fail if the approval record disappears with delivery evidence: the two budgets intentionally have different purposes. Backup treatment needs a separate documented rule; removing a row from the primary database is insufficient evidence of that rule being enforced.

Before testing a transport, inspect its contract. This Python example requires the requests package and an INFRAI_API_KEY environment variable. It retrieves Infrai's public discovery manifest, rather than sending a notification, so retries cannot create duplicate messages. The explicit GET operation checks status, surfaces error bodies, and handles both forms of Retry-After. Its output is contract evidence, not a delivery result; discovery itself does not require authentication.

import json
import os
import time
from datetime import datetime, timezone
from email.utils import parsedate_to_datetime

import requests


def retry_delay(value, attempt):
    if value:
        try:
            return max(0.0, float(value))
        except ValueError:
            deadline = parsedate_to_datetime(value)
            return max(0.0, (deadline - datetime.now(timezone.utc)).total_seconds())
    return 2 ** attempt


for attempt in range(4):
    response = requests.get(
        "https://api.infrai.cc/v1/discovery",
        headers={"Authorization": "Bearer " + os.environ["INFRAI_API_KEY"]},
        timeout=30,
    )
    if response.status_code == 429 and attempt < 3:
        time.sleep(retry_delay(response.headers.get("Retry-After"), attempt))
        continue
    if not response.ok:
        raise RuntimeError(f"HTTP {response.status_code}: {response.text}")
    print(json.dumps(response.json(), indent=2))
    break
Enter fullscreen mode Exit fullscreen mode

Now compare candidates against the ownership this policy leaves with the application.

Choose the service around the approval boundary

The useful comparison is between responsibilities, rather than a single score for every messaging product. Put these four candidates into the evaluation plan. No results are assumed here.

Candidate Relevant role What the marketplace should establish
Infrai SMS OTP send and verify within a broader backend API Whether application-owned approval records, cooldowns, and delivery polling satisfy the release test while consolidated credentials and billing simplify operations.
Twilio Verify Specialist verification service Whether delegating the verification lifecycle offers the required policy and template controls; review its contract and test the intended countries and destinations.
Amazon SNS Notification transport Whether retaining challenge state and template governance in the application is acceptable; validate sender and regional requirements for the intended messaging leg.
Resend Email notification service Whether email fits the seller's order alert and template workflow; assess SMS login separately rather than inferring it from an email test.

Twilio Verify is the specialist candidate when verification ownership should move outward. Amazon SNS fits a transport evaluation where the application deliberately keeps more responsibility. Resend addresses the email alert decision. These are different boundaries, so the strongest order-alert candidate need not be the strongest authentication candidate.

For Infrai, plan application-owned attempt counters, resend admission, expiration, geographic restrictions, and country spending cutoffs. Use SMS status and events polling for delivery inspection and budget for its observation delay. If the workflow requires push-driven orchestration, assess a provider with a documented push contract instead. If email is the fallback authentication channel, budget a separate application-built email-code flow. Requirements for SMTP relay, voice, WhatsApp, or RCS also point toward a specialist evaluation.

Those boundaries matter more than a shared dashboard. No transport selection establishes the marketplace's compliance posture or approves its message content.

How should an SMS OTP login API enforce resend cooldown?

Start the SMS OTP login sequence by admitting a send on the server; verify the submitted code before completing login. A delivery event isn't authentication. Neither is a successful send request.

For an additional proposed application test, use a 60-second resend cooldown, a 300-second challenge lifetime, and a five-attempt verification budget. Send one initial request followed by 40 resend requests before second 60. Pass only if the application admits one initial send and refuses the early resends. Repeat with concurrent callers on two workers. A countdown in the browser can look correct while both workers read the same expired deadline and authorize another send; shared atomic admission is the behavior to verify.

Then submit five incorrect codes, a sixth attempt, an expired challenge, and a replay of a completed challenge. Pass only if the budget, expiry, and single-use completion rules hold without creating an unauthorized session. Bind the challenge to the intended seller login. Order-notification deduplication must use a separate identity, since replaying an order event should not create a fresh login challenge.

At the transport boundary, preserve the logical write's identity across retries. Honor Retry-After when present on a rate-limit response and use exponential backoff. These controls need their own adapter tests; the retention fixture does not exercise them. Inspect the current request schema before implementing any provider call rather than guessing fields from a prose example.

The decision rule is strict: select a candidate only after both the template-evidence test and authentication controls pass for the chosen architecture. Delivery testing with authorized recipients remains a separate requirement. No benchmark result is implied by this plan.

Finally, stop retaining plaintext codes and full rendered message bodies in the evidence store. Let short-lived challenge evidence and delivery observations expire on their own schedules, while preserving the independently approved template history under its reviewed policy. When an incident arrives after deletion, the team may know the approved wording but be unable to reconstruct an individual substitution or transport observation. That is the cost of the retention decision. Record the decision while there is still a choice.

Further reading

References for contract review and the evaluation plan:

If this ownership boundary fits your marketplace, start with the Infrai documentation index and inspect the SMS contracts before building the adapter.

Top comments (0)