On Wed, Nov 4, 2020 at 12:22 AM Janko Marohnić <[email protected]>
wrote:

> Hi everyone,
>
> I'm comparing a bit Active Record's implementation of primary/replica
> selection with Sequel. Active Record requires you to manually switch the
> connection to a replica, and has a Rack middleware that can do this
> switching based on HTTP verbs, which I'm very skeptical about.
>
> On the Ruby Day conference, I asked Eileen why didn't GitHub go the route
> of having Active Record automatically use replica for reads (like Sequel),
> and the answer was that it was due to the replication lag, where the newly
> updated data will not be immediately available on the replica, so it's
> dangerous to write something to a primary and then try to immediately read
> it from a replica.
>
> If this is really the general case, does that make Sequel's approach of
> automatically using replica for reads less useful? I still like Sequel's
> approach much better, I just want to better understand the trade-offs.
>

You are correct, it's a tradeoff.  With Sequel's design and a
primary/replica setup, a read query directly after a write query outside of
a transaction may not see the updated value.  IIRC, the Rails rack
middleware bases the decision on whether to use the primary on a timeout
from when the last POST (or similar non-idempotent request method) was
used.  So directly after a POST, the same session will use the primary and
see up-to-date data, but other sessions would still see stale data from the
replica until it is caught up.

Considering that ActiveRecord focuses on being used only inside Rails,
where the rack middleware is used by default, it seems a good tradeoff.
Sequel has a more general focus, not being restricted to web requests, and
I think Sequel's default makes sense.  I'm guessing it wouldn't be too hard
to copy the Rails middleware and modify it to support Sequel if you wanted
similar behavior to Rails inside web requests.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/CADGZSSfXJZDPRDNj8C5rhQ91LE9na%2B6zk1%3Dqu4P-8n%2B_FpX13w%40mail.gmail.com.

Reply via email to