Skip to content

How to keep state between app restarts? #250

How to keep state between app restarts? #250
Apr 13, 2022 · 3 answers · 3 replies


I'm trying to learn how to integrate bucket4j on our API. One requisite is that I must keep the rate-limit state between app restarts. For example, if I define a limit of 1 calls per hour, deploying our app should not restart the rate-limit counters (even though the app itself will restart).

Is there any simple path to fulfill this requisite? Any way to load/save the state from/to a file should work.

Kind regards


3 suggested answers
3 replies

Hello @lgfischer

Do you to persist state only for graceful restart? What would you plan to do when your application crashed unexpectedly(as result bucket state is not persisted between restart)?

0 replies

Hi @vladimir-bukhtoyarov, thank you for your help.

I'm looking to save the rate-limit state every minute and before the app restart. We do daily deploys, so graceful app restarts are very common. Our app rarely crashes, and losing the last-minute state changes is acceptable in these cases.

Kind regards

2 replies

I have performed quick investigation of currently available abilities and did not find correct way to achieve your requirements.

It looks that desired functionality can be achieved by extending the API of LocalBucket

public byte[] toSnapshot();

static LocalBucket fromSnapshot(byte[] snapshot) {

Most likely I will have a time to implement this feature at the beginning of May.


Thank you very much, @vladimir-bukhtoyarov! I will investigate this API.

Kind regards

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