zio-redis icon indicating copy to clipboard operation
zio-redis copied to clipboard

Asynchronous connection initialization in Layer

Open frekw opened this issue 2 years ago • 4 comments

Hi!

Today the RedisExecutor seems to connect synchronosly when the layer is constructed, which means that my application is unable to start if Redis is currently unavailable. I think it would be preferable if initializing the connection happened asynchronously (or if the user could choose between the two).

frekw avatar Nov 14 '22 17:11 frekw

@mijicd I would like to pick this up if no one started working on this?

drmarjanovic avatar Feb 02 '23 16:02 drmarjanovic

@drmarjanovic all yours

mijicd avatar Feb 02 '23 16:02 mijicd

Hi!

I've investigated this a little bit and I just want to be sure what is the expected behavior.

Currently, we have the following scenarios:

  1. Redis is unavailable
  2. Start the example app
  3. Nothing happens, the application is closed

and

  1. Redis is available
  2. Start the example app
  3. The application is up and running
  4. Redis becomes unavailable
  5. The application is still running, but queries are going to fail

So, I'm just wondering, do you want a lazy init? Even if Redis is down, do you still want your application up and running and to start failing when Redis is actually invoked?

@frekw @mijicd

drmarjanovic avatar Feb 07 '23 21:02 drmarjanovic

This is the behaviour I would want, which is essentially that of a connection pool (perhaps a job for ZPool?)

  1. Redis is unavailable
  2. My application is able to start
  3. Queries fail
  4. Redis becomes available
  5. Queries work
  6. Redis becomes unavailable
  7. Queries fail
  8. etc

But e.g a common scenario would be that when Redis goes down, application load increases. And if I can't spawn new instances of my application when Redis is down I'm unable to auto scale to meet the load :)

frekw avatar Feb 08 '23 00:02 frekw