An implementation guide for preventing duplicate workers, delayed messages, and token races from producing contradictory verification results.
Email verification is usually described as a token problem. In a production REST API, it is more useful to treat it as an ownership problem.
One request creates an attempt. A background worker sends the message. A browser later presents the token. Meanwhile, the client may retry, the worker may time out after sending, and the user may request another email. If no component can say which process owns the current attempt, the system starts making guesses.
The pattern I use for this case is a short-lived lease around each verification attempt. The lease does not replace a token or a queue. It gives the backend an explicit answer to a more practical question: who is allowed to advance this attempt right now?
Why email verification needs ownership
Consider a POST /verification-attempts request that reaches the API twice because the first response was lost.…