Prompt

How do I stop duplicate password-reset emails when my background job retries?

Technology / Identity access5 observationsLast seen Oct 29, 2026

Latest observation

Oct 29, 2026QwenWeb search: on

To stop duplicate password-reset emails during background job retries, you need to address the root cause of the retries. The solution depends on whether the job is retrying because the email failed to send (transient error) or because the job was enqueued multiple times (user double-clicking or a race condition).

Here is the step-by-step architectural approach to solving this, regardless of your tech stack.

1. Separate Token Generation from Email Delivery

The most common cause of duplicate emails is a single background job that does both: it generates a new database token and sends the email. If the email fails and the job retries, it generates a second token and sends a second email.

The Fix: Split the logic or make the token generation idempotent.

  • Step 1: The job checks the database: Does this user already have a valid, unexpired password reset token?
  • Step 2: If yes, reuse that exact token. Do not generate a new one.
  • Step 3: Send the email using the existing token.

If the email fails and the job retries, it will find the existing token, reuse it, and simply attempt to send the email again without creating duplicate database records or confusing the user with multiple different links.

2. Implement an Idempotency Check (The "Cooldown")

Even if the token is reused, you don't want to spam the user's inbox if the job retries 5 times in a row. Add a "cooldown" check at the very beginning of your background job.

# Pseudo-code for the background job
def send_password_reset_email(user_id):
    user = db.get_user(user_id)
    
    # IDEMPOTENCY CHECK: Has an email been sent in the last 15 minutes?
    if user.password_reset_email_sent_at > (now() - 15 minutes):
        return "Skipped: Cooldown active"
        
    # Generate or fetch token...
    token = get_or_create_reset_token(user)
    
    # Send email...
    email_service.send(user.email, token)
    
    # Update timestamp
    user.password_reset_email_sent_at = now()
    user.save()

Note: If the job retries after 15 minutes, it will send the email again, which is usually acceptable behavior.

3. Prevent Duplicate Jobs at the Queue Level (Deduplication)

If the duplicate emails are happening because the user clicked "Forgot Password" twice in rapid succession, you are enqueueing two identical jobs. You need to prevent the second job from entering the queue.

How to do this based on your stack:

  • Sidekiq (Ruby): Use the sidekiq-unique-jobs gem. You can set a unique constraint on the job using the user_id as the lock key. If a job for user_id: 123 is already in the queue, the second one is silently dropped.
  • Celery (Python): Use a distributed lock (like Redis) at the start of the task, or use Celery's worker_deduplicate_successful_tasks / custom routing to ensure only one instance of a task per user runs at a time.
  • BullMQ (Node.js): Use the jobId option when adding a job. If you set the jobId to password_reset_${userId}, BullMQ will automatically ignore duplicate additions of the same job ID.
  • Hangfire (.NET): Use the DisableConcurrentExecution attribute or implement a distributed lock using DistributedLockMutex.

4. Rate-Limit the API Endpoint

The best way to prevent duplicate background jobs is to stop them from being created in the first place. Apply rate limiting to the "Forgot Password" HTTP endpoint.

  • Limit the endpoint to 1 request per IP address or 1 request per email address every 60 seconds.
  • If a user (or a bot) requests a reset twice in 10 seconds, the API should return a 200 OK (to prevent email enumeration) but do not enqueue the background job the second time.

Summary Checklist

  1. API Level: Rate-limit the "Forgot Password" endpoint to 1 request per minute per email.
  2. Queue Level: Use unique job IDs (e.g., reset_password_{user_id}) so the queue drops duplicate enqueues.
  3. Job Level: Check if a reset token was already generated for the user before creating a new one.
  4. Job Level: Check a last_email_sent_at timestamp to ensure you don't send multiple emails for the same token if the job retries.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (5 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.