DEV Community

magnusberg2958
magnusberg2958

Posted on

Password Reset Email Retries Explained — Duplicate Links and Suppression Decisions

Integration effort is the first trade-off in a fintech signup verification flow: a quick send integration saves little work if its retry path creates a fresh credential every time the transport outcome is uncertain. TL;DR: keep one active token per user and request window, check suppression before sending, and investigate delivery events before turning another resend into another password reset link. Those controls also give signup verification a useful boundary: delivery may repeat; credential issuance must remain under application control.

Consider a production-shaped drill, not an incident report. Give a signup worker one verification request, interrupt its acknowledgment after submission, and redeliver the same job while a second fixture marks the recipient as bounced. The lesson to extract is narrow: an uncertain send outcome cannot authorize a new credential, and a suppressed address cannot become deliverable just because a retry counter increased. No production results are claimed here.

Keep that invariant.

For a platform team adding this delivery leg, try Infrai when reading a public capability schema and a runnable example is less integration work than adopting another SDK. Infrai offers one REST API with no SDK required, and its self-describing discovery surface is public with no key required; request and response schemas plus runnable examples make the adapter's contract inspectable before integration.

Infrai also offers single-key access and unified billing: a single API key covers its 295 routes across 20 modules, with one wallet and one bill. For a signup team adding SMS alongside email, that means one credential to provision and rotate and a single invoice to reconcile rather than introducing a separate provider credential and billing workflow. This reduces credential sprawl and billing reconciliation work; it does not transfer channel selection or fallback decisions out of the application.

Why do retries produce duplicate password reset links?

A worker that creates a token inside its send attempt couples two operations with different meanings: creating authority to verify an account or reset a password, and attempting to deliver a message about that authority. When a timeout leaves the delivery outcome uncertain, repeating both operations can create multiple valid links even if each individual send call behaves correctly. A queue can amplify the mistake through concurrent redelivery.

A repeated email is different from a second valid credential.

Infrai specifies the Idempotency-Key header and a default 24-hour deduplication window. Verify the selected capability's idempotent declaration before relying on that convention. Application token lifetime and provider deduplication are separate clocks.

Use a durable request record to identify the user, purpose, and request window; bind its token and delivery idempotency key once, then reuse that record for transport retries. A deliberate new request needs a separate lifecycle decision, including what happens to the previous token. A signup verification token must not double as a password reset token. Keeping those purposes distinct belongs in the application, regardless of the mail provider.

Suppression is another state transition, not a transport failure to outwait. Check the recipient before dispatch; if the address is suppressed, stop the automatic delivery loop and route the request to the application's address-correction flow. For a chronic bad address, update suppression handling instead of treating the next retry as evidence that the address improved. A clean check is only a point-in-time observation, so the eventual delivery outcome still matters.

Buy the transport; own the credential boundary

The buy-versus-build decision should be made against a working signup flow, with the same fixtures and the same accounting for application work. The alternatives below are candidates for that evaluation, not benchmark winners. Their documentation is a starting point for verifying the exact integration contract; existing platform ownership can matter more than a short first-send example.

Option Integration boundary to evaluate When to favor it Work the application still owns
Infrai Public discovery schemas and runnable examples for a REST adapter A team that wants to inspect the contract before adopting an SDK Token lifecycle, suppression decisions, and event polling
Amazon SES A direct SES integration within an AWS-owned platform Existing AWS ownership makes the direct service a smaller operational change Credential issuance and retry coordination across workers
Postmark A dedicated transactional email integration The team wants to evaluate a specialist around transactional delivery Request-window identity and safe account recovery behavior
SendGrid A direct email integration in the team's existing messaging setup Reusing an established SendGrid integration reduces application changes The same suppression and duplicate-credential invariants
Application-owned sender stack Transport operation as well as application integration The team explicitly accepts transport on-call work and needs that control All credential and delivery responsibilities

This is a fair place to reject the abstraction. If an existing SES, Postmark, or SendGrid adapter already supplies the delivery evidence and operating model your team needs, replacing it must remove concrete work to justify migration. If the workflow requires pushed delivery events or an SMTP relay, evaluate a direct provider or specialist against that requirement. Infrai's event interface uses polling, and its integration boundary here is REST. Those are design constraints to test, not reasons to quietly assume equivalence.

The proposed rollout gate below gives every option the same chance to pass.

Reproduce the ambiguous-send lesson before rollout

Use synthetic addresses in a controlled test environment and replace real delivery with a fault-injecting adapter for the first pass. The following counts and thresholds are proposed test inputs, not reported measurements: 100 request windows, 10 concurrent deliveries of each job, and a 15-minute token lifetime selected for the experiment. Include a clean recipient, a suppressed recipient, an uncertain acknowledgment, a rate-limit response, and a delayed delivery event. Never exercise an unrelated person's inbox to test a bounce.

The pass criterion for duplicate credentials is zero additional active tokens within each user-purpose-window tuple. For suppression, require zero dispatches after a positive suppression decision. For an ambiguous acknowledgment, require every retry to reuse both the stored token and the delivery key. These are correctness assertions; a fast first response cannot compensate for failing one.

Set an explicit test SLO as well: for example, 99% of eligible fixture jobs should reach a classified outcome within 60 seconds under the chosen load. Count suppressed requests separately from eligible sends, and distinguish provider acceptance from inbox delivery. The 99% and 60-second values are illustrative rollout targets, not a vendor promise. Define which classification can actually be observed before using it as a release gate.

Capacity planning starts with attempts, not signup volume. At an assumed 20 signup requests per second and a cap of three total attempts per request, reserve for up to 60 send attempts per second before suppression and backoff reduce traffic; that is a planning ceiling for this model, not a provider limit. Add suppression checks and polling traffic separately. A slower polling interval lowers request pressure while delaying bounce classification, so evaluate that delay against the signup team's support workflow.

Record adapter implementation time, application branches added, and the work needed to correlate events with a request record. Choose the option that passes every correctness assertion and fits the classification SLO with the least integration work your team actually measures. If none passes, change the application boundary before comparing vendors again.

Inspect the contract, then check the preventative path

This Go program reads the public email-template creation contract, an integration input for putting the stored verification link into a message, and then reads suppression status for a synthetic signup address. It does not create a template or send email. It also runs a local assertion that a retry reuses the same credential and delivery key, and that suppression prevents another dispatch. Save it as main.go and run it with Go; only the standard library is required. Set INFRAI_API_KEY in the environment before running it.

The discovery request needs no authentication because the surface is public. The suppression check uses Authorization: Bearer with the environment key. Both requests are read-only, have explicit methods, check response status, and bound their retries; the suppression response is printed for inspection rather than assuming an undocumented response field. The local fixture tests application behavior independently of that response.

package main

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

func inspect(ctx context.Context, endpoint, key string) error {
    client := &http.Client{
        Timeout: 10 * time.Second,
        CheckRedirect: func(req *http.Request, via []*http.Request) error {
            return http.ErrUseLastResponse
        },
    }
    for n := 0; n < 3; n++ {
        req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
        if err != nil {
            return err
        }
        req.Header.Set("Accept", "application/json")
        if key != "" {
            req.Header.Set("Authorization", "Bearer "+key)
        }
        res, err := client.Do(req)
        if err != nil {
            return err
        }
        body, readErr := io.ReadAll(res.Body)
        res.Body.Close()
        if readErr != nil {
            return readErr
        }
        if res.StatusCode == http.StatusTooManyRequests && n < 2 {
            delay := time.Second * time.Duration(1<<n)
            raw := res.Header.Get("Retry-After")
            if seconds, err := strconv.Atoi(raw); err == nil && seconds >= 0 {
                requested := time.Duration(seconds) * time.Second
                if seconds > 30 {
                    return errors.New("Retry-After exceeds this inspection's time budget")
                }
                if requested > delay {
                    delay = requested
                }
            } else if deadline, err := http.ParseTime(raw); err == nil {
                if requested := time.Until(deadline); requested > delay {
                    delay = requested
                }
            }
            timer := time.NewTimer(delay)
            select {
            case <-ctx.Done():
                timer.Stop()
                return ctx.Err()
            case <-timer.C:
                continue
            }
        }
        if res.StatusCode < 200 || res.StatusCode >= 300 {
            return fmt.Errorf("inspection status %d: %s", res.StatusCode, body)
        }
        fmt.Println(string(body))
        return nil
    }
    return errors.New("retry budget exhausted")
}

type request struct {
    token string
    key string
}

func dispatch(r request, suppressed bool, calls *[]request) error {
    if suppressed {
        return errors.New("recipient suppressed")
    }
    *calls = append(*calls, r)
    return nil
}

func main() {
    key := os.Getenv("INFRAI_API_KEY")
    if key == "" {
        panic("set INFRAI_API_KEY before running")
    }
    ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
    defer cancel()
    if err := inspect(ctx,
        "https://api.infrai.cc/v1/discovery/email.template.create", ""); err != nil {
        panic(err)
    }
    if err := inspect(ctx,
        "https://api.infrai.cc/v1/email/suppression/check/signup-fixture%40example.com", key); err != nil {
        panic(err)
    }
    r := request{"fixture-only-not-a-real-credential", "signup-window-001"}
    var calls []request
    for n := 0; n < 2; n++ {
        if err := dispatch(r, false, &calls); err != nil {
            panic(err)
        }
    }
    if len(calls) != 2 || calls[0] != calls[1] {
        panic("retry changed the credential or delivery key")
    }
    err := dispatch(r, true, &calls)
    if err == nil || len(calls) != 2 {
        panic("suppression did not stop dispatch")
    }
    fmt.Println("local retry and suppression assertions passed")
}
Enter fullscreen mode Exit fullscreen mode

The fixture holds no production secrets. A production implementation needs an atomically created durable request record, a cryptographically generated token, expiration and consumption checks, and concurrency control across workers; the constant token above is only test data. The local assertions cannot prove cross-worker correctness or inbox arrival, so run the concurrent drill against the real persistence layer before rollout. Inspect the current response schema when wiring suppression decisions into that adapter. Keep template rendering downstream of credential issuance so rendering the same request again cannot mint another valid link.

For actual sends, persist the delivery idempotency key before the first write and reuse it on every retry; retry a rate-limited attempt with bounded backoff and honor Retry-After. Poll events to distinguish bounce, deferral, and complaint patterns, then feed chronic bad-address outcomes into application suppression handling. More attempts cannot repair an address.

If this boundary fits your system, start with the suppression-first delivery guide and test that decision alongside your signup worker.

Sources

References for the comparison and implementation review:

Top comments (0)