Introducing Apache CouchDB 2.0 at ApacheCon

Introducing Apache CouchDB 2.0 at ApacheCon

Apache CouchDB is a document database featuring an HTTP API, JSON documents, and peer-to-peer replication. Take a tour of the upcoming features and improvements in Apache CouchDB 2.0 including clustering capabilities for horizontal scalability and a declarative MongoDB-style ad hoc querying system. This talk should be of interest to you whether you're new to Apache CouchDB or an experienced Apache CouchDB developer.

8896271ee9d6f46d4b1783c9566cb645?s=128

Bradley Holt

May 13, 2016
Tweet

Transcript

  1. ApacheCon Bradley Holt, Developer Advocate Friday, May 13, 2016 Introducing

    Apache CouchDB 2.0 @BradleyHolt
  2. @BradleyHolt

  3. None
  4. IBM Cloud Data Services Open for Data A comprehensive por.olio

    of open source data services
  5. What is Apache CouchDB?

  6. Document Database Apache CouchDB is a JSON document database

  7. HTTP API Apache CouchDB is accessed through an HTTP API

    @BradleyHolt GET / GET /db/doc POST /db DELETE /db/doc PUT /db/doc PUT /db
  8. Peer-to-Peer Replication @BradleyHolt Cloudant Sync CouchDB PouchDB CouchDB Replication Protocol

    CouchDB
  9. What's new in CouchDB 2.0?

  10. None
  11. None
  12. CouchDB 1.x: Standalone @BradleyHolt CouchDB

  13. CouchDB 2.0: Clusterered @BradleyHolt CouchDB node1 CouchDB node2 CouchDB node3

    haproxy
  14. Shards and Replicas §  q=8 –  Number of shards – 

    One or more shards per node –  Cannot have more nodes than shards §  r=2 –  Read quorum §  w=2 –  Write quorum §  n=3 –  Number of replicas of every document @BradleyHolt CouchDB node1 CouchDB node2 CouchDB node3
  15. Mango §  Declarative indexes §  MongoDB-style query language §  You

    can still use map/reduce views @BradleyHolt
  16. couch_peruser @BradleyHolt userdb-51d055 userdb-d76846 userdb-905cec userdb-adc95b userdb-c082f2 userdb-730bba userdb-c3d3e5 userdb-da

    userdb-a1ec1f db-85bcfe userdb-85a327 userdb-9b9aba
  17. None
  18. What else is new? §  Improved database compaction §  Faster

    index updates §  New _bulk_get endpoint for optimized replication §  View-based filters in _changes feed §  Filter _changes feed with _doc_ids §  _all_docs and _changes will support attachments=true @BradleyHolt
  19. CouchDB 2.0 Developer Preview

  20. None
  21. None
  22. None
  23. None
  24. None
  25. Apache CouchDB 2.0 Sandbox Cluster Try Apache CouchDB 2.0 on

    an IBM Cloudant sandbox cluster @BradleyHolt
  26. http-console

  27. http-console $ npm install http-console -g! $ http-console 127.0.0.1:5984! >

    http-console 0.6.3! > Welcome, enter .help if you're lost.! > Connecting to 127.0.0.1 on port 5984.! @BradleyHolt https://github.com/cloudhead/http-console
  28. http-console http://127.0.0.1:5984/> GET /! HTTP/1.1 200 OK! Content-Type: text/plain; charset=utf-8!

    ! {! couchdb: 'Welcome',! version: '9afa6a0',! vendor: { name: 'The Apache Software Foundation' }! } @BradleyHolt https://github.com/cloudhead/http-console
  29. http-console http://127.0.0.1:5984/> .q @BradleyHolt https://github.com/cloudhead/http-console

  30. http-console $ http-console https://bradley-holt.cloudant.com! > http-console 0.6.3! > Welcome, enter

    .help if you're lost.! > Connecting to bradley-holt.cloudant.com on port 443.! @BradleyHolt https://github.com/cloudhead/http-console
  31. http-console https://bradley-holt.cloudant.com:443/> GET /! HTTP/1.1 200 OK! Content-Type: application/json! !

    {! couchdb: 'Welcome',! version: '9d28c57',! vendor: {! name: 'IBM Cloudant',! version: '5331',! variant: 'paas'! },! features: [ 'geo' ]! }! @BradleyHolt https://github.com/cloudhead/http-console
  32. http-console https://bradley-holt.cloudant.com:443/> .q @BradleyHolt https://github.com/cloudhead/http-console

  33. Exploring the CouchDB API

  34. Connecting to CouchDB 2.0 $ http-console root:passw0rd@127.0.0.1:5984 --json! > http-console

    0.6.3! > Welcome, enter .help if you're lost.! > Connecting to 127.0.0.1 on port 5984.! @BradleyHolt
  35. Connecting to IBM Cloudant $ http-console https://bradley-holt:passw0rd@bradley-holt.cloudant.com --json! > http-console

    0.6.3! > Welcome, enter .help if you're lost.! > Connecting to bradley-holt.cloudant.com on port 443.! @BradleyHolt
  36. Request Headers /> .headers! Accept: application/json! Content-Type: application/json! Authorization: Basic

    cm9vdDorMi95N3Y2aA==! Host: 127.0.0.1! @BradleyHolt
  37. PUT a Database /> PUT /kittens! ... ! HTTP/1.1 201

    Created! Content-Type: application/json! Location: http://127.0.0.1/kittens! ! { ok: true }! @BradleyHolt
  38. PUT a Database Again /> PUT /kittens! ... ! HTTP/1.1

    412 Precondition Failed! Content-Type: application/json! ! { error: 'file_exists', reason: 'The database could not be created, the file already exists.' }! @BradleyHolt
  39. POST a Document /> /kittens! @BradleyHolt

  40. POST a Document /kittens> POST /! ... { "_id": "mittens",

    "age_weeks": 10, "weight_kilograms": 0.997 }! HTTP/1.1 201 Created! Content-Type: application/json! Location: http://127.0.0.1/kittens/mittens! ! {! ok: true,! id: 'mittens',! rev: '1-e665a40d9ea9711c983e907f0b0b6e8a'! }! @BradleyHolt
  41. GET All Documents /kittens> GET /_all_docs! HTTP/1.1 200 OK! Content-Type:

    application/json! Etag: "92afa0f309a9fd9f140cd31ff5000b5c"! ! {! total_rows: 1,! offset: 0,! rows: [! {! id: 'mittens',! key: 'mittens',! value: { rev: '1-e665a40d9ea9711c983e907f0b0b6e8a' }! }! ]! }! @BradleyHolt
  42. GET a Document /kittens> GET /mittens! HTTP/1.1 200 OK! Content-Type:

    application/json! Etag: "1-e665a40d9ea9711c983e907f0b0b6e8a"! ! {! _id: 'mittens',! _rev: '1-e665a40d9ea9711c983e907f0b0b6e8a',! age_weeks: 10,! weight_kilograms: 0.997! }! @BradleyHolt
  43. PUT an Attachment /kittens> .headers! Accept: application/json! Content-Type: application/json! Authorization:

    Basic cm9vdDorMi95N3Y2aA==! Host: 127.0.0.1! /kittens> Content-Type: image/gif! @BradleyHolt
  44. PUT an Attachment /kittens> PUT /mittens/photo?rev=1-e665a40d9ea9711c983e907f0b0b6e8a! ... R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=! HTTP/1.1 201

    Created! Content-Type: application/json! Location: http://127.0.0.1/kittens/mittens/photo! ! {! ok: true,! id: 'mittens',! rev: '2-d858e51453a5785bafe517b7eddc5a98'! }! /kittens> Content-Type: application/json! @BradleyHolt
  45. GET an Attachment /kittens> GET /mittens/photo! HTTP/1.1 200 OK! Content-Type:

    image/gif! Etag: "UsqjdPnY6ApD2ENFOglFHg=="! ! R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=! @BradleyHolt
  46. Conditional Caching /kittens> If-None-Match: "UsqjdPnY6ApD2ENFOglFHg=="! /kittens> GET /mittens/photo! HTTP/1.1 304

    Not Modified! ! /kittens> If-None-Match:! @BradleyHolt
  47. DELETE a Document /kittens> DELETE /mittens! HTTP/1.1 409 Conflict! Content-Type:

    application/json! ! { error: 'conflict', reason: 'Document update conflict.' }! @BradleyHolt
  48. DELETE a Document /kittens> HEAD /mittens! HTTP/1.1 200 OK! Etag:

    "2-d858e51453a5785bafe517b7eddc5a98"! ! @BradleyHolt
  49. DELETE a Document /kittens> If-Match: "2-d858e51453a5785bafe517b7eddc5a98"! /kittens> DELETE /mittens! HTTP/1.1

    200 OK! Content-Type: application/json! ! {! ok: true,! id: 'mittens',! rev: '3-d0780627ddff7a7f536fe273100cec41'! }! /kittens> If-Match:! @BradleyHolt
  50. Replication /kittens> ..! /> DELETE /kittens! HTTP/1.1 200 OK! Content-Type:

    application/json! ! { ok: true }! @BradleyHolt
  51. Replication /> POST /_replicate! ... { "create_target": true, "source": "https://bradley-holt.cloudant.com/

    kittens", "target": "kittens" }! HTTP/1.1 200 OK! Content-Type: application/json! ! {! ok: true,! session_id: '9f7bd286a0001ece5bf0bf65dd83c5ab',! source_last_seq: '5- g1AAAAFDeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtVLykxPyilN1UvOyS9NScwr0ctLLckBKmRKZEiy___ _f1YiA6oWQ9xakhyAZFI9SFcGcyJzLpDHbplmZmxkaULYBKIdlscCJBkagBTQov2kuA- i8wBEJ9iNTGA3mhoampmnGBA2JQsA1LtoyA',! …! }! @BradleyHolt
  52. None
  53. Mango /> /kittens! @BradleyHolt

  54. Mango /kittens> POST /_index! ... { "index": { "fields": [

    "age_weeks", "weight_kilograms" ] } }! HTTP/1.1 200 OK! Content-Type: application/json! ! {! result: 'created',! id: '_design/e19dde7f518129a966ebe072edc66be88d54e694',! name: 'e19dde7f518129a966ebe072edc66be88d54e694'! }! @BradleyHolt
  55. @BradleyHolt

  56. Mango /kittens> POST /_find! ... { "selector": { "age_weeks": {

    "$gte": 7, "$lte": 10 } }, "fields": [ "_id", "age_weeks" ] }! HTTP/1.1 200 OK! Content-Type: application/json! ! {! docs: [! { _id: 'tiger', age_weeks: 7 },! { _id: 'daisy', age_weeks: 9 },! { _id: 'mittens', age_weeks: 10 }! ]! }! @BradleyHolt
  57. @BradleyHolt

  58. @BradleyHolt

  59. @BradleyHolt

  60. Mango /kittens> POST /_find! ... { "selector": { "age_weeks": {

    "$gte": 0 }, "weight_kilograms": { "$gte": 0.5, "$lte": 1 } }, "fields": [ "_id", "weight_kilograms" ] }! HTTP/1.1 200 OK! Content-Type: application/json! ! {! docs: [! { _id: 'tiger', weight_kilograms: 0.726 },! { _id: 'daisy', weight_kilograms: 0.816 },! { _id: 'mittens', weight_kilograms: 0.997 }! ]! }! @BradleyHolt
  61. @BradleyHolt

  62. @BradleyHolt

  63. @BradleyHolt

  64. Contributing

  65. None
  66. None
  67. Offline Camp June 24th - 26th, Catskill Mountains

  68. offlinefirst.org/camp

  69. Image Credits §  paper by malik, on Flickr <https://flic.kr/p/aZjTXv> § 

    person by Tim Morgan, on Flickr <https://flic.kr/p/7DSF5> §  database by Tim Morgan, on Flickr <https://flic.kr/p/7DUk5> §  gear by Tim Morgan, on Flickr <https://flic.kr/p/7DSF1> §  Mango with section on a white background by bangdoll, on Flickr <https://flic.kr/p/9CBP2h> @BradleyHolt
  70. Questions? @BradleyHolt