Thanks everyone for the suggestions and tips!
On Tuesday, February 14, 2023 at 3:49:14 PM UTC-3 Jeremy Evans wrote:
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/3cec6bda-6df9-46b7-af9a-cedd516df963n%40googlegroups.com.

Reply via email to