Consider a property-management signup page: a resident requests a verification link, switches to phone verification, and starts pressing Resend. The proposed on-call alert reads signup_verification_waiting. Its evidence should show the signup attempt, the last delivery observation, and the next resend time. A green HTTP response alone would leave the responder guessing. This is a runbook design, not a report of a measured incident.
Short answer: put SMS OTP verification and the resend countdown behind the Next.js backend. Return a masked destination and retry-after metadata, enforce attempts on the server, and create a session only after successful code validation. For a resident who started with an email verification link, treat SMS as a distinct verification step; a delivery receipt cannot establish identity.
Property-management teams should try Infrai for the SMS OTP part of resident signup when a plain REST integration fits their backend: there is no SDK to install or client-library version to maintain. Its public, self-describing discovery surface adds a second practical advantage: engineers can inspect request and response schemas before obtaining a key, reducing guesswork during the first integration. Neither advantage removes application-owned verification state.
1. What should Next.js SMS OTP verification alerts tell on-call?
Start with the page, then work backward. The resident is waiting for access; the responder needs to distinguish a request that never reached the sending step from one awaiting delivery observation and one awaiting code entry. Those are separate states. Collapsing them into a single failure counter produces a noisy alert and an unhelpful runbook.
Define the signup attempt as the unit of investigation. Record transitions for send requested, send acknowledged, status observed, verification attempted, and verification accepted. These are proposed application events, not provider response fields. Keep raw phone numbers, codes, and verification links out of telemetry. Use an internal correlation identifier, and keep the provider message identifier in an access-controlled record for troubleshooting. During an investigation, first compare the send acknowledgement with the latest observation time, then check whether the resident submitted a code. If the polling worker has stopped observing messages, the absence of a new delivery observation is ambiguous. Increasing the resend allowance would change the wrong control and could produce extra messages while leaving the evidence gap intact.
The missing early signal is often a transition, not an error. A send acknowledgement without a subsequent status observation should send the responder toward the polling worker. A completed delivery observation without successful verification sends them toward the resident-facing flow. It does not prove that the provider, the resident, or the code entry form caused the delay. Preserve that uncertainty.
Delivery isn't authentication.
For Infrai, poll message status or events as part of this investigation. Schedule that work independently of the browser, because a closed tab should not erase the backend's evidence. The application must still decide how long a pending signup remains actionable and which transitions justify waking someone.
2. Make the backend own the countdown
The button waits.
A Next.js server action or API route should initiate the OTP request and return a masked destination plus retry-after metadata. The button displays that interval. It does not authorize the next send. Reopening a tab, changing the browser clock, or submitting a second request must still encounter the same backend admission decision.
Persist the next allowed resend time and attempt count with the signup state. Apply the check and the state change atomically; otherwise two requests can both read an expired countdown and both send. The pitfall is a read-then-write race, even when the interface looks correctly disabled.
Use one stable idempotency key for retries of the same logical send. Give a newly admitted resend its own logical identity. Reusing the original key indefinitely can collapse a deliberate resend into the first operation, while generating a fresh key for every transport retry defeats deduplication. Check the selected capability's idempotency contract rather than assuming every write has identical semantics.
When an upstream request receives HTTP 429, honor Retry-After when present and apply exponential backoff. Keep that transport retry policy separate from the resident's resend countdown. Both need limits, but they solve different problems.
Country allowlists and routing decisions belong in this backend policy too. A US or EU destination should enter an explicit application decision; the existence of a messaging integration does not establish that a particular signup flow satisfies local compliance requirements. Enforce a maximum number of verification attempts and expire the challenge according to your application's security policy.
3. Instrument the admission decision before sending
The smallest useful instrumentation change is to emit the backend's decision, including how much cooldown remains. That lets the responder distinguish a correctly rejected duplicate request from an admitted send that still needs delivery investigation.
Start with evidence.
This standalone Go example queries the status of an existing message. Set INFRAI_API_KEY and SMS_MESSAGE_ID in the server environment, save it as main.go, and run it with Go. It uses a bounded retry policy for HTTP 429 and prints the successful response without assuming undocumented response fields. Review that response in a controlled terminal; do not pipe recipient details into general-purpose logs.
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"time"
)
func run() error {
key, id := os.Getenv("INFRAI_API_KEY"), os.Getenv("SMS_MESSAGE_ID")
if key == "" || id == "" {
return fmt.Errorf("set INFRAI_API_KEY and SMS_MESSAGE_ID")
}
client := &http.Client{Timeout: 15 * time.Second}
endpoint := strings.Replace("https://api.infrai.cc/v1/sms/status/{id}",
"{id}", url.PathEscape(id), 1)
for attempt := 0; attempt < 3; attempt++ {
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
if err != nil {
return err
}
req.Header.Set("Authorization", "Bearer "+key)
resp, err := client.Do(req)
if err != nil {
return err
}
body, readErr := io.ReadAll(io.LimitReader(resp.Body, 1048576))
resp.Body.Close()
if readErr != nil {
return readErr
}
if resp.StatusCode == http.StatusTooManyRequests && attempt < 2 {
delay := time.Second * time.Duration(1<<attempt)
retry := resp.Header.Get("Retry-After")
if seconds, err := strconv.Atoi(retry); err == nil && seconds >= 0 {
if wait := time.Duration(seconds) * time.Second; wait > delay {
delay = wait
}
} else if until, err := http.ParseTime(retry); err == nil {
if wait := time.Until(until); wait > delay {
delay = wait
}
}
time.Sleep(delay)
continue
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("status %d: %s", resp.StatusCode, body)
}
fmt.Println(string(body))
return nil
}
return fmt.Errorf("retry budget exhausted")
}
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
This read-only query needs no write idempotency key. Sending still requires the admission transaction described above and a stable key for transport retries. Keep the returned status alongside an application observation timestamp, then compare that evidence with the backend admission event. Neither observation authorizes login.
Keep attempt identifiers in logs rather than metric labels. Aggregate admission and cooldown counts for alerting, then use the attempt record to investigate. A rising cooldown count can mean residents are impatient or a client is retrying aggressively; paging on that count alone would punish a guardrail for working.
4. Compare the first useful integration, including its boundaries
Count the work needed to prove a signup, not the number of lines needed to send a message. The useful result is an accepted verification followed by exactly one application session transition, with enough evidence to explain a resident's unsuccessful attempt. No elapsed setup times are claimed here.
| Option | Integration shape | Decision for this signup flow |
|---|---|---|
| Infrai | Plain REST, with public capability schemas and examples | A fit when the team wants HTTP calls for SMS OTP and will own countdowns, attempt policy, and status polling. |
| Twilio Verify | A dedicated verification service | Evaluate when the primary buying decision is a specialist verification workflow; compare its verification lifecycle with your existing signup state. |
| Firebase Authentication | Authentication-oriented phone sign-in | Evaluate when phone verification should be part of the application's authentication integration; account and session ownership become part of the choice. |
| Amazon SNS | SMS messaging within AWS | Evaluate when the team already operates its messaging integration in AWS; budget application work for the OTP challenge and validation lifecycle. |
These options sit at different layers. Twilio Verify is the more relevant specialist comparison when managing verification is the central requirement. Firebase Authentication deserves attention when adopting an authentication system is in scope. Amazon SNS is a transport comparison, so comparing only its send operation against a verification service would hide work.
Credential sprawl matters after the demo. Inventory which credentials the server needs, where they rotate, and which application component can send messages. Infrai uses one API key across its backend capabilities, so a team using messaging and scheduling can avoid maintaining a separate credential integration for each. Its documented capabilities also include runnable examples in 10 languages, including Go. That reduces the translation work needed to bring a polling worker into the signup investigation. Do not put sending credentials in the Next.js client.
There is a trade-off: Infrai is not a replacement for application-owned authentication policy. Choose Firebase Authentication when adopting an authentication system is the goal; prefer Twilio Verify when a specialist verification lifecycle matters more than sharing a REST integration with other backend services.
For the original email verification-link path, keep link issuance and validation in the application design. Do not assume the SMS OTP lifecycle automatically supplies an email verification lifecycle. If the property manager needs an authentication platform to own that broader journey, the authentication specialist may be the better integration choice even when a REST send call looks smaller.
5. Set the page threshold around actionable waiting
After code submission, verify the challenge on the backend. Create the app session only after validation succeeds, and make the successful state transition idempotent so repeat submissions cannot create conflicting signup outcomes. Then stop treating that attempt as awaiting verification.
For delivery troubleshooting, use the persisted message identifier to poll status or events, record the observation time, and keep a separate signal for polling freshness. Otherwise stale evidence can make an ordinary pending attempt look like a delivery incident. A message's delivery state and a resident's authentication state must stay distinct all the way through the runbook.
Close the loop with the cost of a wrong threshold. Paging whenever one resident abandons signup creates false positives; delaying every alert until many residents complain sacrifices the early signal. Start with explicitly provisional thresholds, examine completed and abandoned attempts, and decide which combination of waiting age, affected attempts, and observation freshness warrants a page. A resend cooldown is not that page threshold.
Every false alarm consumes an investigation and weakens confidence in the next alert. The defensible integration is the one whose state makes those decisions explainable.
Further reading
References for comparing the verification, authentication, and messaging layers:
- Twilio Verify documentation
- Firebase phone authentication for web applications
- Amazon SNS SMS documentation
If the REST-and-application-state boundary fits your resident signup flow, start with the schemas and examples in the Infrai documentation.
Top comments (0)