22. Riak
• Combo key-value store and
document database
• HTTP REST interface
• “Link walking”
• Map-Reduce
Thursday, March 11, 2010
23. Map/Reduce
• Massively parallel way to
process large datasets
• First you scour data and “map” a
new set of data
• Then you “reduce” the data
down to a salient result
Thursday, March 11, 2010
24. map = function() {
this.tags.forEach(function(tag) {
emit(tag, {count: 1});
});
}
reduce = function(key, values) {
var total = 0;
for (var i = 0; i < values.length; i++) {
total += values[i].count;
return {count: total};
}
Thursday, March 11, 2010
25. Tokyo Cabinet
Dynomite
MemcachedDB
Voldemort
Thursday, March 11, 2010
50. The Hard Way:
Do it by hand.
Thursday, March 11, 2010
51. class Post
include MongoMapper::Document
key :title, String
key :body, String
key :tags, Array
key :user_id, Integer
def user
User.find_by_id(self.user_id)
end
def user=(some_user)
self.user_id = some_user.id
end
end
class User < ActiveRecord::Base
def posts(options = {})
Post.all({:conditions => {:user_id => self.id}}.merge(options))
end
end
Thursday, March 11, 2010
52. Pros & Cons
• Simple, maps to your domain
• Works for small, simple ORM intersections
• MUCH simpler in Rails 3
• Complex relationships are a mess
• Makes your models fat
• As DRY as the ocean
Thursday, March 11, 2010
54. DataMapper
• Generic, relational ORM
• Speaks pretty much everything
you’ve ever heard of
• Implements Identity Map
• Module-based inclusion
Thursday, March 11, 2010
55. DataMapper.setup(:default, "mysql://localhost")
DataMapper.setup(:mongodb, "mongo://localhost/posts")
class Post
include DataMapper::Resource
def self.default_repository_name; :mongodb; end
property :title, String
property :body, String
property :tags, Array
belongs_to :user
end
class User
include DataMapper::Resource
property :email, String
property :name, String
has n, :posts
end
Thursday, March 11, 2010
56. Pros & Cons
• The ultimate Polyglot ORM
• Simple relationships between persistence
engines are easy
• Jack of all trades, master of none
• Perpetuates (sometimes) false assumptions
• Legacy stuff is in ActiveRecord anyway
Thursday, March 11, 2010
57. Is there a better way?
Thursday, March 11, 2010
61. Can’t we just sit
down and talk to
each other?
Thursday, March 11, 2010
62. class Post
include MongoMapper::Resource
key :title, String
key :body, String
key :tags, Array
gloo :active_record do
belongs_to :user
end
end
class User < ActiveRecord::Base
gloo :mongo_mapper do
many :posts
end
end
Thursday, March 11, 2010
63. Goals/Status
• Be able to define relationships
on the terms of any ORM from
any class, ORM or not
• Right Now: Partially working
ActiveRecord relationships
• Doing it wrong? Maybe
Thursday, March 11, 2010
64. Code Time:
Schema4Less
Thursday, March 11, 2010
65. Social Storefront
• Dummy application of a store that
lets others “follow” your purchases (a
less creepy Blippy?)
• Four requirements:
• users
• purchasing
• listings
• social graph
Thursday, March 11, 2010
66. Users
• I already have an authentication
system
• I’m happy with it
• It’s Devise and ActiveRecord
• Stick with SQL
Thursday, March 11, 2010
67. Purchasing
• Users need to be able to purchase
items from my storefront
• I can’t lose their transactions
• I need full ACID
• I’ll use MySQL
Thursday, March 11, 2010
68. Social Graph
• I want activity streams and one
and two way relationships
• I need speed
• I don’t need consistency
• I’ll use Redis
Thursday, March 11, 2010
69. Product Listings
• I am selling both movies and
books
• They have very different
properties
• Products are relatively non-
relational
• I’ll use MongoDB
Thursday, March 11, 2010