Rails 7.2+ Multi Database Read-Write Proxy for Custom SQL (Makara Alternative)

Since the introduction of Rails 7.2 the gem Makara is no longer working. Until this point it definitely was the best Read-Write Proxy for Connections.

There currently does not seem to be a good alternative. Rails introduced a build-in read/write split with version 6, however the setup assumes a CRUD style application rather than a rich API. It’s hooked into routes rather than looking at the actual query content itself.

So while the build-in way does work well for ActiveRecord, any custom SQL is not being handled properly at this point in time.

The guys over at OLIOEX started working on their own implementation, which is only available for MySQL: - OLIOEX/janus-ar: A read/write ActiveRecord database adapter

They created a great post outlining the issue: Introducing Janus a read/write proxy for ActiveRecord 7.1+ | Olioverse

Makara is currently looking for someone to take over development, as InstaCart seems to have switched over to an in-house solution and will no longer maintain Makara.

This is a dealbreaker for us to upgrade to Rails 7.2, Rails 8 and beyond.

Ideally the built in Rails way would start to support custom SQL by checking for write prefixes like INSERT, UPDATE, DELETE, LOCK, CREATE, GRANT, DROP, ALTER, TRUNCATE, BEGIN, SAVEPOINT & FLUSH.

It would be great if someone from the core team can chime in here whether this is planned to be supported in the future directly. It certainly is a crucial feature for scaling Rails applications.

1 Like

Would implementing custom query detection (like checking for SQL command prefixes) in Rails’ built-in read/write splitting be a viable alternative to Makara for handling custom SQL in Rails 7.2+? Could this approach scale effectively without relying on third-party gems?

Yes I believe so - this is the same approach that the guys over at NASDAQ are taking now:

This is a good alternative to Makara now, though supporting this natively would still be valuable in my opinion.

1 Like

Hi Oskar, I’m the author of Janus, if you’re happy to help then I’m not against adding postgres support to the library :). I/we don’t work with it day to day so it would be more difficult for us to pick up any issues, but if there were people actively using postgres then its certainly something that could go in.