Giter Site home page Giter Site logo

At least once semantics about zio-sqs HOT 4 OPEN

zio avatar zio commented on July 30, 2024
At least once semantics

from zio-sqs.

Comments (4)

reibitto avatar reibitto commented on July 30, 2024

I see there's retryDelay and retryMaxCount right now. I'm not sure if there's a different design to reconcile that with what I'm proposing.

The sealed trait I mentioned could maybe encode the concept of recoverable errors, unrecoverable errors, and maybe different retry policies (like Schedule.exponential) and so on. If we go with that kind of design, retryDelay and retryMaxCount kind of don't make sense anymore (it's too "global" of a setting).

This might require some more thought.

from zio-sqs.

reibitto avatar reibitto commented on July 30, 2024

To give a better idea of the alternate design I was thinking of:

sealed trait MessageAction
object MessageAction {
  case object Success extends MessageAction
  case object Ignore extends MessageAction
  case class Delay(delay: Duration) extends MessageAction
  case class RecoverableError[E](error: E, retryPolicy: Schedule[Clock, Any, Duration]) extends MessageAction
  case class UnrecoverableError[E](error: E) extends MessageAction
}

For the RecoverableError case you calculate whether to retry or not and for how long based on ZIO Schedule and the ApproximateReceiveCount header. That means you can do stuff like Schedule.exponential(1.second) && Schedule.recurs(10) and put it in RecoverableError to say "retry 10 times using exponential backoff" or anything else you can express with Schedule.

This design feels more "ZIO" to me than my original proposal.

And maybe you could make retryPolicy a default param, with Schedule.spaced(settings.retryDelay) && Schedule.recurs(settings.retryMaxCount) if you want to keep those settings and not make a breaking change.

from zio-sqs.

ghostdogpr avatar ghostdogpr commented on July 30, 2024

The retry stuff only exists on the Publisher right now. I understand the need for Delay as an equivalent to Akka ChangeMessageVisibility, but for retrying can't you just use the combinators on ZStream?

from zio-sqs.

reibitto avatar reibitto commented on July 30, 2024

Oops, missed the fact that retry was on ProducerSettings.

As for the relying on retries on ZStream for the consumer, that would work mostly fine in a single consumer case (with the exception of App restarts/crashes... you'll start retrying from 0 again). The issue is mostly with multiple consumers.

If you have multiple consumers in a distributed system pulling entries from the same queue, you can't share a ZIO retry policy between them. This is why I use ApproximateReceiveCount to drive retries and exponential backoff.

Another case for Delay(0) or Ignore: Let's say I'm doing a rolling deployment with my consumer nodes. They will be running different versions for a while. In this kind of case you may want to say, "I don't know how to handle this version of the message. Let some other consumer pick it up."

By the way, I created a separate issue in ZIO that's kind of a prerequisite for the retries I had in mind:
zio/zio#3468

from zio-sqs.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.