Introduction into CouchDB / Jan Lehnardt

Post on 09-Jun-2015

5.642 views 1 download

description

In this talk - Jan Lenhnardt introduces Apache CouchDB. CouchDB is a distributed, fault-tolerant and schema-free document-oriented database accessible via a RESTful HTTP/JSON API. Among other features, it provides robust, incremental replication with bi-directional conflict detection and resolution, and is queryable and indexable using a table-oriented view engine with JavaScript acting as the default view definition language. A video of this talk can be found at http://bbcwebdevelopers.blip.tv/ as

Transcript of Introduction into CouchDB / Jan Lehnardt

CouchDB

Who’s talking?

Jan Lehnardt, project member, web developer, curious person.

jan@apache.org / @janl

And you?

What can you expect today?

Built for the Future“640k processors should be enough for anybody.”

Single-user machinesBack then

Multi-user machinesNow

Application: ScienceBack then

Application: InternetToday

Monolithic machinesBack then

Lots of small serversToday

CPU, RAM and disks == $$$Back then

Components cheaperNow

RDBMS vsJust Storing Data

RDBMS vs Just Storing Data

Design schema upfront

Write or use software to translate your data into that schema

…and back1) beware of speed considerations without having an app to measure2) or use an ORM which turns out to be a pain in the back for all sorts of reasons3) Most Data is not inherently relational

RDBMS vs Just Storing Data

Isolated data records called Documents

No schema (!)

data records that make up the app’s data objects

Documents in the Real World

Documents in the Real World

Bills, tax forms, letters…

Same type != same structure

Can be out of date

Natural data behaviour

Actual data record, no pointer

CouchDB Documents

JSON Format

Similar to XML

Easy to read and write (unlike XML)

XML does too much for us

CouchDB Documents{ “_id”: ”BCCD12CBB”, “_rev”: ”AB764C”, “type”: ”person”, “name”: ”Darth Vader”, “age”: 63, “headware”: [“Helmet”, “Sombrero”], “dark_side”: true}

CouchDB Documents{ “_id”: ”BCCD12CBB”, “_rev”: ”AB764C”, “type”: ”person”, “name”: ”Darth Vader”, “age”: 63, “headware”: [“Helmet”, “Sombrero”], “dark_side”: true}

Natural type mapping between languagesRevisionsAttachments

CouchDB Documents{ “_id”: ”BCCD12CBB”, “_rev”: ”AB764C”, “type”: ”person”, “name”: ”Darth Vader”, “age”: 63, “headware”: [“Helmet”, “Sombrero”], “dark_side”: true}

Natural type mapping between languagesRevisionsAttachments

CouchDB Documents{ “_id”: ”BCCD12CBB”, “_rev”: ”AB764C”, “type”: ”person”, “name”: ”Darth Vader”, “age”: 63, “headware”: [“Helmet”, “Sombrero”], “dark_side”: true}

Natural type mapping between languagesRevisionsAttachments

HTTP REST API

CRUD

HTTP REST API

Powers the World Wide Web

Supported everywhere

Lots of tools available

Working With a Document – The REST API

Create: HTTP PUT /db/docid Read: HTTP GET /db/docidUpdate: HTTP POST /db/docidDelete: HTTP DELETE /db/docid

HTTP around for ages, simple, proven,scales, tools available

Views

Views

Filter, Collate, Aggregate

Powered by Map/Reduce

Design documentsfunctions get executed, you don’t do that

Views - Map Tags

Keys Values

family 1

friends 1

friends 1

work 1

work 1

youtube 1

… …

Views - Reduce Tag Count

Keys Values

family 1

friends 1

friends 1

work 1

work 1

youtube 1

… …

Keys Values

family 1

friends 2

work 2

youtube 1

… …

Views - Map Tags

function (doc) { for(var i in doc.tags) emit(doc.tags[i], 1);}

Views - Reduce Tag Count

Keys Values

family 1

friends 1

friends 1

work 1

work 1

youtube 1

… …

Keys Values

family 1

friends 2

work 2

youtube 1

… …

Views - Reduce Tag Count

function (Key, Values) { var sum = 0; for(var i in Values) sum += Values[i]; return sum;}

Incremental, On-demandreduce optional

Views

Built incrementally…

…and on demand

Reduce optional

map/reduce can be parallelised

Replication

Replication

Take your data with you

CouchDB makes it easy to synchronise machines

rsync-likeLarge spectrum of architectures: - P2P, Failover, Load Balancing, BackupConflicts: auto-detect & resolve, data consistency

Built for the Future

Written in Erlang - a telco-grade concurrent platform

Non-locking MVCC and ACID compliant data store

Erlang Processes + messagingEricsson AXD 301 - nine nines - 1/30th second per yearCrash resistant

Number Bragging

Silly read-only benchmark with memory saturation

2,500 req/s sustained on a 2Ghz dual core Athlon

Number Bragging

Silly read-only benchmark with memory saturation

2,500 req/s sustained on a 2Ghz dual core Athlon

Using 9.8 MB RAM

A Little History

Damien Katz self funded fulltime development for 2 years

Now backed by IBM

A Little History

Accepted to the Apache Software Foundation

Open Source License

Resources

http://couchdb.org/

http://couchdbwiki.com/

http://damienkatz.net/

http://jan.prima.de/

http://blog.racklabs.com/?p=74

not covered everything,other talks + tutorialshow to join

Hired me, thanks!$$$£££/€€€.

Thank YouReally, thanks.

Got it?Questions