1: we are here at rubyfringe with Damien Katz. How about you introduce yourself?
I am the creator and Project Leader of couchdb. I currently work for IBM. Before that I worked for MySQL and before that I worked at IBM again on a project called Lotus Notes.
2: So what's this couchdb thing that we see on your T-shirt?
so what is couchdb? Couchdb is a document database; it's a replicated document database with a rest interface which means that it is accessible over HTTP, using standard get, put, post verbs. and it uses JavaScript as its query language to create views of your data. it's schemaless Unlike SQL databases where you have to define a bunch of tables with all the data types and sizes. with couchdb each document is its own independent object and it can be any sort of JSON structure. that's kind of a technical description but what is it good for, it's good for building lots of collaborative applications, lots of Web applications which generally are centered around documents, context, to-do's, bug reports, things like that. and that's the sort of stuff couchdb excels.
3: How wocould you compare it to other products like lotus notes which I think is also document based in a way. or XML databases which are similar, I think. how wocould you put it in that area?
SO, it's most like lotus notes because I worked so policyears on Lotus Notes, I got a really good grasp on Lotus Notes 'whole platform, and what is actually good about it, there were a whole lot of crap piled out on Lotus Notes and a lot of people really disliked it, but it's been successful for a reason. it's been around for a long time and it still got like a hundred million users. so there is something there and I felt like I had a pretty good idea of the core of Lotus Notes what was actually powerful about that, so that's what I tried to extract down and make it in couchdb. it was that document model. so it definitely works most like Lotus Notes. XML databases where you have these very, very, large single XML documents, they aren't really quite the same model, so I don't know. I haven't used them that much but I know they are kind of different.
4: So basically couchdb works by you inserting a lot of unstructured events. How do you search in them? How do you index them? I think you use JavaScript for it?
yes. generally each document won't have a random structure. the specified Ents will have some sort of predefined structures but it's not enforced by the database, being enforced by the application layer. eventually we wowould have hooks into the database where you can enforce when provided ENTs are saved that they adhere to a specific format or schema. but generally speaking the specified Ents don't have to follow any sort of schema, it's the application. so it gives you a lot of flexibility, how you want to display the data. if you want to display a bunch of comments, for example you have a discussion database and you want to display the main topics, or you want to display the comments, or you want to display all the documents by a certain user, it's really easy to do that with couchdb.
5: How wocould you do a query in couchdb? What do you use? What language?
you use JavaScript and you create these views. if you know the name of the document, each document has its own ID, this can be any source string or it can just be randomly generated, so if you know the name you coshould just ask for it, do a get for the document. if you want to create a view of all the documents of a certain type, then you create a JavaScript function, and that function will be used by the view engine and it will be fed every document in the database, and your function then decides what information in that document does it want to admit into the view. and then it admits a key and a value and the key sorts the value into the view. so every document that the function gets run over it can admit whatever it likes. and then those values and the view are collected and displayed. and then you do a get on the view and you get back a JSON response of all these nicely formatted results.
6: Do these run for every query? Or do they run through all the clients, instance of caching?
It runs over all the documents, but it keeps a persisted index so that every time you run it, it just has to use the index. when your ENTs are updated, five your ENTs are updated, it doesn't have to go run over all the documents in the database to recreate this index. instead, it just figures out the specified ents that have changed, and recomputes the results, eliminates the old results and adjusts the index and then you can query it. all that happens automatically, all you do is you create the view definition and you access it, And couchdb handles it, doing all this things for you.
7: You chose an interesting language for implementing couchdb, Erlang. What's the main reason for that?
Yes, so the original versions of couchdb were written in C ++, and I kind of hit the wall. I had a storage engine, I had a view engine and I had a query language, that I had written in C ++ and I hit the wall with the concurrency issues. so, I always had to do conventional threading with locks and messaging and things like that. and I read about Erlang on Lambda the ultimate or something like that it has been a really good concurrent language, so I decided I was going to figure how I cocould integrate that with my code base. so I played around with it, downloaded it and it didn't take long before I just decided that it was perfectly suited for writing a database engine and server and I threw away all my C and C ++ code and rewrote everything in Erlang and it's been fantastically productive for that. it's excellent for infrastructure type stuff, it's designed for Telecom. telecom has a lot of the same issues that you have with databases, lots of input, output, has to be reliable, has to deal with failure gracefully. so, it ended up being a perfect language for that.
8: How do you integrate JavaScript, is JavaScript runtime in Erlang? Is that the same process?
So we have the Mozilla spider monkey engine and what we have is a separate executable, a command line process that links in the Mozilla spider monkey engine and it talks to couchdb over standard Io, so couchdb actually spawns instances of this process and then couchdb sends JSON over standard out and then it gets the response via the pipe that it creates. then, if the Javascript process hangs or uses too much memory or whatever and it gets killed by the OS, the Erlang VM is still fine and we recover with no problem.
9: This protocol that you use over the pipe, that's just JSON messages?
it's just JSON getting pushed back and forth. so you have a command and the command acts like a verb and it will just be a string, an array and then the arguments will be subsequent elements and the array, and Pushes that need SS and then it gets parsed on the other side, and then it figures out what you are asking for, then it computes the result and sends it back. and the nice thing about having a simple line based protocol like that is that we can swap up the language backend. so right now the standard engine is JavaScript but we already have a language backend for Ruby and python, maybe other languages ages I think somebody wrote one for PHP too, so you can write your queries in whatever language you want. I know that it became actually very popular with the python community right now.
10: you are using Erlang's features for reliability. I figure you liked that for couchdb. Do you also use sort of scalability features?
definitely for concurrency. somebody did some early benchmarks on couchdb and they wowould probably get twenty thousands simultaneous connections. that was pretty impressive. and we haven'teven done any profiling yet. definitely Erlang helps us in that area. if I had written this using conventional threading model, you were lucky to get five hundred active connections, so definitely Erlang helps with single machine scalability. erlang will also help with Multi machine scalability but we are not really using Erlang for that yet, but it has a whole lot of tools and libraries and things like that to allow for Multi machine Erlang environments for automated fail over and efficient messaging and things like that. and we just haven'ttaken advantage of it yet.
11: Did you see any benefits from Erlang and SMP versions? Or didn't that make any difference?
I hadn't profiled it, I think that the person who profiled it, profiled it with the Multi Processor around, so I don't think anybody actually profiled it with the single processing version of Erlang.
12: One thing you recently or some time ago wrote a blog about what you didn't like about Erlang. So what's your current position on that? Did anything change?
yes, most of those complaints are still there, but every language has things that you dislike about it. some of the things in Erlang are old. if you are designing it to modern day, you wouldn't have made these decisions and some of it is kind of inherent to the programming paradigm like you can't fix that without breaking other things that are very right with Erlang, so there are things that are frustrating about it. it has very poor string handling, something that I think cocould be improved. but if your problems don't fit well into the functional paradigm, then maybe you shoshould just use a different language.
13: What's your top three complaints: the string handling, Unicode support, something like that?
I think string handling right now is the issue that is always there. it's really inefficient right now, so not only has it been cumbersome doing a lot of the string stuff that, if you are using a language like Ruby or Python, wocould be much easier, much cleaner, so not only was it harder to write code out there, it's also slower. so yes, that's an issue. but we are also trying to address that, we are trying to use a different style of strings where each string is a element in a list and it actually ends up taking sixteen bytes just to store a single character. and then it has binary strings which are more like conventional strings in other programming ages, the syntax for those is ugly of course, but I think we are going to switch over to them anyway because it's way more efficient.
14: Well coming back to the document database. What are document databases like Lotus Notes for instance? What are they special good? What is Lotus Notes for instance used?
A good analogy I wocould like to use, as an exercise for you to figure out what's a god application for a document database. if you weren't doing this application, if it weren't computerize, how wocould you do it in the real world? And if it ends up being lots of pieces of paper that are filed away and passed around to different people, that's a really good indication that a document database is the right place. if it ends up being the kind of problem like a pain program or single spreadsheet, it's all locked down, so for an accountant, what do they call them? They are spreadsheets on paper, those are the things that can't be split up, they have to be a single document. in those cases that means that it probably shocould be a single application but if you have a bunch of these statements they are constantly getting spread around like to-do lists, bug list, customer complaints, these are the kind of things that in the real world they wocould be generating stacks of paper. and that's when you shoshould really start to consider maybe a relational database is the ideal place and maybe a document database is, and with couchdb's nature where you can actually take the documents with you offline and then edit them and then later when you are online replicate the changes back, that's definitely something that is very difficult to do with a relational database. so any time you need that offline capability to access your data and edit your data, that's when a document database like couchdb wocould really excel.
15: that's also what Lotus is used for in big companies.
Yes, Lotus is still extensively used, for people a lot of time think of lotus as just an email platform but it's actually an application development platform for documents.
16: Did it start out this way, or did it start as email?
It started of that way and one of the first applications built on top of it as being a document oriented database was email. so it is email and that's one of its top applications, but it's just another application in the Lotus Notes stack. but Lotus also has all these other applications so you can do bug tracking and customer reports and CRM type stuff and it's used extensively by a lot of companies for that sort of thing.
17: So wocould you say that this document database concept, this has been around for some time with Lotus Notes, this has been available in other products, or it seams to be becoming popular with couchdb.
exchange wanted to be something like that a long time ago, they had the Exchange Server, they had this concept with shared folders where you were supposed to build the applications on that. and that never really worked out, nobody really used it for that, so there have been other attempts to build things like that and then of course anything on the web like a Sharepoint works very much like Lotus Notes, but it's a single instance Web server of Lotus Notes and you use your browser client, but it's still doing a lot of the same things, it still is very document oriented type of environment. so there have been other things but Lotus Notes is in my mind the only thing that really got it right. even though it got a whole lot wrong, in addition to that. I always thought that Lotus Notes was still kind of unique in the market place and that is why I really wanted to build couchdb because I thought that model had been under appreciated and under already ed.
18: You want to bring that document model to the open source. it seams to be a lot of other paradigms for databases as a competition to a relational databases like Google's bigtable. what do you think about that?
bigtable-I don't really quite get the benefits of it, other than scalability. I definitely see the benefits in that way but for most applications that people want to build, they don't need that sort of scalability. it's kind of a limited platform but I haven't actually used it, so I don't know, I just read some of the complaints.
19: Do you see it as an alternative to a document based concept or do you see it as a different model do you think?
I do think it's a different model, they don't have the same view model. the really key to couchdb is the view model where you can create these views that are generated to index all your data. and bigtable is just this big key-value table store and not really sure that's powerful enough to build interesting applications.