We're working on an RoR app that has a spiky demand curve (think online
sweepstakes). As a result we need to handle a large number of
simultaneous requests. We're using MySQL as our db as we have on
several previous (non-RoR) projects. In the past we've found MySQL
master/slave replication to be very useful. Unfortunately, RoR doesn't
seem to have an easy mechanism to support this feature as it needs to
distinguish database reads from writes and route them to the
So, we had an idea inspired by MySQL's Connector/J
We were thinking of creating a new ActiveRecord::ConnectionAdaptor
that supports a pool of connections. The YAML for this type of
connector in database.yml would take an array of masters and slaves.
Database read statements (ie. SELECT, DESCRIBE, SHOW TABLES) would be
routed to one of slaves (randomly). Database writes and transactions
would be routed to one of the masters.
The API looks quite clean but, as we are new to RoR, we were wondering
if there is some fatal flaw that we hadn't considered. Does this sound
like a good idea?