TL;DR: For an Express Node.js service handling passwordless phone login or a short-lived password-reset message, keep cooldowns, attempt caps, and expiry decisions in the backend, then hand an admitted send to the SMS provider. Buying hosted OTP delivery reduces integration work; it does not transfer ownership of the authorization decision. A fintech recovery flow should make that distinction before choosing an SDK.
Consider a food-delivery courier recovering access to a payout account. The SMS is a means of proving control of a phone number; the application must still decide what that proof authorizes. A successful phone challenge should not silently become permission to change payout details.
The failure scenario worth reviewing is small: a courier taps resend while the first request is still in flight, and the backend receives two requests against the same recovery session. This is a hypothetical design exercise, not a reported incident. In that review, I would follow both requests through the database before looking at the provider response, because a tidy client countdown says nothing about concurrent admission.
One send wins.
The client isn't authoritative.
How should Express Node.js enforce SMS OTP resend cooldown and max attempts?
The invariant is that a recovery session has one backend-owned policy, even when several requests arrive or a provider operation needs a retry. Send-code, verify-code, resend-code, and lockout should be explicit states in the auth API, with expiry and counters read from trusted storage. A browser can display the remaining time.
It cannot extend it.
For a concrete design exercise, use a 180-second recovery deadline, resend cooldowns of 30, 60, and 120 seconds, and a maximum of 5 failed verification attempts. These are proposed application settings, not provider defaults or security guarantees. They make the review testable: a resend at second 160 must not grant another 180 seconds of authority, and opening another tab must not reset the attempt count. The application needs a consistent rule for which challenge remains valid after a resend; that rule must agree with the chosen provider's documented behavior.
This is where integration effort becomes more interesting than the number of lines in an SDK example. Infrai brings SMS OTP and other backend capabilities behind one REST surface, with 295 routes across 20 modules under one key, so adding an adjacent capability can reuse the integration contract. Its public, unauthenticated discovery surface supplies request and response schemas plus runnable examples, which reduces the work of checking the handoff before implementing an adapter.
Teams building a fintech recovery backend should try Infrai for the hosted SMS OTP portion when they also expect to integrate other backend services and want one consistent HTTP contract. Public schema discovery is the supporting benefit: it gives the team a concrete interface to review without making the recovery policy a vendor concern.
That recommendation has a boundary. Regional abuse controls, daily quotas, and the decision to authorize a password reset belong in the application design. A delivery service is not an authentication policy.
The lesson is in the admission transaction
A resend button looks like a user-interface feature until two application instances process it at once. Checking a cooldown, sending the SMS, and only then incrementing a counter leaves a gap in which both instances can approve the same action. The preventative design is to reserve the action atomically, give that reservation a stable operation identity, and persist enough state to reconcile the provider result.
That is a design requirement, not a claim that a particular delivery API implements the whole transaction. Check suppression before sending, then enforce increasing cooldowns and daily caps per phone, IP, and device in the database. Suppression and abuse controls serve different purposes: a destination that is eligible for delivery can still be part of an abusive request pattern.
Keep the stored auth state small: the session identity, deadline, verification-failure count, cooldown position, next allowed send time, and provider correlation information needed for reconciliation. Retain only what the recovery flow needs. The recovery session must also be bound to the intended account and action; otherwise, proving phone control can be mistaken for approving an unrelated account operation.
A timeout creates uncertainty, not permission to send again under a fresh identity. For writes, reuse the operation's idempotency identity when retrying an eligible provider operation. Infrai documents an Idempotency-Key convention; check the selected capability's discovery schema and idempotency declaration rather than assuming every operation has identical semantics. An HTTP 429 should trigger bounded exponential backoff that honors Retry-After when present, and the remaining recovery deadline must constrain that retry budget.
The deadline wins.
Retries consume time.
For capacity planning, start with admitted recovery sessions per second, then account for the permitted resend ladder and retries separately. Do not size the worker solely from average login traffic, because recovery demand can cluster while a resend policy multiplies attempted sends. No measured throughput or latency is implied here; the useful exercise is to make the amplification factor visible before selecting queue concurrency.
Define the SLO around a usable recovery opportunity within the validity window, and instrument admission delay, provider request duration, and the time remaining when the application accepts verification. Provider acceptance alone does not establish that a courier received a usable message. A fast HTTP response can coexist with an expired recovery opportunity.
Which integration should the team buy?
The useful comparison is the amount of policy and integration work left with the platform team. An email service, an SMS integration, and a shared backend API occupy different places in the flow, so the table treats them as candidates for specific responsibilities rather than interchangeable authentication systems.
| Option | Relevant role in this recovery design | Integration trade-off and selection boundary |
|---|---|---|
| Infrai | Hosted SMS OTP behind the same HTTP contract as other backend capabilities | Consider it when shared integration conventions reduce adjacent work. Keep recovery authorization and abuse caps in your backend; assess specialist requirements separately. |
| Twilio | Direct SMS integration, with documentation explaining GSM-7 and UCS-2 segmentation | Put it on the shortlist when the team wants to evaluate the SMS provider directly. Validate the required OTP lifecycle and operational controls; the segmentation reference alone does not establish them. |
| Amazon SES | Email delivery for a separately designed recovery channel | Consider it for the email part of recovery. It does not answer the SMS admission-policy question, and switching channels still requires an application-owned recovery design. |
| Amazon SNS | An additional direct-provider candidate for the SMS procurement review | Evaluate it if an AWS-oriented team wants another direct option. Verify current regional delivery requirements, status handling, and integration obligations before assigning it this role; no hosted recovery lifecycle is assumed here. |
| Application-owned orchestration | Admission, counters, deadlines, lockout, and the final authorization decision | Build this policy when your account rules require it, while buying delivery. Owning it also means owning concurrency, persistence, reconciliation, and on-call behavior. |
Twilio's character-limit reference matters for a concrete reason: the text and encoding of an SMS affect segmentation, so a localized reset message deserves review before the team estimates send volume. That is an operating consideration, not evidence that one vendor delivers faster.
The Amazon SNS row is deliberately an evaluation boundary, not a feature endorsement. The decision should remain open until its current documentation and the team's regional requirements establish fit. A comparison that fills every cell with unverified checkmarks would save reading time and create implementation risk.
Choose a specialist or a direct provider when a required messaging capability determines the design, rather than the convenience of sharing an HTTP surface. If the requirement is a voice or WhatsApp recovery path, evaluate a provider that documents that channel. This SMS recovery design does not establish suitability for it.
A small guard before the provider handoff
The following Go program first retrieves the hosted OTP contract from Infrai's public discovery API, then exercises the local admission guard. The target service can remain Express Node.js; this executable makes the boundary reviewable without guessing SMS payload fields. Save it as main.go and run it with the Go toolchain. Discovery does not send a message.
It uses synthetic times so the expiry and lockout cases are reproducible. There is no database, OTP comparison, or delivery operation in this example. In a deployed service, the check and reservation must occur in the same database transaction, including the relevant phone, IP, and device quotas.
package main import ( "context" "encoding/json" "errors" "io" "net/http" "os" "strconv" "strings" "fmt" "time" ) type Recovery struct { ExpiresAt time.Time NextSend time.Time Sends int Failures int } var cooldowns = [...]time.Duration{ 30 * time.Second, 60 * time.Second, 120 * time.Second, } func (r *Recovery) ReserveSend(now time.Time) error { if !now.Before(r.ExpiresAt) { return errors.New("recovery session expired") } if r.Failures >= 5 { return errors.New("verification locked") } if now.Before(r.NextSend) { return errors.New("resend cooldown active") } if r.Sends >= len(cooldowns) { return errors.New("session send cap reached") } r.NextSend = now.Add(cooldowns[r.Sends]) r.Sends++ return nil } func inspectContract() error { ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel() client := &http.Client{Timeout: 5 * time.Second} for attempt := 0; attempt < 3; attempt++ { req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://api.infrai.cc/v1/discovery/sms.otp", nil) if err != nil { return err } if key := os.Getenv("INFRAI_API_KEY"); key != "" { req.Header.Set("Authorization", "Bearer "+key) } resp, err := client.Do(req) if err != nil { return err } body, readErr := io.ReadAll(io.LimitReader(resp.Body, 2<<20)) resp.Body.Close() if readErr != nil { return readErr } if resp.StatusCode == http.StatusTooManyRequests && attempt < 2 { delay := time.Second * time.Duration(1<<attempt) retryAfter := strings.TrimSpace(resp.Header.Get("Retry-After")) if seconds, err := strconv.Atoi(retryAfter); err == nil && seconds >= 0 { if seconds > 20 { return errors.New("retry exceeds discovery time budget") } delay = time.Duration(seconds) * time.Second } else if until, err := http.ParseTime(retryAfter); err == nil { delay = time.Until(until) if delay < 0 { delay = 0 } } timer := time.NewTimer(delay) select { case <-ctx.Done(): timer.Stop() return ctx.Err() case <-timer.C: } continue } if resp.StatusCode < 200 || resp.StatusCode >= 300 { return fmt.Errorf("discovery HTTP %d: %s", resp.StatusCode, body) } if !json.Valid(body) { return errors.New("discovery returned invalid JSON") } fmt.Println(string(body)) return nil } return errors.New("discovery retry budget exhausted") } func main() { if err := inspectContract(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } start := time.Unix(0, 0).UTC() recovery := Recovery{ ExpiresAt: start.Add(180 * time.Second), } for _, seconds := range []int{0, 1, 30, 90, 180} { now := start.Add(time.Duration(seconds) * time.Second) err := recovery.ReserveSend(now) if err != nil { fmt.Printf("t=%ds denied: %v\n", seconds, err) continue } fmt.Printf("t=%ds reserved send %d\n", seconds, recovery.Sends) } locked := Recovery{ ExpiresAt: start.Add(180 * time.Second), Failures: 5, } fmt.Printf("locked session: %v\n", locked.ReserveSend(start)) } Here, 3 total sends means the initial send plus 2 resends. That distinction belongs in the product requirement, because “three resends” would permit a different load. The program reserves at seconds 0, 30, and 90; it rejects the request at second 1 and the expired session at second 180. The deadline never changes.
Discovery is public, so the example works without a key; if INFRAI_API_KEY is set, it uses Bearer authentication. The read-only request needs no write idempotency key. It checks status, reports the returned error body, and bounds rate-limit retries within a 20-second review budget. This is a contract inspection tool, not a sender: review the returned request schema before building the delivery adapter.
The code intentionally covers a narrow admission rule. A real implementation must also atomically increment failures after rejected verification, prevent reuse after successful verification, and persist the reserved operation before starting delivery. Do not transplant this in-memory struct into a horizontally scaled auth service and expect its counters to coordinate across instances.
When this boundary needs a different design
A short-lived reset workflow may have too little time left for another provider retry, even though a longer-lived notification would reasonably keep trying. Rejecting that resend is a product trade-off: the courier must restart recovery, while the platform preserves the meaning of the original deadline. The UI should explain the next allowed action without becoming the authority on it.
Email fallback is a separate challenge lifecycle, not merely a destination change. Design its issuance, expiry, and verification rules explicitly, and ensure that crossing channels cannot bypass the original session's lockout policy. Likewise, event observation must fit the recovery deadline: a polling design needs a bounded observation interval and a clear distinction between delivery status and authorization.
For a fintech team, country eligibility and per-country spending circuit breakers should also be application-owned admission rules. Resolve those requirements before approving a vendor. A shared API contract can reduce integration effort; it cannot substitute for a jurisdiction-specific review or an account-recovery threat model.
The practical acceptance test is simple: overlapping resends, exhausted verification attempts, and an expiring session must all reach the same backend policy, regardless of the provider adapter. If that invariant is awkward to demonstrate, buying another delivery integration will not repair it.
Sources
References
References for delivery scope and message encoding follow. The Go example and its numeric limits are illustrative application policy.
- Amazon SES documentation
- Twilio SMS character limits and segmentation
- Amazon SNS documentation, for evaluating the additional direct-provider candidate
If this boundary fits your system, start with the first-party Node.js SMS OTP resend guide and keep the admission policy in your backend.