Hacker News new | ask | show | jobs
by peteforde 2503 days ago
It's a lot more than talking to pg and mysql at the same time, thankfully!

https://edgeguides.rubyonrails.org/active_record_multiple_da...

In short, to do this feature family properly and in an opinionated, predictable way means that you have to cover a number of non-trivial cases. Multiple primaries and their replicas is just the beginning:

- automatic connection switching on a per-model basis

- Automatic swapping between the primary and replica depending on the HTTP verb and recent writes

- Rails tasks for creating, dropping, migrating, and interacting with the multiple databases

Sharding, cross-cluster joins and load balancing replicas are coming soon.

I think what's important here is that every site over a certain scale previously needed to implement their own take on this, and there were a lot of thorny edge cases, race conditions and heisenbugs to do so. It's kind of like the old chestnut that if you find yourself writing original crypto code, you're probably doing it very wrong.

The fact that any project can uncomment a few lines and get all of this for free is properly awesome.