34
CouchDB from 10.000ft with Jan Lehnardt <[email protected] > Not the best time for a talk, Easy content, just relax

Couch DB from 10 000 ft

Embed Size (px)

DESCRIPTION

from Erlang eXchange 2008

Citation preview

Page 1: Couch DB from 10 000 ft

CouchDB from 10.000ftwith Jan Lehnardt <[email protected]>

Not the best time for a talk,Easy content, just relax

Page 2: Couch DB from 10 000 ft

Why am I here?

• No clue

• Most speakers here

• are some sort of Erlang expert

• talk about something Erlangy

Page 3: Couch DB from 10 000 ft

Why am I here?

• Most speakers here

• are some sort of Erlang expert

• talk about something Erlangy

• I’m not and I don’t

Page 4: Couch DB from 10 000 ft

Maybe it’s CouchDB

• Written in Erlang

• You are probably not using it from Erlang

• The HTTP API is as easy in any language

Page 5: Couch DB from 10 000 ft

Maybe it’s CouchDB

• Shows what cool things can be done with Erlang

• So here is CouchDB an Erlang Case Study

Page 6: Couch DB from 10 000 ft

What is CouchDB?

• “DB” gives it away, really

• Not a relational database

• But a Document Database

Page 7: Couch DB from 10 000 ft

A Document Database?

• Concepts borrowed from the Notes Database (NOT from the client!)

• Data is not stored in tables and rows

• No need to design a schema

Real World Documents

Page 8: Couch DB from 10 000 ft

A Document Database?

• Data records are stored as individual documents

• Documents can have any structure and the structure can be made up on the fly

Page 9: Couch DB from 10 000 ft

The Documents in CouchDB

• Data stored in JSON format

• JSON stores native language objects in a portable way

• No ORM needed

Page 10: Couch DB from 10 000 ft

A JSON Example{ “_id”: ”123ABC”, “_rev”: ”BCCE34”, “name”: “Darth Vader”, “location”: { “name”:“Death Star”, “street”: “Galaxy Street 4”, “zip”: 56665 }, “favourite_colour”: “black”, “tools”: [“helmet”, “light sabre”]}

Page 11: Couch DB from 10 000 ft

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

Page 12: Couch DB from 10 000 ft

Updating a Document

• [insert gfx showing optimistic locking]

Page 13: Couch DB from 10 000 ft

Views

• “Filter, Collate & Aggregate”

• Bring structure to your data mess

• Map / Reduce powered1

• Defaults to JavaScript

• Incremental1 Tell audience how awesome it is!

Page 14: Couch DB from 10 000 ft

Views - Map TagsKeys Valuesfamily 1

friends 1

friends 1

work 1

work 1

youtube 1

… …

Page 15: Couch DB from 10 000 ft

Views - Reduce Tag Count

Keys Valuesfamily 1

friends 1

friends 1

work 1

work 1

youtube 1

… …

Keys Values

family 1

friends 2

work 2

youtube 1

… …

Page 16: Couch DB from 10 000 ft

Views - Map Tags

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

Page 17: Couch DB from 10 000 ft

Views - Reduce Tag Count

Keys Valuesfamily 1

friends 1

friends 1

work 1

work 1

youtube 1

… …

Keys Values

family 1

friends 2

work 2

youtube 1

… …

Page 18: Couch DB from 10 000 ft

Views - Reduce Tag Count

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

Incremental, On-demandreduce optional

Page 19: Couch DB from 10 000 ft

Replication – The Killer Feature

• Data synchronisation is the core of the solutions to many problems

• Works…

• Distributed / peer to peer

• Offline

Page 20: Couch DB from 10 000 ft

Replication – The Killer Feature

• (continued)

• Works…

• With any number of nodes

• Automatic conflict detection and resolution(!)

Page 21: Couch DB from 10 000 ft

Inherits all of Erlang’s Coolness

• Massive concurrency

• Fault tolerance

• Less code

• No downtime

• Excellent hardware utilisation

Page 22: Couch DB from 10 000 ft

The Storage Engine

• [my pet detail, but bear with me, it is cool!]

• ACID

• MVCC

• Append only

• Compaction

Page 23: Couch DB from 10 000 ft

Search API

• Lucene as a reference

• Works with any other search technology

• View engine works similar. Not a JavaScript fan? Use XYZ

Page 24: Couch DB from 10 000 ft

The Project

• Damien Katz is the man!

• Open Source

• Apache 2.0

• The Apache Software Foundation gives shelter in case IBM plays bad

Page 25: Couch DB from 10 000 ft

Questions?

Page 26: Couch DB from 10 000 ft

Questions?

• I prepared two

Page 27: Couch DB from 10 000 ft

One – Does it use Mnesia?

Page 28: Couch DB from 10 000 ft

One – Does it use Mnesia?

•No

Page 29: Couch DB from 10 000 ft

Two – Why?

Page 30: Couch DB from 10 000 ft

Two – Why?

• 2GB limit (at the time of research)

• Consistency check on restart not acceptable

Page 31: Couch DB from 10 000 ft

Two – Why?

• Mnesia Replication is good for clusters, not so much for disconnected and distributed edits

• Other “cool” feature not useful to CouchDB

Page 32: Couch DB from 10 000 ft

Two – Why?

• CouchDB’s storage engine is optimised – down to hard drive head seeks – for fast writes and super-fast index creation

Page 33: Couch DB from 10 000 ft

Your Questions?

Page 34: Couch DB from 10 000 ft

Bonus Slide

• 6k lines of Erlang

• A few lines of C code