Menu

1 / 2

Why your async user-creation endpoint silently produces duplicates

DEV Community·Alan West·6 months ago
#waIfaQAr
#option#webdev#javascript#email#await
Reading 0:00
15s threshold

Six hours. That's how long I burned last Tuesday tracking down a bug that only showed up in production. The tests passed. CI was green. Two reviewers approved the PR. But once real traffic hit, our user-creation endpoint started silently producing duplicate rows.

I've seen this exact pattern enough times to know what's going on. The code looked fine. It read fine. Modern async/await, no callback nesting, type-safe. But whoever wrote it (could've been me on a bad day) hadn't actually internalized what await does. And the moment you skip the fundamentals — what the event loop guarantees, what a transaction actually isolates, what "atomic" means — you build a thing that only fails under load.

Here's the bug, the root cause, and a process for catching this class of issue.

The frustrating problem

Picture an endpoint that creates a user if one doesn't already exist:

async function createUserIfMissing ( email ) { const existing = await db . users .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.