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

Distributed data synchronization in 5 lines of ...

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Distributed data synchronization in 5 lines of code

Avatar for James Nocentini

James Nocentini

October 19, 2015

More Decks by James Nocentini

Other Decks in Technology

Transcript

  1. ©2015  Couchbase  Inc. ‹#› Multi-­‐Master  Replication read write Master Master

    Master synchronize synchronize read read synchronize write write
  2. ©2015  Couchbase  Inc. ‹#› Multiversion  Concurrency  Control ▪ Non-­‐blocking  reads

    User 1 User 2 read v0 read v0 read v0 write v1 read v0 v-current=v0 v-current=v1 read v1 write v2 v-current=v2 v0 v1 v2 Time
  3. ©2015  Couchbase  Inc. ‹#› Multiversion  Concurrency  Control ▪ Transactions  on

     concurrent  writes User 1 User 2 read v0 read v0 write v1-1 v-current=v0 write v1-2 v-read=0 v-current=v1-1 conflict! v-read < v-current v-read=0 v0 v1-1 v1-2 Time
  4. ©2015  Couchbase  Inc. ‹#› Getting  started   Download the app

    from bit.ly/guess-where-android Android Open http://labs.couchbase.com/ mini-hacks on your mobile or laptop Web
  5. ©2015  Couchbase  Inc. ‹#› Starting  the  Listener Peer-To-Peer URL url

    = new URL("http://10.8.4.3:55000/votingapp"); Replication r = Replication.createPushReplication(url); r.start(); Result doc1 doc1 Listener listener = new Listener(manager, 55000); listener.start(); Push replication A B
  6. ©2015  Couchbase  Inc. ‹#› Peer  discovery   CBL Listener on

    port 55000 Service name jamiltz Service type _peersync._tcp Device A register a service Listen for all services and handle those with service type _peersync._tcp Device B discover services 1. Broadcast service 2. Hostname resolution 3. Return IP address 4. Start pull or push replication
  7. ©2015  Couchbase  Inc. ‹#› Schemas   { "_id": "question-1", "type":

    "question", "answer": "Paris", "link": "http://…" } Question { "_id": "8920380-940324932-84032", "type": "answer", "nickname": "james", "user_answer": "Barcelona", "time": 1443759003805, "question_id": "question-1" } Answer
  8. ©2015  Couchbase  Inc. ‹#› Schemas   { "_id": "question-1", "_rev":

    "1-je32jd2dqwl", "type": "question", "answer": "Paris", "link": "http://…" } Question { "_id": "8920380-940324932-84032", "_rev": "1-r83o2f20", "type": "answer", "nickname": "james", "user_answer": "Barcelona", "time": 1443759003805, "question_id": "question-1" } Answer
  9. ©2015  Couchbase  Inc. ‹#› Schemas   { "_id": "question-1", "_rev":

    "2-je32jd2dqwl", "type": "question", "answer": "Paris", "link": "http://…" } Question { "_id": "8920380-940324932-84032", "_rev": "1-r83o2f20", "type": "answer", "nickname": "james", "user_answer": "Barcelona", "time": 1443759003805, "question_id": "question-1" } Answer
  10. ©2015  Couchbase  Inc. ‹#› Schemas   { "_id": "question-1", "_rev":

    "3-je32jd2dqwl", "type": "question", "answer": "Paris", "link": "http://…" } Question { "_id": "8920380-940324932-84032", "_rev": "1-r83o2f20", "type": "answer", "nickname": "james", "user_answer": "Barcelona", "time": 1443759003805, "question_id": "question-1" } Answer
  11. ©2015  Couchbase  Inc. ‹#› Schemas   { "_id": "question-1", "_rev":

    "3-je32jd2dqwl", "type": "question", "answer": "Paris", "link": "http://…" } Question { "_id": "8920380-940324932-84032", "_rev": "1-r83o2f20", "type": "answer", "nickname": "james", "user_answer": "Barcelona", "time": 1443759003805, "question_id": "question-1" } Answer
  12. ©2015  Couchbase  Inc. ‹#› _id: doc1 _rev: 3-a9ff _id: doc1

    _rev: 2-c31b Couchbase Lite Sync Gateway Replicating Documents & Revisions Sync Gateway: "What’s new since we last spoke?" Couchbase Lite: "I added rev #3-a9ff of doc1." Sync Gateway: "That’s new to me!" Couchbase Lite: "I’ll send it over…"
  13. ©2015  Couchbase  Inc. ‹#› Hybrid  approaches ▪ "A  Sync  Gateway

     node  is  just  a  well-­‐connected  peer"   ▪ Clients  can  connect  to  local  peers  and  to  a  server