Checking before inserting isn't enough

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:

  1. The character eve 1 sends a request to our application to create an account.
  2. The character eve 2 sends a request to our ...

Get Learning Apache Cassandra - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.