In this demo, I implemented rate limiter with sliding window algorithm.
Note that in production, if your backend sits behind a load balancer, you will need to get the remote Ip from the header:
String ipAddress = request.getHeader("X-FORWARDED-FOR");
Requirement:
- Redis
- Java 8
For Redis client, I used Lettuce, which is shipped by default with Spring.
How to run:
- Run a local Redis server. I used the Redis image from Docker.
- Then just run ./gradlew bootRun