Slide 1

Slide 1 text

!"

Slide 2

Slide 2 text

! I'M JULIA

Slide 3

Slide 3 text

2015

Slide 4

Slide 4 text

WEB DEVELOPER @ NEIGHBOURHOODIE SOFTWARE

Slide 5

Slide 5 text

!"

Slide 6

Slide 6 text

ON-CALL HORROR STORIES (OF MY FRIENDS) > Database Server going offline (panic!) > Failed attempt in scaling up causes corrupted & lost data I realised that CouchDB has some distinct features that I just took for granted

Slide 7

Slide 7 text

Apache CouchDB has started. Time to relax.

Slide 8

Slide 8 text

!" RELAX

Slide 9

Slide 9 text

RELAX? > ease of use JSON & HTTP ! works with all* Languages

Slide 10

Slide 10 text

RELAX? > fault-tolerant > build with anticipating failure > Couch = cluster of unreliable commodity hardware Build with Erlang

Slide 11

Slide 11 text

ERLANG robust & concurrent > developed for real-time telecom applications > extreme emphasis on reliability and availability

Slide 12

Slide 12 text

DOCUMENT DATABASE

Slide 13

Slide 13 text

DOCUMENT DATABASE ! > JSON > unique IDs > schema-free > attachments

Slide 14

Slide 14 text

COUCHDB DOCUMENT { "_id": "00001", "_rev": "1-A", "name": "Bulbasaur", "types": ["grass", "poison"], "abilities": ["Overgrow","Chlorophyll"], "catch_rate": 45 }

Slide 15

Slide 15 text

QUERYING

Slide 16

Slide 16 text

QUERYING > Map/Reduce > Mango > Primary Index > changes

Slide 17

Slide 17 text

MAP/REDUCE > runs func on every doc in the db (once!) this creates a view index (b-tree) > next time of query -> only runs on docs that have changed/are new

Slide 18

Slide 18 text

MAP > Creates index function myMapFunction(doc) { emit(doc.name); } > Query The index

Slide 19

Slide 19 text

REDUCE Already Build in: '_sum', '_count', '_stats' { map: function (doc) { emit(doc.name.charAt(0)); }, reduce: '_count' }

Slide 20

Slide 20 text

MANGO a DSL inspired by MongoDB > faster-performing & easier to use > ! since CouchDB 2.0.0

Slide 21

Slide 21 text

MANGO { selector: { name: { $eq: 'Pikachu' } } }

Slide 22

Slide 22 text

PRIMARY INDEX curl -X GET 127.0.0.1:5984/pokemon/00025 > Index by ID > Already there > super fast ! create your own IDs in a clever format

Slide 23

Slide 23 text

MAKE USE OF THE PRIMARY INDEX Example: Timeseries Data (Logs) > system has many devices > device sends log data ID Format: system:device:ISODate

Slide 24

Slide 24 text

MAKE USE OF THE PRIMARY INDEX Example: Timeseries Data (Logs) // get all logs of Device 1 of System 23 from January 2017, latest first await db.allDocs({ include_docs: true, startkey: `system23:device1:2017-01-`, endkey: `system23:device1:2017-01-\uffff`, descending: true })

Slide 25

Slide 25 text

REAL-TIME CHANGE NOTIFICATIONS > index by sequence /db/_changes > What changes happened in die database? > What change occurred to this document? > What changed since X?

Slide 26

Slide 26 text

REPLICATION CouchDB was designed with sync in mind, and this is exactly what it excels at.

Slide 27

Slide 27 text

REPLICATION { "_id": "00001", "_rev": "1-A", "name": "Bulbasaur", "types": ["grass", "poison"], "abilities": ["Overgrow","Chlorophyll"], "catch_rate": 45 }

Slide 28

Slide 28 text

REPLICATION { "_id": "00001", "_rev": "1-A", "name": "Bulbasaur", "types": ["grass", "poison"], "abilities": ["Overgrow","Chlorophyll"], "catch_rate": 45 } CouchDB requires you to manage revisions (_rev) (tedious but pays off in the end)

Slide 29

Slide 29 text

REPLICATION > MVCC (Multiversion concurrency control) > sequence index & revisions

Slide 30

Slide 30 text

REPLICATION > bi-directional replication (synchronization) > multi-primary architecture

Slide 31

Slide 31 text

REPLICATION ! ⬅ ☁☁☁ ↖ ☁☁☁ ↘ ☁☁ *

Slide 32

Slide 32 text

REPLICATION ! ⬅ ☁☁☁ ↖ ☁☁☁ ↘ ☁☁ * ↕ !

Slide 33

Slide 33 text

REPLICATION ! ⬅ ☁☁☁ ↖ ☁☁☁ ↘ ☁☁ * ! !

Slide 34

Slide 34 text

REPLICATION CONFLICTS > an arbitrary winner Revision is chosen by CouchDB > conflicting Revisions are also stored > no Data is lost > up to the application developer to decide what to do

Slide 35

Slide 35 text

COUCHDB 2.0 ( ! ! ) > (Amazon) Dynamo Paper > same API as Single Instance > ready for big data workloads

Slide 36

Slide 36 text

NEIGHBOURHOODIE SOFTWARE > CouchDB Consulting / Support / Workshops > ! Opservatory - CouchDB Monitoring > Greenkeeper - Javascript Dependency updates > (Offline-First) App Development Consulting

Slide 37

Slide 37 text

!

Slide 38

Slide 38 text

LINKS > CouchDB Docs > Offline-First Web App with Couch & Pouch Tutorial > Learn Mango Queries