title: Database Concurrency / Synchronization issues with thousands of active users
body: <p>We are building a game and I wonder possible solutions about some syncronization issues. I currently use mongodb but those problems will exist in any db.</p>
  <p>EXAMPLES (Unlikely to happen)</p>
  <p>Scenario 1) A clan has unique name and every user can create a clan.</p>
  <p>Create Clan Execution flow.
  1 - CheckClanNameUnique ()
  2 - DoStuff ()
  3- InsertClan ()</p>
  <p>In scenario above, when to users tries to create a clan with same name, both can be validated before update.(I know I can make clanname unique in database.)</p>
  <p>Scenario 2) There are tournaments with 20 people groups in it.</p>
  <p>Assume a group already has 19 people at the moment and 2 concurrent requests are made to join group.</p>
  <p>Join Tournament group Execution flow.
  1 - CheckGroupHasSlots ()
  2 - DoStuff ()
  3- JoinGroup () (update db)</p>
  <p>In scenario above, when to users tries to join group with same name, both can be treated as empty before update.</p>
  <p>What are the solutions for such problems?
  I appreciate any searching keyword or readings, articles.</p>
  <p>Thank you</p>