Database sharding and Rails

前端 未结 6 1559
南方客
南方客 2021-02-02 01:35

What\'s the best way to deal with a sharded database in Rails? Should the sharding be handled at the application layer, the active record layer, the database driver layer, a pr

6条回答
  •  北荒
    北荒 (楼主)
    2021-02-02 01:53

    Connecting Rails to multiple databases is not a big deal- you simply have an ActiveRecord subclass for each shard that overrides the connection property. That makes it pretty simple if you need to make cross-shard calls. You then just have to write a little code when you need to make calls between the shards.

    I don't like Hank's idea of splitting the rails instances, because it seems challenging to call the code between the instances unless you have a big shared library.

    Also you should look at doing something like Masochism before you start sharding.

提交回复
热议问题