Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Concurrency + Mongo

Concurrency + Mongo

Concurrent Operations with MongoDB

gamechanger

August 21, 2012
Tweet

More Decks by gamechanger

Other Decks in Technology

Transcript

  1. Concurrency • Multiple, interacting computations • Processes modifying same or

    dependent records • Relational: solved with transactions (2PC) • Mongo: no transactions (right?) • So, how do we do this? Monday, August 20, 12
  2. Examples • Multiple users scoring one game • One user,

    scoring on device, following on web • Background updates run on multiple nodes Monday, August 20, 12
  3. atomic updates • $set, $unset, $inc, $push, $pull, $addToSet .

    . . • $ operator, upserts . . . • findAndModify Monday, August 20, 12
  4. Atomic Updates • Don’t support all operations • Schema design

    important! • If we need to do a read first, can’t use Monday, August 20, 12
  5. Isolation Queue • Do all modifications in a queue processor

    • Only allow a record to be in the queue once • Compare to Java “synchronized” (monitor) Monday, August 20, 12
  6. Isolation Queue • Part of the Dockets library • github.com/gamechanger/dockets

    • Guarantees: • Updates will not conflict • Last update will be run • Intermediate updates may not be Monday, August 20, 12
  7. Isolation Queue • Requires a queue • Not everything can

    be async • Slower than Mongo atomic operators Monday, August 20, 12
  8. Optimistic Transactions • Like Redis, sort of • Don’t lock,

    but detect conflicts using save_date Monday, August 20, 12
  9. Optimistic Transactions • Single-record only • Slower than atomic updates

    • Inefficient when there’s a lot of contention Monday, August 20, 12
  10. Conclusions • Safe concurrency != ACID • Schema design is

    important • No one-size-fits-all solutions in NoSQL! Monday, August 20, 12