Skip to content
tchandy edited this page Sep 14, 2010 · 8 revisions

Ideas

Octopus works using the Proxy Pattern . Basically, Octopus build a proxy between ActiveRecord and Database Connection. The proxy object handles the way of executing queries, when send to multiple shards, or send to master when the database is replicated. Default behaviours are:

  • Replication: Writes queries are sent to master, and reads queries are sent to slaves.
  • Sharding: Writes/Reads queries are sent to master, unless you specified a shard to send the query.

Each ActiveRecord objects know their current shard, that is setted after the object is created using callbacks. Example:

 
ree-1.8.7-2010.02 > user = User.using(:slave1).create!(:name => "Thiago")
 => #<User id: 1, name: "Thiago", birthday: nil, created_at: "2010-07-15 17:35:10", updated_at: "2010-07-15 17:35:10"> 
ree-1.8.7-2010.02 > user.current_shard
 => :slave1 
Clone this wiki locally