Lone Star Ruby Conference 2010... by Jesse Wolgamott
Dive into the target audiences and differences in NoSQL storage, how to implement them and what this NoSQL thing is all about.
Discuss how SQL has limits when you get to web-scale and how NoSQL bypasses these limits.
9. API: COUCHDB
POST /somedatabase/ HTTP/1.0
Content-Length: 245
Content-Type: application/json
{
"Subject":"I like Plankton",
"Author":"Rusty",
"PostedDate":"2006-08-15T17:30:12-04:00",
"Tags":["plankton", "baseball", "decisions"],
"Body":"I decided today that I don't like baseball. I like plankton."
}
-----------------
GET /somedatabase/some_doc_id HTTP/1.0
-------------------
HTTP/1.1 200 OK
Date: Thu, 17 Aug 2006 05:39:28 +0000GMT
Content-Type: application/json
Connection: close
{
"_id":"some_doc_id",
"_rev":"946B7D1C",
"Subject":"I like Plankton",
"Author":"Rusty",
"PostedDate":"2006-08-15T17:30:12Z-04:00",
"Tags":["plankton", "baseball", "decisions"],
"Body":"I decided today that I don't like baseball. I like plankton."
}
10. API: COUCHPOTATO
class User
include CouchPotato::Persistence
property :age, :type => Fixnum
property :receive_newsletter, :type => :boolean
end
CouchPotato.database.save_document User.new
11. API: MONGODB
Mongoid MongoMapper
class Person class Person
include Mongoid::Document include MongoMapper::Document
field :name key :name, String, :required=>true
embeds_many :phones many :phones
references_many :addresses has_many :addresses
end end
Person.create {:name=>”Darth Vader”} Person.create {:name=>”Darth Vader”}
12. MM V GOID
Mongoid uses ActiveModel Mongoid uses ARel, MM:
(Rails3). custom DSL
MongoMapper is more like Mongoid has Master/Slave
Rails 2 with Validatable
MM is more familiar for
MongoMapper has better Active Record
relational association
support
13. API: RAVENDB
PUT http://localhost:8080/docs/bobs_address
{
FirstName: 'Bob',
LastName: 'Smith',
Address: '5 Elm St'
}
---------------
GET http://localhost:8080/docs/bobs_address
---------------
HTTP/1.1 200 OK
{
"FirstName": "Bob",
"LastName": "Smith",
"Address": "5 Elm St."
}
var companies = session.Query<Company>("CompaniesByRegion")
.Where(x => x.Region == "Asia")
.Take(5);
14. API: SIMPLEDB
Amazon’s Restful... This is rest?
Answer: No (IMHO). And returns XML
https://sdb.amazonaws.com/?Action=PutAttributes
&DomainName=MyDomain
&ItemName=Item123
&Attribute.1.Name=Color&Attribute.1.Value=Blue
&Attribute.2.Name=Size&Attribute.2.Value=Med
&Attribute.3.Name=Price&Attribute.3.Value=0014.99
&AWSAccessKeyId=<valid_access_key>
&Version=2007-11-07
&Signature=Dqlp3Sd6ljTUA9Uf6SGtEExwUQE=
&SignatureVersion=2
&SignatureMethod=HmacSHA256
&Timestamp=2007-06-25T15%3A01%3A28-07%3A00
20. VERSIONING
CouchDB has Multi Versioning Concurrency Control
Compaction removes old revs, only the latest rev is represented in view queries, and only the latest revision is
replicated.
you can only depending on having a single version of the document available.
Especially in Multi-Master
Mongoid::Versioning (has_many versions)
RavenDB - Versioning Built In
21. VERSIONING
CouchDB and Mongoid
Mongomapper class Person
include Mongoid::Document
Roll your Own
include Mongoid::Versioning
Using many versions as embedded # keep at most 5 versions of a record
documents max_versions 5
end
RavenDB
<appSettings>
<add key="Raven/Versioning/MaxRevisions"
value="50"/>
<add key="Raven/Versioning/Exclude"
value="Comments;LogEntries;"/>
</appSettings>
28. QUERY: RAVENDB
MapReduce Indexes
Raven process them in the background, executing the
queries against the stored documents and persisting the
results to a Lucene index
Raven executes your indexes in the background, and the
results are written to disk.
Indexes are written in LINQ
45. LITTLE BIT OF CODE
MLB 2000-2009 Game Data used in Demo
The information used here was obtained free of charge from and is copyrighted by Retrosheet.
Interested parties may contact Retrosheet at "www.retrosheet.org".
Load Time Experience - 24000‘ish Games
Load Time in Seconds
Mongo 77.6 seconds
Couch 355.1 seconds