On Tue, Feb 14, 2023 at 10:12 AM Tomás Miguez <[email protected]> wrote:

> Hello everyone!
>
> We are currently experiencing some database problems and would like to
> hear your opinions. Our database is sharded, and occasionally, one of the
> shards becomes inaccessible. When a service attempts to access it, a
> timeout exception is eventually raised. This can cause a service clog since
> the timeout takes some time to occur. We have found a solution for a
> similar issue with Redis by activating the circuit breaker functionality of
> the Redis' gem. Would it be advisable to implement a circuit breaker, or
> would a different approach be more suitable? Has there been any discussion
> about including it as part of the Sequel gem's functionality?
>
This is the first time someone has asked for circuit breaker functionality
in Sequel, as far as I know.  The issue with circuit breakers with Sequel
is that the implementation will heavily depend on the different adapter and
driver in use.  I doubt it's possible to write a generic circuit breaker
that supports all adapters/drivers that Sequel supports.  This isn't an
issue with Redis because Redis only needs to support a single driver.

One way to implement such a circuit breaker without directly integrating it
into Sequel would be to use the driver directly, sending simple queries at
a given frequency, making sure they complete within a given deadline, and
breaking the circuit if they don't. Then wrapping code that calls Sequel in
a circuit breaker check.  You can use Database#new_connection to create a
database connection object that is not added to the Database's connection
pool, and use that for checking whether the circuit is broken.

In terms of integrating such a circuit breaker into Sequel, I'm not sure
exactly what behavior would be desired.  The simplest behavior seems to be
to raise an error when attempting to check out a connection for a shard
with a broken circuit.  Not sure if that is sufficient, though.

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/CADGZSSehFy4MKMGaoLu-Bj6YV8DzhNy1rOBYwLRHk2TwHw2CiQ%40mail.gmail.com.

Reply via email to