Ruby on Rails でデータベースの Sharding を実現する DataFabric プラグイン

RubyFlowより。

One of the lingering issues we’ve had to deal with over the last year in the Manage service is ActiveRecord’s reluctance to talk to more than one database. It’s really quite stubborn in that regard and while there are a few solutions out there, none of them worked quite like we wanted. Some required intrusive application-level code changes, some didn’t offer the features we needed, so we bit the bullet and wrote what we needed.

Specifically we needed two features to scale our mysql database: application-level sharding and master/slave replication. Sharding is the process of splitting a dataset across many independent databases. This often happens based on geographical region (e.g. craigslist) or user account (e.g. flickr). Replication provides a near-real-time copy of a database which can be used for fault tolerance and to reduce load on the master node. Combined, you get a scalable database solution which does not require huge hardware to scale to huge volumes. DataFabric extends ActiveRecord’s standard connection handling to provide these two features.

http://blog.fiveruns.com/2008/7/9/introducing-data_fabric

細分化(Sharding) とは、例えばユーザ名の先頭2文字を使うなどして、データセットを複数の独立したデータベースに分割する処理のことを指すらしい。
(ググったけど適当な日本語がなかったので、『細分化』と訳してみた。いい訳があれば教えてください。)
細分化は、データベースの分散方法としてはたいへん原始的であるが、partition とかのようにデータベース側に特別な機能が必要ないので、例えばMySQL4のような高機能でないデータベースでも使える方法である。ただしデータベース側に機能が必要ない分、アプリケーション側での作り込みが必要になる。

DataFabricは、ActiveRecord で Sharding を実現するためのプラグイン

class Auction < ActiveRecord::Base
  data_fabric :shard_by => :city, :replicated => true

のようにするだけで、Shardingが実現できるらしい。
アプリケーション側での作り込みがいらなくなるので、興味のある人は使ってみるといいかも。