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

Error: KV PUT failed: 429 Too Many Requests #34

Open
dopufol opened this issue Nov 11, 2024 · 2 comments
Open

Error: KV PUT failed: 429 Too Many Requests #34

dopufol opened this issue Nov 11, 2024 · 2 comments
Assignees

Comments

@dopufol
Copy link

dopufol commented Nov 11, 2024

Few issues I see when using hono-rate limiter with Cloudflare KV.

Workers KV has a maximum of 1 write to the same key per second. Writes made to the same key within 1 second will cause rate limiting (429) errors to be thrown. A retry might be needed.
Error: KV PUT failed: 429 Too Many Requests

Another issue is about setting the expiration, in Cloudflare KV, Expiration targets that are less than 60 seconds into the future are not supported. This is true for both expiration methods. When updating the kv, the expiration date might be less than 60 seconds from last time.
Error: KV PUT failed: 400 Invalid expiration of 1731388191. Expiration times must be at least 60 seconds in the future.

Finally, for the concurrent write issue,
"Due to the eventually consistent nature of KV, concurrent writes to the same key can end up overwriting one another."
"If concurrent writes are made to the same key, the last write will take precedence."

does this mean if concurrent requests come in from the same ip, the kv might not be able to increment properly?

@MathurAditya724
Copy link
Member

Yes, these are the limitations in the KV-based rate limiting, that's why I created support for the Durable Object Store too. The basic idea is that the KV is global and the Durable Object is regional, which helps it have an edge over KV.

@MathurAditya724 MathurAditya724 self-assigned this Nov 21, 2024
@MathurAditya724
Copy link
Member

MathurAditya724 commented Dec 18, 2024

Related PR #40

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

No branches or pull requests

2 participants