Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract and restore state #339

Open
algattik opened this issue Mar 6, 2022 · 3 comments
Open

Extract and restore state #339

algattik opened this issue Mar 6, 2022 · 3 comments

Comments

@algattik
Copy link

algattik commented Mar 6, 2022

I am working on extending an open source application for distributed data exchange that uses failsafe. One thing the application does is serve as a mediator, accepting and persisting HTTP requests that it needs to relay to other instances at scale.

For this, the application persists requests to a local database (used similarly to a work queue), and moves them through a state machine. There may be hundreds of requests to dozens of remote servers waiting there to be fulfilled. If the remote server can't be reached, we need to figure out what behaviour to implement for resilience. Potentially this could involve a few cycles of fast retry, after which we just leave that request in the database in its current state, to be processed again later. For that, it might be useful to be able to extract the retry and circuit breaker state to persist it to the database.

e.g.

 Failsafe.with(retryPolicy).withStateFrom(jsonString)...
@jhalterman
Copy link
Member

jhalterman commented Jul 8, 2022

I'd look at the API slightly differently, where this is about wanting to serialize/deserialize a policy config, which is a fair enough request. For example, this could look something like:

RetryPolicy<Object> retryPolicy = RetryPolicy.builder(RetryPolicyConfig.fromJson(jsonString));

Failsafe.with(retryPolicy)...

This would allow you to create a "new" RetryPolicy, CircuitBreaker, etc, from config stored in a file. I'm not sure if that's exactly what you're after though, or if you'd want to also serialize the state of the policy as well? For example, a CircuitBreaker's internal state tracks how many successes and failures have occurred, potentially over some time period. IMO, serializing config may be fair game, but serializing state may be more hassle than it's worth (since serialization formats can change, breaking things, etc).

FWIW, you should be able to serialize policy config yourself and re-create a policy if needed just using the policy.getConfig() and Policy.builder() methods.

@algattik
Copy link
Author

algattik commented Jul 8, 2022

The idea here is to serialise the state. We have items processed by N workers from a work queue, they pick up one work item, attempt I/O, and then on failure serialise it back with the necessary state information so that the next worker will not hammer the external server.

We have resolved this by implementing our own policy outside of failsafe and persisting # of retries, last retry time, circuit status etc. along with the work item. It would be nice to have this within failsafe, but I agree with you that unless others are requesting the same feature, it might be more cruft than it's worth.

@whiskeysierra
Copy link

whiskeysierra commented Jul 8, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants