Our first instinct might simply be to check the users table to make sure there isn't already a row with the requested username in the table. To keep things concise, we might do something like the following:
SELECT "username" FROM "users" WHERE "username" = 'eve' LIMIT 1;
This will return a single row containing only the username value if the username value is taken:
If the username is available, rows eve 1 and eve 2 try to create an account with the username eve at the same time:
- The character eve 1 sends a request to our application to create an account.
- The character eve 2 sends a request to our ...