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

Couchbase Mobile Architecture

Jens Alfke
September 13, 2013

Couchbase Mobile Architecture

Presentation from the Couchbase Conference, Sept. 2013.

An overview of the architectural components of Couchbase Lite and the Sync Gateway, and how data flows through them during replication.

Jens Alfke

September 13, 2013
Tweet

More Decks by Jens Alfke

Other Decks in Programming

Transcript

  1. High-­‐Level  View                

         My  Super  App Couchbase  Lite
  2. High-­‐Level  View                

         My  Super  App Couchbase  Lite My  Awesome Data  Center Couchbase  Server
  3. High-­‐Level  View                

         My  Super  App Couchbase  Lite My  Awesome Data  Center Couchbase  Server Sync  Gateway
  4. High-­‐Level  View                

         My  Super  App Couchbase  Lite My  Awesome Data  Center Couchbase  Server Sync  Gateway
  5. Couchbase  Lite  Components Key-­‐Value JSON   Storage Sync   Engine

    Map/Reduce View  Indexer Query  Engine ApplicaOon  API
  6. Couchbase  Lite  Components Key-­‐Value JSON   Storage Sync   Engine

    Map/Reduce View  Indexer Query  Engine ApplicaOon  API
  7. Couchbase  Lite  Components Key-­‐Value JSON   Storage Sync   Engine

    Map/Reduce View  Indexer Query  Engine ApplicaOon  API
  8. Couchbase  Lite  Components Key-­‐Value JSON   Storage Sync   Engine

    Map/Reduce View  Indexer Query  Engine ApplicaOon  API
  9. Couchbase  Lite  Components Key-­‐Value JSON   Storage Sync   Engine

    Map/Reduce View  Indexer Query  Engine ApplicaOon  API
  10. Couchbase  Lite  Components Key-­‐Value JSON   Storage Sync   Engine

    Map/Reduce View  Indexer Query  Engine ApplicaOon  API
  11. Sync  Gateway  Components Sync REST  API Couchbase   Smart  Client

    Revision/ Conflict   Management AuthenOcaOon App’s  Sync   FuncOon Channel   Change   Tracking External  Auth   Services to  client to  Couchbase  Server
  12. Sync  Gateway:  Incoming  Changes Sync REST  API AuthenOcaOon External  Auth

      Services • Pushes  changes  from  client: • POST  /db/_revs_diff • POST  /db/_bulk_docs
  13. Sync  Gateway:  Incoming  Changes Sync REST  API AuthenOcaOon External  Auth

      Services • HTTP  Basic  (over  SSL),  or • Session  cookie
  14. Sync  Gateway:  Incoming  Changes Sync REST  API AuthenOcaOon External  Auth

      Services • Facebook • Persona  (email-­‐based) • Custom • LDAP,  etc.  *
  15. Sync  Gateway:  App  Logic  &  Storage Couchbase   Smart  Client

    Revision/ Conflict   Management App’s  Sync   FuncOon to  Couchbase  Server AuthenOcaOon
  16. Sync  Gateway:  App  Logic  &  Storage Couchbase   Smart  Client

    Revision/ Conflict   Management App’s  Sync   FuncOon to  Couchbase  Server function(doc,  oldDoc)  { … requireUser(oldDoc.owner); … channel(doc.channel); … access(doc.members,  doc.roomID); } AuthenOcaOon
  17. Sync  Gateway:  App  Logic  &  Storage Couchbase   Smart  Client

    Revision/ Conflict   Management App’s  Sync   FuncOon to  Couchbase  Server function(doc,  oldDoc)  { … requireUser(oldDoc.owner); … channel(doc.channel); … access(doc.members,  doc.roomID); } validaOon AuthenOcaOon
  18. Sync  Gateway:  App  Logic  &  Storage Couchbase   Smart  Client

    Revision/ Conflict   Management App’s  Sync   FuncOon to  Couchbase  Server function(doc,  oldDoc)  { … requireUser(oldDoc.owner); … channel(doc.channel); … access(doc.members,  doc.roomID); } rouOng AuthenOcaOon
  19. Sync  Gateway:  App  Logic  &  Storage Couchbase   Smart  Client

    Revision/ Conflict   Management App’s  Sync   FuncOon to  Couchbase  Server function(doc,  oldDoc)  { … requireUser(oldDoc.owner); … channel(doc.channel); … access(doc.members,  doc.roomID); } access  ctrl AuthenOcaOon
  20. Sync  Gateway:  App  Logic  &  Storage Couchbase   Smart  Client

    Revision/ Conflict   Management App’s  Sync   FuncOon to  Couchbase  Server AuthenOcaOon
  21. Sync  Gateway:  App  Logic  &  Storage Couchbase   Smart  Client

    Revision/ Conflict   Management App’s  Sync   FuncOon to  Couchbase  Server rev 1 rev 2 rev 3a rev 3b AuthenOcaOon
  22. Sync  Gateway:  App  Logic  &  Storage Couchbase   Smart  Client

    Revision/ Conflict   Management App’s  Sync   FuncOon to  Couchbase  Server AuthenOcaOon
  23. What  Channels  Are  For proj1 proj2 public sales_Q1 jens Jens’

     phone Anil’s  phone Proj2 Press   Release
  24. What  Channels  Are  For proj1 proj2 public sales_Q1 jens Jens’

     phone Anil’s  phone Proj2 Press   Release
  25. What  Channels  Are  For App’s  Sync   FuncOon proj1 proj2

    public sales_Q1 jens Jens’  phone Anil’s  phone Proj2 Press   Release
  26. What  Channels  Are  For App’s  Sync   FuncOon public proj2

    proj1 proj2 public sales_Q1 jens Jens’  phone Anil’s  phone Proj2 Press   Release
  27. What  Channels  Are  For App’s  Sync   FuncOon public proj2

    proj1 proj2 public sales_Q1 jens Jens’  phone Anil’s  phone Proj2 Press   Release function(doc,  oldDoc)  { channel(doc.projectID); if  (doc.accessLevel  <  1)    channel(“public”); ... }
  28. What  Channels  Are  For App’s  Sync   FuncOon public proj2

    proj1 proj2 public sales_Q1 jens Jens’  phone Anil’s  phone Proj2 Press   Release
  29. What  Channels  Are  For App’s  Sync   FuncOon public proj2

    proj1 proj2 public sales_Q1 jens Jens’  phone Anil’s  phone Proj2 Press   Release
  30. What  Channels  Are  For App’s  Sync   FuncOon public proj2

    proj1 proj2 public sales_Q1 jens Jens’  phone Anil’s  phone Proj2 Press   Release
  31. Sync  Gateway  Components Sync REST  API Couchbase   Smart  Client

    Revision/ Conflict   Management AuthenOcaOon App’s  Sync   FuncOon Channel   Change   Tracking TAP  feed  from  server
  32. Sync  Gateway  Components Sync REST  API Couchbase   Smart  Client

    Revision/ Conflict   Management AuthenOcaOon App’s  Sync   FuncOon Channel   Change   Tracking TAP  feed  from  server
  33. Sync  Gateway  Components Sync REST  API Couchbase   Smart  Client

    Revision/ Conflict   Management AuthenOcaOon App’s  Sync   FuncOon Channel   Change   Tracking TAP  feed  from  server
  34. Sync  Gateway  Components Sync REST  API Couchbase   Smart  Client

    Revision/ Conflict   Management AuthenOcaOon App’s  Sync   FuncOon Channel   Change   Tracking TAP  feed  from  server
  35. Sync  Gateway  Components Sync REST  API Couchbase   Smart  Client

    Revision/ Conflict   Management AuthenOcaOon App’s  Sync   FuncOon Channel   Change   Tracking TAP  feed  from  server ZOMG SERVER PUSH!!
  36. Custom  User  AuthenOcaOon Sync  Gateway Session  Key   Generator Custom

     App  Server Couchbase  Lite LDAP,  etc. Auth Auth Back
  37. Custom  User  AuthenOcaOon Sync  Gateway Session  Key   Generator Custom

     App  Server Couchbase  Lite LDAP,  etc. Auth Auth Back
  38. Custom  User  AuthenOcaOon Sync  Gateway Session  Key   Generator Custom

     App  Server Couchbase  Lite LDAP,  etc. Auth Auth Back
  39. Custom  User  AuthenOcaOon Sync  Gateway Session  Key   Generator Custom

     App  Server Couchbase  Lite LDAP,  etc. Auth Auth Back
  40. Custom  User  AuthenOcaOon Sync  Gateway Session  Key   Generator Custom

     App  Server Couchbase  Lite LDAP,  etc. Auth Auth Back
  41. Custom  User  AuthenOcaOon Sync  Gateway Session  Key   Generator Custom

     App  Server Couchbase  Lite LDAP,  etc. Auth Auth Back
  42. Custom  User  AuthenOcaOon Sync  Gateway Session  Key   Generator Custom

     App  Server Couchbase  Lite LDAP,  etc. Auth Auth Back
  43. Custom  User  AuthenOcaOon Sync  Gateway Session  Key   Generator Custom

     App  Server Couchbase  Lite LDAP,  etc. Auth Auth Back
  44. Custom  User  AuthenOcaOon Sync  Gateway Session  Key   Generator Custom

     App  Server Couchbase  Lite LDAP,  etc. Auth Auth Back
  45. Data  Model  Differences Couchbase  Lite  /  Couchbase  Server • All

     docs  are  JSON;  no  binary  opOon • But  you  get  ahachments  (binary,  typed,  unlimited  size) • Revision  IDs  (_rev  field) ­ Revision  ID  matching  (MVCC)  instead  of  CAS ­ Mandatory,  not  opKonal • Revision  tree ­ Conflicts  cause  document  history  to  branch • No  counters  (INC/DEC  operaOons) • Views  never  fall  behind