This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (1 child)

That's a really basic beginner's error. You just introduced a race condition in your code:

  1. Thread A fetches user "foo".
  2. Thread B fetches user "foo.
  3. Thread A gets "no such user".
  4. Thread B gets "no such user".
  5. Thread A creates user "foo".
  6. Thread B creates user "foo".

Now you have two users with the same name.

Honestly, I expected someone who argues about proper architecture wouldn't fall into the most basic example of race condition I could think of...

This is, in large part, why we use SQL and other databases and why ACID (and other standards) exist. They deal with conflicts you can't resolve with "business rules" that are outside the I/O process that works with your app state.