Short answer: for a forgot password backend in Node.js, use Postgres to authorize each email send atomically, prevent user enumeration with a generic response, and retain an audit log that distinguishes authorization from delivery. For a healthtech portal, choose the workflow by the evidence it can produce before a short-lived reset link expires.
| Approach | Pick this when | Evidence boundary |
|---|---|---|
| Send during the request | A small service can tolerate transport latency | Record authorization before contacting the transport; a timeout leaves acceptance uncertain |
| Transactional outbox and worker | Database-backed handoffs and retry history matter | Commit the reset digest, delivery job, and audit event together |
| Queue and notification service | Several applications need shared messaging policy | Trace the request across the database handoff, queue, and delivery attempts |
The decision is about evidence. A successful send call does not establish that a patient received, opened, or used a password-reset email. Treat those as separate questions.
How can a forgot password backend prevent user enumeration before an email send?
OWASP's Forgot Password Cheat Sheet calls for consistent messages and response timing for existing and nonexistent accounts. Return the same public acknowledgment: “If an account matches, a message will arrive shortly.” Keep internal decisions out of the response. An account-specific error code defeats the wording.
Don't stop there.
Move lookup and delivery decisions behind an asynchronous boundary so the public request does not wait for account-specific email work. Apply abuse limits to this intake too. Otherwise, an attacker can fill the queue even while your account-level cooldown correctly suppresses messages. Avoid claiming that a fixed delay proves timing resistance; test the response distributions for known and unknown synthetic addresses.
For the example below, five minutes is a proposed cooldown and 15 minutes is a proposed token lifetime. Neither number is a clinical compliance requirement. A team should select them against its recovery workflow, threat model, and support process. A shorter window reduces exposure after a link leaks, but also leaves less time for someone switching between a portal and an email client.
Pick the handoff you can explain to an auditor
A synchronous sender has fewer moving parts. It also couples a public request to transport latency. Choose it only if you can explain what happens when authorization succeeds but the send result is unknown. You still need a durable record before attempting delivery.
An outbox makes that record part of the same Postgres transaction as the reset token digest. That is a useful default for this example: a committed job can be found after a worker restarts. The extra work is real. Someone owns queue age, leases, payload protection, and deletion.
A separate notification service fits shared channel policy. It introduces another evidence boundary, though. A database commit and a queue publish are separate operations unless the design explicitly bridges them; use a durable handoff rather than assuming that two successful-looking calls form one transaction.
Diagram in words: public acknowledgment → private authorization transaction → protected outbox → delivery attempts → token redemption. Each arrow needs a correlation identifier.
None needs a reset URL in a log.
Make the authorization transaction the teaching example
Here is a TypeScript policy sketch for a Node.js worker. The repository methods are application interfaces, not a database library API. Its important contract is explicit: serialize decisions for the same account, then check cooldown and write all three records in one transaction. In Postgres, locking the existing account row provides a common serialization point even when no reset record exists yet.
import { createHash, randomBytes, randomUUID } from "node:crypto"; type Account = { id: string }; type ResetTx = { // Lock the account row; return database time and the last accepted request. lockResetState(accountId: string): Promise<{ now: Date; lastAcceptedAt: Date | null; }>; replaceActiveReset(input: { accountId: string; requestId: string; digest: string; expiresAt: Date; }): Promise<void>; // Encrypt the delivery payload under the application's key policy. enqueueProtectedReset(input: { accountId: string; requestId: string; token: string; expiresAt: Date; }): Promise<void>; appendAudit(input: { accountId: string; requestId: string; event: "authorized" | "cooldown_blocked"; at: Date; policyVersion: string; }): Promise<void>; }; type ResetStore = { transaction<T>(work: (tx: ResetTx) => Promise<T>): Promise<T>; }; async function authorizeReset( store: ResetStore, account: Account, requestId = randomUUID() ): Promise<void> { await store.transaction(async (tx) => { const state = await tx.lockResetState(account.id); const blocked = state.lastAcceptedAt !== null && state.now.getTime() - state.lastAcceptedAt.getTime() < 5 * 60_000; if (!blocked) { const token = randomBytes(32).toString("base64url"); const digest = createHash("sha256").update(token).digest("hex"); const expiresAt = new Date(state.now.getTime() + 15 * 60_000); await tx.replaceActiveReset({ accountId: account.id, requestId, digest, expiresAt }); await tx.enqueueProtectedReset({ accountId: account.id, requestId, token, expiresAt }); } await tx.appendAudit({ accountId: account.id, requestId, event: blocked ? "cooldown_blocked" : "authorized", at: state.now, policyVersion: "reset-policy-v1" }); }); } This function runs after private account lookup. It returns no token to the public caller. Use the application's established address matching rules; don't invent a new normalization rule in the reset path.
The lock matters.
Checking cooldown before the transaction creates a concrete race: two workers can both observe an eligible account and both authorize delivery. The account lock must remain held until commit, and every path that issues a reset must follow the same rule. On redemption, enforce expiry and consume the matching digest atomically with the password change. Two simultaneous submissions must not both succeed. OWASP recommends random, securely stored, single-use reset tokens with an appropriate expiry.
The protected outbox is a temporary secret store. Keep its access narrower than ordinary operational logs. Retain the encrypted token only while delivery attempts need it; retain nonsecret attempt evidence under a separate retention policy. Never include diagnosis, appointment details, or other clinical context in this example's reset message.
Teach the dashboard to distinguish waiting, accepted, and unknown
Retry the authorized delivery job without creating a fresh token or extending its expiry. Use a bounded backoff policy and stop sending when the link expires. Record the job identifier, attempt number, time, transport result, and next action. Provider acceptance is a transport event.
A timeout is ambiguous. The transport might have accepted the message before the response was lost. A unique local attempt row prevents duplicate bookkeeping; it does not guarantee exactly-once email delivery. If the transport supports an applicable deduplication contract, record that boundary. Otherwise, document the possibility of duplicate messages and keep retries tied to the same authorized reset.
For observability, track oldest pending job age, authorization-to-acceptance latency, cooldown blocks, expired unsent jobs, and unknown outcomes. Keep account identifiers in access-controlled audit records rather than metric labels. A dashboard full of unique request IDs is difficult to aggregate and exposes unnecessary identifiers.
Before rollout, test concurrent requests for one account, a crash after commit, a transport timeout, expiry during backoff, and simultaneous redemption. These are proposed tests, not reported measurements. Deploy against synthetic accounts first, and verify that tracing, exception reporting, and dead-letter inspection never capture reset URLs.
Check the traces.
Limits worth writing down
The main trade-off is operational ownership: an outbox requires a worker, lease recovery, and protected payload retention. It is not suitable for a team that cannot operate those controls. A shared notification service may fit that team better, provided the service exposes the authorization and delivery evidence the application needs.
This workflow produces operational evidence; it does not establish healthcare regulatory compliance by itself. Define access, retention, incident review, and deletion with the people responsible for those controls. An unkeyed email-address hash should not be treated as anonymous data: likely addresses can be guessed.
Delivery can consume most of a short expiry window. Measure that delay before tightening the policy. The control narrative should say exactly what the audit trail proves: an authorized reset, a series of delivery attempts, and a separate redemption decision.