Add rate-limit module: Bucket4j 8.21 token buckets on Redis in a Spring Boot 4.1 filter, per-user/per-key/global limits, 429 with Retry-After, two instances sharing one bucket

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b7rnC7jppGGdHGESvy
This commit is contained in:
Claude
2026-10-28 18:27:06 +00:00
parent 99a8a0df42
commit fd0cf9b527
37 changed files with 1705 additions and 1 deletions
+18
View File
@@ -0,0 +1,18 @@
== free-key-123 allows 5 per minute; requests alternate between instance A and B
sent to A -> 200 remaining=4 (served by A)
sent to B -> 200 remaining=3 (served by B)
sent to A -> 200 remaining=2 (served by A)
sent to B -> 200 remaining=1 (served by B)
sent to A -> 200 remaining=0 (served by A)
sent to B -> 429 remaining=0 (served by -)
sent to A -> 429 remaining=0 (served by -)
allowed in total: 5 (not 10)
== one bucket in Redis, written by both instances
$ redis-cli --scan
rl:global
rl:key:c31ab6f47fba3609
== 200 concurrent requests for pro-key-456 (20 per minute), half to A and half to B
200 sent: 20 allowed, 180 rejected with 429
== instance B's clock is 30 s ahead of A's (user carol: 10 per minute, one token per 6 s)
A, bucket empty -> 429
B sees 30 s of refill that never happened on A's clock: 5 of 8 allowed