zio / zio-redis

A ZIO-based redis client
https://zio.github.io/zio-redis
Apache License 2.0
123 stars 63 forks source link

Asynchronous connection initialization in Layer #676

Open frekw opened 2 years ago

frekw commented 2 years ago

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).

drmarjanovic commented 1 year ago

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

mijicd commented 1 year ago

@drmarjanovic all yours

drmarjanovic commented 1 year ago

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

frekw commented 1 year ago

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 :)