{"id":338,"date":"2025-12-13T05:55:00","date_gmt":"2025-12-13T05:55:00","guid":{"rendered":"https:\/\/harshad-sonawane.com\/blog\/?p=338"},"modified":"2025-12-15T12:53:12","modified_gmt":"2025-12-15T12:53:12","slug":"api-rate-limiting-throttling-in-spring-boot-with-bucket4j","status":"publish","type":"post","link":"https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/","title":{"rendered":"API Rate Limiting &amp; Throttling in Spring Boot with Bucket4j"},"content":{"rendered":"<p data-start=\"235\" data-end=\"551\">As modern systems continue to embrace <a href=\"https:\/\/harshad-sonawane.com\/blog\/reduce-cloud-costs-java-applications\/\">microservices<\/a>, public APIs, and high-volume traffic, controlling how consumers access APIs becomes critical. Without proper rate limiting, even a single misbehaving client can overwhelm your application\u2014leading to degraded performance, increased latency, and potential downtime.<\/p>\n<p data-start=\"553\" data-end=\"805\"><strong data-start=\"553\" data-end=\"570\">Rate limiting<\/strong> and <strong data-start=\"575\" data-end=\"589\">throttling<\/strong> safeguard your APIs by controlling the number of requests a client can make within a specific time window. In <a href=\"https:\/\/harshad-sonawane.com\/blog\/audit-logging-in-java-microservices-techniques-and-compliance-tips\/\">Spring Boot<\/a>, one of the most effective and developer-friendly libraries for this purpose is <strong data-start=\"792\" data-end=\"804\">Bucket4j<\/strong>.<\/p>\n<p data-start=\"807\" data-end=\"1054\">This guide provides a clear, practical look at implementing API rate limiting using Bucket4j, covering architectural considerations, token bucket mechanics, real-world examples, and integration patterns for both monolithic and <a href=\"https:\/\/harshad-sonawane.com\/blog\/eventual-consistency-distributed-java-systems\/\">distributed systems<\/a>.<\/p>\n<hr data-start=\"1056\" data-end=\"1059\" \/>\n<h1 data-start=\"1061\" data-end=\"1103\">Understanding Rate Limiting &amp; Throttling<\/h1>\n<p data-start=\"1105\" data-end=\"1206\">Rate limiting ensures clients do not exceed predefined request quotas. It protects applications from:<\/p>\n<ul data-start=\"1208\" data-end=\"1356\">\n<li data-start=\"1208\" data-end=\"1226\">\n<p data-start=\"1210\" data-end=\"1226\">Traffic spikes<\/p>\n<\/li>\n<li data-start=\"1227\" data-end=\"1259\">\n<p data-start=\"1229\" data-end=\"1259\">Abuse or brute-force attacks<\/p>\n<\/li>\n<li data-start=\"1260\" data-end=\"1293\">\n<p data-start=\"1262\" data-end=\"1293\">Over-consumption of resources<\/p>\n<\/li>\n<li data-start=\"1294\" data-end=\"1308\">\n<p data-start=\"1296\" data-end=\"1308\">API misuse<\/p>\n<\/li>\n<li data-start=\"1309\" data-end=\"1356\">\n<p data-start=\"1311\" data-end=\"1356\">Out-of-memory and thread starvation crashes<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"1358\" data-end=\"1390\">Rate Limiting vs. Throttling<\/h3>\n<div class=\"_tableContainer_1rjym_1\">\n<div class=\"group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse\" tabindex=\"-1\">\n<table data-start=\"1392\" data-end=\"1618\" class=\"w-fit min-w-(--thread-content-width)\">\n<thead data-start=\"1392\" data-end=\"1413\">\n<tr data-start=\"1392\" data-end=\"1413\">\n<th data-start=\"1392\" data-end=\"1402\" data-col-size=\"sm\">Concept<\/th>\n<th data-start=\"1402\" data-end=\"1413\" data-col-size=\"md\">Meaning<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"1435\" data-end=\"1618\">\n<tr data-start=\"1435\" data-end=\"1522\">\n<td data-start=\"1435\" data-end=\"1455\" data-col-size=\"sm\"><strong data-start=\"1437\" data-end=\"1454\">Rate Limiting<\/strong><\/td>\n<td data-start=\"1455\" data-end=\"1522\" data-col-size=\"md\">Restricts the number of requests allowed in a given time frame.<\/td>\n<\/tr>\n<tr data-start=\"1523\" data-end=\"1618\">\n<td data-start=\"1523\" data-end=\"1540\" data-col-size=\"sm\"><strong data-start=\"1525\" data-end=\"1539\">Throttling<\/strong><\/td>\n<td data-start=\"1540\" data-end=\"1618\" data-col-size=\"md\">Delays or slows down requests when rate limits are approached or exceeded.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p data-start=\"1620\" data-end=\"1675\">Both mechanisms prevent overload and ensure fair usage.<\/p>\n<hr data-start=\"1677\" data-end=\"1680\" \/>\n<h1 data-start=\"1682\" data-end=\"1697\">Why Bucket4j?<\/h1>\n<p data-start=\"1699\" data-end=\"1835\">Bucket4j is a Java-native library that implements the <strong data-start=\"1753\" data-end=\"1779\">Token Bucket Algorithm<\/strong>, a widely used method for managing request consumption.<\/p>\n<h3 data-start=\"1837\" data-end=\"1865\">Key Features of Bucket4j<\/h3>\n<ul data-start=\"1867\" data-end=\"2087\">\n<li data-start=\"1867\" data-end=\"1903\">\n<p data-start=\"1869\" data-end=\"1903\">Lightweight and high-performance<\/p>\n<\/li>\n<li data-start=\"1904\" data-end=\"1935\">\n<p data-start=\"1906\" data-end=\"1935\">Millisecond-level precision<\/p>\n<\/li>\n<li data-start=\"1936\" data-end=\"2011\">\n<p data-start=\"1938\" data-end=\"2011\">Built-in support for distributed caching (Hazelcast, Redis, Infinispan)<\/p>\n<\/li>\n<li data-start=\"2012\" data-end=\"2050\">\n<p data-start=\"2014\" data-end=\"2050\">Supports multiple bandwidth limits<\/p>\n<\/li>\n<li data-start=\"2051\" data-end=\"2087\">\n<p data-start=\"2053\" data-end=\"2087\">Thread-safe and production-ready<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"2089\" data-end=\"2092\" \/>\n<h1 data-start=\"2094\" data-end=\"2132\">How the Token Bucket Algorithm Works<\/h1>\n<p data-start=\"2134\" data-end=\"2232\">A <em data-start=\"2136\" data-end=\"2144\">bucket<\/em> contains a predefined number of tokens.<br data-start=\"2184\" data-end=\"2187\" \/>Each incoming request <strong data-start=\"2209\" data-end=\"2231\">consumes one token<\/strong>.<\/p>\n<ul data-start=\"2234\" data-end=\"2408\">\n<li data-start=\"2234\" data-end=\"2278\">\n<p data-start=\"2236\" data-end=\"2278\">Tokens are <strong data-start=\"2247\" data-end=\"2259\">refilled<\/strong> at a fixed rate.<\/p>\n<\/li>\n<li data-start=\"2279\" data-end=\"2343\">\n<p data-start=\"2281\" data-end=\"2343\">If the bucket is empty \u2192 the request is <em data-start=\"2321\" data-end=\"2340\">denied or delayed<\/em>.<\/p>\n<\/li>\n<li data-start=\"2344\" data-end=\"2408\">\n<p data-start=\"2346\" data-end=\"2408\">This ensures predictable, constant enforcement of rate limits.<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"2410\" data-end=\"2418\">Example:<\/p>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\">\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs\"><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre!\"><span><span class=\"hljs-number\">20<\/span> requests <span class=\"hljs-keyword\">per<\/span> <span class=\"hljs-keyword\">minute<\/span><br \/>\nBucket capacity: <span class=\"hljs-number\">20<\/span> tokens<br \/>\nRefill rate: <span class=\"hljs-number\">20<\/span> tokens<span class=\"hljs-operator\">\/<\/span><span class=\"hljs-keyword\">minute<\/span><br \/>\n<\/span><\/code><\/div>\n<\/div>\n<hr data-start=\"2509\" data-end=\"2512\" \/>\n<h1 data-start=\"2514\" data-end=\"2552\">Implementing Bucket4j in Spring Boot<\/h1>\n<h2 data-start=\"2554\" data-end=\"2579\">Step 1: Add Dependency<\/h2>\n<h3 data-start=\"2581\" data-end=\"2590\">Maven<\/h3>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\">\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs\"><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre! language-xml\"><span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">dependency<\/span><\/span>&gt;<br \/>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">groupId<\/span><\/span>&gt;com.github.vladimir-bukhtoyarov<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">groupId<\/span><\/span>&gt;<br \/>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">artifactId<\/span><\/span>&gt;bucket4j-core<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">artifactId<\/span><\/span>&gt;<br \/>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">version<\/span><\/span>&gt;8.8.0<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">version<\/span><\/span>&gt;<br \/>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">dependency<\/span><\/span>&gt;<br \/>\n<\/span><\/code><\/div>\n<\/div>\n<p data-start=\"2758\" data-end=\"2807\">(Optional Redis\/Hazelcast integration available.)<\/p>\n<hr data-start=\"2809\" data-end=\"2812\" \/>\n<h1 data-start=\"2814\" data-end=\"2853\">Step 2: Create a Rate Limiting Filter<\/h1>\n<p data-start=\"2855\" data-end=\"2928\">A common implementation is applying rate limiting per API path or per IP.<\/p>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\">\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs\"><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre! language-java\"><span><span class=\"hljs-meta\">@Component<\/span><br \/>\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">RateLimitFilter<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title class_\">OncePerRequestFilter<\/span> {<\/p>\n<p>    <span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-keyword\">final<\/span> Map&lt;String, Bucket&gt; bucketCache = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\"><a href=\"https:\/\/harshad-sonawane.com\/blog\/advanced-java-collections-internals-performance\/\">ConcurrentHashMap<\/a><\/span>&lt;&gt;();<\/p>\n<p>    <span class=\"hljs-keyword\">private<\/span> Bucket <span class=\"hljs-title function_\">createNewBucket<\/span><span class=\"hljs-params\">()<\/span> {<br \/>\n        <span class=\"hljs-type\">Refill<\/span> <span class=\"hljs-variable\">refill<\/span> <span class=\"hljs-operator\">=<\/span> Refill.intervally(<span class=\"hljs-number\">10<\/span>, Duration.ofMinutes(<span class=\"hljs-number\">1<\/span>));<br \/>\n        <span class=\"hljs-type\">Bandwidth<\/span> <span class=\"hljs-variable\">limit<\/span> <span class=\"hljs-operator\">=<\/span> Bandwidth.classic(<span class=\"hljs-number\">10<\/span>, refill);<br \/>\n        <span class=\"hljs-keyword\">return<\/span> Bucket.builder().addLimit(limit).build();<br \/>\n    }<\/p>\n<p>    <span class=\"hljs-keyword\">private<\/span> Bucket <span class=\"hljs-title function_\">resolveBucket<\/span><span class=\"hljs-params\">(String clientKey)<\/span> {<br \/>\n        <span class=\"hljs-keyword\">return<\/span> bucketCache.computeIfAbsent(clientKey, k -&gt; createNewBucket());<br \/>\n    }<\/p>\n<p>    <span class=\"hljs-meta\">@Override<\/span><br \/>\n    <span class=\"hljs-keyword\">protected<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title function_\">doFilterInternal<\/span><span class=\"hljs-params\">(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)<\/span><br \/>\n            <span class=\"hljs-keyword\">throws<\/span> ServletException, IOException {<\/p>\n<p>        <span class=\"hljs-type\">String<\/span> <span class=\"hljs-variable\">clientId<\/span> <span class=\"hljs-operator\">=<\/span> request.getRemoteAddr();<br \/>\n        <span class=\"hljs-type\">Bucket<\/span> <span class=\"hljs-variable\">bucket<\/span> <span class=\"hljs-operator\">=<\/span> resolveBucket(clientId);<\/p>\n<p>        <span class=\"hljs-keyword\">if<\/span> (bucket.tryConsume(<span class=\"hljs-number\">1<\/span>)) {<br \/>\n            filterChain.doFilter(request, response);<br \/>\n        } <span class=\"hljs-keyword\">else<\/span> {<br \/>\n            response.setStatus(HttpStatus.TOO_MANY_REQUESTS.value());<br \/>\n            response.getWriter().write(<span class=\"hljs-string\">\"Rate limit exceeded. Try again later.\"<\/span>);<br \/>\n        }<br \/>\n    }<br \/>\n}<br \/>\n<\/span><\/code><\/div>\n<\/div>\n<hr data-start=\"4025\" data-end=\"4028\" \/>\n<h1 data-start=\"4030\" data-end=\"4070\">Step 3: Register Filter in Spring Boot<\/h1>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\">\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs\"><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre! language-java\"><span><span class=\"hljs-meta\">@Configuration<\/span><br \/>\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">FilterConfig<\/span> {<\/p>\n<p>    <span class=\"hljs-meta\">@Bean<\/span><br \/>\n    <span class=\"hljs-keyword\">public<\/span> FilterRegistrationBean&lt;RateLimitFilter&gt; <span class=\"hljs-title function_\">rateLimiter<\/span><span class=\"hljs-params\">(RateLimitFilter filter)<\/span> {<br \/>\n        FilterRegistrationBean&lt;RateLimitFilter&gt; registrationBean = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">FilterRegistrationBean<\/span>&lt;&gt;();<br \/>\n        registrationBean.setFilter(filter);<br \/>\n        registrationBean.addUrlPatterns(<span class=\"hljs-string\">\"\/api\/*\"<\/span>);<br \/>\n        <span class=\"hljs-keyword\">return<\/span> registrationBean;<br \/>\n    }<br \/>\n}<br \/>\n<\/span><\/code><\/div>\n<\/div>\n<hr data-start=\"4463\" data-end=\"4466\" \/>\n<h1 data-start=\"4468\" data-end=\"4510\">Applying Multiple Rate Limits (Optional)<\/h1>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\">\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs\"><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre! language-java\"><span><span class=\"hljs-type\">Bandwidth<\/span> <span class=\"hljs-variable\">minuteLimit<\/span> <span class=\"hljs-operator\">=<\/span> Bandwidth.classic(<span class=\"hljs-number\">100<\/span>, Refill.intervally(<span class=\"hljs-number\">100<\/span>, Duration.ofMinutes(<span class=\"hljs-number\">1<\/span>)));<br \/>\n<span class=\"hljs-type\">Bandwidth<\/span> <span class=\"hljs-variable\">hourlyLimit<\/span> <span class=\"hljs-operator\">=<\/span> Bandwidth.classic(<span class=\"hljs-number\">1000<\/span>, Refill.intervally(<span class=\"hljs-number\">1000<\/span>, Duration.ofHours(<span class=\"hljs-number\">1<\/span>)));<\/p>\n<p><span class=\"hljs-type\">Bucket<\/span> <span class=\"hljs-variable\">bucket<\/span> <span class=\"hljs-operator\">=<\/span> Bucket.builder()<br \/>\n        .addLimit(minuteLimit)<br \/>\n        .addLimit(hourlyLimit)<br \/>\n        .build();<br \/>\n<\/span><\/code><\/div>\n<\/div>\n<p data-start=\"4829\" data-end=\"4862\">This enforces layered protection.<\/p>\n<hr data-start=\"4864\" data-end=\"4867\" \/>\n<h1 data-start=\"4869\" data-end=\"4907\">Distributed Rate Limiting with Redis<\/h1>\n<p data-start=\"4909\" data-end=\"5028\">For microservices running multiple pods\/instances, in-memory buckets are insufficient. Use Redis to share bucket state.<\/p>\n<h3 data-start=\"5030\" data-end=\"5055\">Add Redis dependency:<\/h3>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\">\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs\"><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre! language-xml\"><span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">dependency<\/span><\/span>&gt;<br \/>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">groupId<\/span><\/span>&gt;com.github.vladimir-bukhtoyarov<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">groupId<\/span><\/span>&gt;<br \/>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">artifactId<\/span><\/span>&gt;bucket4j-redis<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">artifactId<\/span><\/span>&gt;<br \/>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">version<\/span><\/span>&gt;8.8.0<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">version<\/span><\/span>&gt;<br \/>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">dependency<\/span><\/span>&gt;<br \/>\n<\/span><\/code><\/div>\n<\/div>\n<h3 data-start=\"5224\" data-end=\"5255\">Create Redis-backed bucket:<\/h3>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\">\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs\"><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre! language-java\"><span><span class=\"hljs-type\">Bucket<\/span> <span class=\"hljs-variable\">bucket<\/span> <span class=\"hljs-operator\">=<\/span> Bucket4j.extension(RedisBucket4jExtension.getDefault())<br \/>\n        .builder()<br \/>\n        .addLimit(Bandwidth.simple(<span class=\"hljs-number\">50<\/span>, Duration.ofSeconds(<span class=\"hljs-number\">60<\/span>)))<br \/>\n        .build(redisProxy);<br \/>\n<\/span><\/code><\/div>\n<\/div>\n<p data-start=\"5453\" data-end=\"5507\">This ensures consistent throttling across the cluster.<\/p>\n<hr data-start=\"5509\" data-end=\"5512\" \/>\n<h1 data-start=\"5514\" data-end=\"5552\">Best Practices for API Rate Limiting<\/h1>\n<h3 data-start=\"5554\" data-end=\"5594\">1. Choose the Right Limit Strategy<\/h3>\n<ul data-start=\"5595\" data-end=\"5656\">\n<li data-start=\"5595\" data-end=\"5605\">\n<p data-start=\"5597\" data-end=\"5605\">Per IP<\/p>\n<\/li>\n<li data-start=\"5606\" data-end=\"5618\">\n<p data-start=\"5608\" data-end=\"5618\">Per user<\/p>\n<\/li>\n<li data-start=\"5619\" data-end=\"5634\">\n<p data-start=\"5621\" data-end=\"5634\">Per API key<\/p>\n<\/li>\n<li data-start=\"5635\" data-end=\"5656\">\n<p data-start=\"5637\" data-end=\"5656\">Per tenant (SaaS)<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"5658\" data-end=\"5693\">2. Monitor Rate Limit Metrics<\/h3>\n<p data-start=\"5694\" data-end=\"5698\">Use:<\/p>\n<ul data-start=\"5700\" data-end=\"5746\">\n<li data-start=\"5700\" data-end=\"5719\">\n<p data-start=\"5702\" data-end=\"5719\">Spring Actuator<\/p>\n<\/li>\n<li data-start=\"5720\" data-end=\"5734\">\n<p data-start=\"5722\" data-end=\"5734\"><a href=\"https:\/\/harshad-sonawane.com\/blog\/monitoring-java-applications-prometheus-grafana-kubernetes\/\">Prometheus<\/a><\/p>\n<\/li>\n<li data-start=\"5735\" data-end=\"5746\">\n<p data-start=\"5737\" data-end=\"5746\">Grafana<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"5748\" data-end=\"5786\">3. Communicate Limits to Clients<\/h3>\n<p data-start=\"5787\" data-end=\"5808\">Send headers such as:<\/p>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\">\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs\"><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre!\"><span><span class=\"hljs-variable\">X<\/span><span class=\"hljs-operator\">-<\/span><span class=\"hljs-variable\">Rate<\/span><span class=\"hljs-operator\">-<\/span><span class=\"hljs-built_in\">Limit<\/span><span class=\"hljs-operator\">-<\/span><span class=\"hljs-variable\">Remaining<\/span><br \/>\n<span class=\"hljs-variable\">X<\/span><span class=\"hljs-operator\">-<\/span><span class=\"hljs-variable\">Rate<\/span><span class=\"hljs-operator\">-<\/span><span class=\"hljs-built_in\">Limit<\/span><span class=\"hljs-operator\">-<\/span><span class=\"hljs-variable\">Retry<\/span><span class=\"hljs-operator\">-<\/span><span class=\"hljs-built_in\">After<\/span><br \/>\n<\/span><\/code><\/div>\n<\/div>\n<h3 data-start=\"5867\" data-end=\"5906\">4. Implement Graceful Degradation<\/h3>\n<p data-start=\"5907\" data-end=\"5914\">Return:<\/p>\n<ul data-start=\"5915\" data-end=\"5964\">\n<li data-start=\"5915\" data-end=\"5940\">\n<p data-start=\"5917\" data-end=\"5940\">429 Too Many Requests<\/p>\n<\/li>\n<li data-start=\"5941\" data-end=\"5964\">\n<p data-start=\"5943\" data-end=\"5964\">Retry-After seconds<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"5966\" data-end=\"6019\">5. Combine Rate Limiting with Security Controls<\/h3>\n<p data-start=\"6020\" data-end=\"6035\">Use along with:<\/p>\n<ul data-start=\"6036\" data-end=\"6073\">\n<li data-start=\"6036\" data-end=\"6048\">\n<p data-start=\"6038\" data-end=\"6048\">API keys<\/p>\n<\/li>\n<li data-start=\"6049\" data-end=\"6059\">\n<p data-start=\"6051\" data-end=\"6059\"><a href=\"https:\/\/harshad-sonawane.com\/blog\/two-factor-authentication-java-applications\/\">OAuth2<\/a><\/p>\n<\/li>\n<li data-start=\"6060\" data-end=\"6073\">\n<p data-start=\"6062\" data-end=\"6073\">WAF rules<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"6075\" data-end=\"6078\" \/>\n<h1 data-start=\"6080\" data-end=\"6092\">Conclusion<\/h1>\n<p data-start=\"6094\" data-end=\"6319\">Rate limiting and throttling are essential components of a robust API strategy. With Bucket4j, Spring Boot offers an elegant and high-performance way to manage traffic, protect resources, and ensure fair usage across clients.<\/p>\n<p data-start=\"6321\" data-end=\"6530\">Whether your application runs on a single node or across a distributed Kubernetes cluster, Bucket4j provides the flexibility and precision needed to maintain system stability and protect your APIs from misuse.<\/p>\n<hr data-start=\"6532\" data-end=\"6535\" \/>\n<h1 data-start=\"6537\" data-end=\"6560\">References (Official)<\/h1>\n<ul data-start=\"6562\" data-end=\"6751\">\n<li data-start=\"6562\" data-end=\"6587\">\n<p data-start=\"6564\" data-end=\"6587\"><a data-start=\"6564\" data-end=\"6585\" rel=\"noopener\" target=\"_new\" class=\"decorated-link\" href=\"https:\/\/bucket4j.com\/\">https:\/\/bucket4j.com\/<span aria-hidden=\"true\" class=\"ms-0.5 inline-block align-middle leading-none\"><svg width=\"20\" height=\"20\" viewbox=\"0 0 20 20\" fill=\"currentColor\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" data-rtl-flip=\"\" class=\"block h-[0.75em] w-[0.75em] stroke-current stroke-[0.75]\"><path d=\"M14.3349 13.3301V6.60645L5.47065 15.4707C5.21095 15.7304 4.78895 15.7304 4.52925 15.4707C4.26955 15.211 4.26955 14.789 4.52925 14.5293L13.3935 5.66504H6.66011C6.29284 5.66504 5.99507 5.36727 5.99507 5C5.99507 4.63273 6.29284 4.33496 6.66011 4.33496H14.9999L15.1337 4.34863C15.4369 4.41057 15.665 4.67857 15.665 5V13.3301C15.6649 13.6973 15.3672 13.9951 14.9999 13.9951C14.6327 13.9951 14.335 13.6973 14.3349 13.3301Z\"><\/path><\/svg><\/span><\/a><\/p>\n<\/li>\n<li data-start=\"6588\" data-end=\"6661\">\n<p data-start=\"6590\" data-end=\"6661\"><a data-start=\"6590\" data-end=\"6659\" rel=\"noopener\" target=\"_new\" class=\"decorated-link\" href=\"https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/htmlsingle\/\">https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/htmlsingle\/<span aria-hidden=\"true\" class=\"ms-0.5 inline-block align-middle leading-none\"><svg width=\"20\" height=\"20\" viewbox=\"0 0 20 20\" fill=\"currentColor\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" data-rtl-flip=\"\" class=\"block h-[0.75em] w-[0.75em] stroke-current stroke-[0.75]\"><path d=\"M14.3349 13.3301V6.60645L5.47065 15.4707C5.21095 15.7304 4.78895 15.7304 4.52925 15.4707C4.26955 15.211 4.26955 14.789 4.52925 14.5293L13.3935 5.66504H6.66011C6.29284 5.66504 5.99507 5.36727 5.99507 5C5.99507 4.63273 6.29284 4.33496 6.66011 4.33496H14.9999L15.1337 4.34863C15.4369 4.41057 15.665 4.67857 15.665 5V13.3301C15.6649 13.6973 15.3672 13.9951 14.9999 13.9951C14.6327 13.9951 14.335 13.6973 14.3349 13.3301Z\"><\/path><\/svg><\/span><\/a><\/p>\n<\/li>\n<li data-start=\"6662\" data-end=\"6686\">\n<p data-start=\"6664\" data-end=\"6686\"><a data-start=\"6664\" data-end=\"6684\" rel=\"noopener\" target=\"_new\" class=\"decorated-link\" href=\"https:\/\/oauth.net\/2\/\">https:\/\/oauth.net\/2\/<span aria-hidden=\"true\" class=\"ms-0.5 inline-block align-middle leading-none\"><svg width=\"20\" height=\"20\" viewbox=\"0 0 20 20\" fill=\"currentColor\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" data-rtl-flip=\"\" class=\"block h-[0.75em] w-[0.75em] stroke-current stroke-[0.75]\"><path d=\"M14.3349 13.3301V6.60645L5.47065 15.4707C5.21095 15.7304 4.78895 15.7304 4.52925 15.4707C4.26955 15.211 4.26955 14.789 4.52925 14.5293L13.3935 5.66504H6.66011C6.29284 5.66504 5.99507 5.36727 5.99507 5C5.99507 4.63273 6.29284 4.33496 6.66011 4.33496H14.9999L15.1337 4.34863C15.4369 4.41057 15.665 4.67857 15.665 5V13.3301C15.6649 13.6973 15.3672 13.9951 14.9999 13.9951C14.6327 13.9951 14.335 13.6973 14.3349 13.3301Z\"><\/path><\/svg><\/span><\/a><\/p>\n<\/li>\n<li data-start=\"6687\" data-end=\"6751\">\n<p data-start=\"6689\" data-end=\"6751\"><a data-start=\"6689\" data-end=\"6749\" rel=\"noopener\" target=\"_new\" class=\"decorated-link cursor-pointer\">https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Status\/429<\/a><\/p>\n<\/li>\n<\/ul>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"o-typing-delay-100ms ticss-27f7e3e9\"><o-anim-typing>&lt;> <strong>&#8220;Happy developing, one line at a time!&#8221;<\/strong> &lt;\/><\/o-anim-typing><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As modern systems continue to embrace microservices, public APIs, and high-volume traffic, controlling how consumers access APIs becomes critical. Without proper rate limiting, even a single misbehaving client can overwhelm your application\u2014leading to degraded performance, increased latency, and potential downtime. Rate limiting and throttling safeguard your APIs by controlling the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":397,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_themeisle_gutenberg_block_has_review":false,"footnotes":"","jetpack_publicize_message":"Just published a detailed guide on API Rate Limiting & Throttling in Spring Boot using Bucket4j.\nIt covers token bucket mechanics, distributed rate limiting with Redis, Spring Boot filter integration, and real-world best practices for protecting APIs at scale.\n\nIf you're building REST or microservice architectures, this is a must-read.","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[113],"tags":[16,273,2,9,274,3,275],"class_list":["post-338","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java-spring-boot-aws-microservices","tag-api-security","tag-bucket4j","tag-java","tag-microservices","tag-rate-limiting","tag-spring-boot","tag-throttling"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>API Rate Limiting &amp; Throttling in Spring Boot with Bucket4j - &lt;&gt;HARSHAD&#039;s Dev Diary&lt;\/&gt;<\/title>\n<meta name=\"description\" content=\"A complete guide on implementing API rate limiting and throttling in Spring Boot using Bucket4j. Includes rate limiting and best practices\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"API Rate Limiting &amp; Throttling in Spring Boot with Bucket4j - &lt;&gt;HARSHAD&#039;s Dev Diary&lt;\/&gt;\" \/>\n<meta property=\"og:description\" content=\"A complete guide on implementing API rate limiting and throttling in Spring Boot using Bucket4j. Includes rate limiting and best practices\" \/>\n<meta property=\"og:url\" content=\"https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/\" \/>\n<meta property=\"og:site_name\" content=\"&lt;&gt;HARSHAD&#039;s Dev Diary&lt;\/&gt;\" \/>\n<meta property=\"article:published_time\" content=\"2025-12-13T05:55:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-15T12:53:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2025\/12\/ChatGPT-Image-Dec-15-2025-06_22_14-PM.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1536\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"HS\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"HS\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\\\/\"},\"author\":{\"name\":\"HS\",\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/#\\\/schema\\\/person\\\/d82781218ba30c34fa81b49e8393681e\"},\"headline\":\"API Rate Limiting &amp; Throttling in Spring Boot with Bucket4j\",\"datePublished\":\"2025-12-13T05:55:00+00:00\",\"dateModified\":\"2025-12-15T12:53:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\\\/\"},\"wordCount\":531,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/#\\\/schema\\\/person\\\/d82781218ba30c34fa81b49e8393681e\"},\"image\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/ChatGPT-Image-Dec-15-2025-06_22_14-PM.png\",\"keywords\":[\"API Security\",\"Bucket4j\",\"Java\",\"Microservices\",\"Rate Limiting\",\"Spring Boot\",\"Throttling\"],\"articleSection\":[\"Java, Spring Boot, AWS, Microservices\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\\\/\",\"url\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\\\/\",\"name\":\"API Rate Limiting &amp; Throttling in Spring Boot with Bucket4j - &lt;&gt;HARSHAD&#039;s Dev Diary&lt;\\\/&gt;\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/ChatGPT-Image-Dec-15-2025-06_22_14-PM.png\",\"datePublished\":\"2025-12-13T05:55:00+00:00\",\"dateModified\":\"2025-12-15T12:53:12+00:00\",\"description\":\"A complete guide on implementing API rate limiting and throttling in Spring Boot using Bucket4j. Includes rate limiting and best practices\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\\\/#primaryimage\",\"url\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/ChatGPT-Image-Dec-15-2025-06_22_14-PM.png\",\"contentUrl\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/ChatGPT-Image-Dec-15-2025-06_22_14-PM.png\",\"width\":1536,\"height\":1024,\"caption\":\"API Rate Limiting & Throttling in Spring Boot with Bucket4j\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"API Rate Limiting &amp; Throttling in Spring Boot with Bucket4j\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/\",\"name\":\"Harshad's Dev Diary\",\"description\":\"HARSHAD&#039;s Dev Diary\",\"publisher\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/#\\\/schema\\\/person\\\/d82781218ba30c34fa81b49e8393681e\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/#\\\/schema\\\/person\\\/d82781218ba30c34fa81b49e8393681e\",\"name\":\"HS\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/about.jpg\",\"url\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/about.jpg\",\"contentUrl\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/about.jpg\",\"width\":400,\"height\":400,\"caption\":\"HS\"},\"logo\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/about.jpg\"},\"sameAs\":[\"https:\\\/\\\/harshad-sonawane.com\\\/blog\"],\"url\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"API Rate Limiting &amp; Throttling in Spring Boot with Bucket4j - &lt;&gt;HARSHAD&#039;s Dev Diary&lt;\/&gt;","description":"A complete guide on implementing API rate limiting and throttling in Spring Boot using Bucket4j. Includes rate limiting and best practices","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/","og_locale":"en_US","og_type":"article","og_title":"API Rate Limiting &amp; Throttling in Spring Boot with Bucket4j - &lt;&gt;HARSHAD&#039;s Dev Diary&lt;\/&gt;","og_description":"A complete guide on implementing API rate limiting and throttling in Spring Boot using Bucket4j. Includes rate limiting and best practices","og_url":"https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/","og_site_name":"&lt;&gt;HARSHAD&#039;s Dev Diary&lt;\/&gt;","article_published_time":"2025-12-13T05:55:00+00:00","article_modified_time":"2025-12-15T12:53:12+00:00","og_image":[{"width":1536,"height":1024,"url":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2025\/12\/ChatGPT-Image-Dec-15-2025-06_22_14-PM.png","type":"image\/png"}],"author":"HS","twitter_card":"summary_large_image","twitter_misc":{"Written by":"HS","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/#article","isPartOf":{"@id":"https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/"},"author":{"name":"HS","@id":"https:\/\/harshad-sonawane.com\/blog\/#\/schema\/person\/d82781218ba30c34fa81b49e8393681e"},"headline":"API Rate Limiting &amp; Throttling in Spring Boot with Bucket4j","datePublished":"2025-12-13T05:55:00+00:00","dateModified":"2025-12-15T12:53:12+00:00","mainEntityOfPage":{"@id":"https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/"},"wordCount":531,"commentCount":0,"publisher":{"@id":"https:\/\/harshad-sonawane.com\/blog\/#\/schema\/person\/d82781218ba30c34fa81b49e8393681e"},"image":{"@id":"https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/#primaryimage"},"thumbnailUrl":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2025\/12\/ChatGPT-Image-Dec-15-2025-06_22_14-PM.png","keywords":["API Security","Bucket4j","Java","Microservices","Rate Limiting","Spring Boot","Throttling"],"articleSection":["Java, Spring Boot, AWS, Microservices"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/","url":"https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/","name":"API Rate Limiting &amp; Throttling in Spring Boot with Bucket4j - &lt;&gt;HARSHAD&#039;s Dev Diary&lt;\/&gt;","isPartOf":{"@id":"https:\/\/harshad-sonawane.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/#primaryimage"},"image":{"@id":"https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/#primaryimage"},"thumbnailUrl":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2025\/12\/ChatGPT-Image-Dec-15-2025-06_22_14-PM.png","datePublished":"2025-12-13T05:55:00+00:00","dateModified":"2025-12-15T12:53:12+00:00","description":"A complete guide on implementing API rate limiting and throttling in Spring Boot using Bucket4j. Includes rate limiting and best practices","breadcrumb":{"@id":"https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/#primaryimage","url":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2025\/12\/ChatGPT-Image-Dec-15-2025-06_22_14-PM.png","contentUrl":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2025\/12\/ChatGPT-Image-Dec-15-2025-06_22_14-PM.png","width":1536,"height":1024,"caption":"API Rate Limiting & Throttling in Spring Boot with Bucket4j"},{"@type":"BreadcrumbList","@id":"https:\/\/harshad-sonawane.com\/blog\/api-rate-limiting-throttling-in-spring-boot-with-bucket4j\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/harshad-sonawane.com\/blog\/"},{"@type":"ListItem","position":2,"name":"API Rate Limiting &amp; Throttling in Spring Boot with Bucket4j"}]},{"@type":"WebSite","@id":"https:\/\/harshad-sonawane.com\/blog\/#website","url":"https:\/\/harshad-sonawane.com\/blog\/","name":"Harshad's Dev Diary","description":"HARSHAD&#039;s Dev Diary","publisher":{"@id":"https:\/\/harshad-sonawane.com\/blog\/#\/schema\/person\/d82781218ba30c34fa81b49e8393681e"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/harshad-sonawane.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/harshad-sonawane.com\/blog\/#\/schema\/person\/d82781218ba30c34fa81b49e8393681e","name":"HS","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2025\/02\/about.jpg","url":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2025\/02\/about.jpg","contentUrl":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2025\/02\/about.jpg","width":400,"height":400,"caption":"HS"},"logo":{"@id":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2025\/02\/about.jpg"},"sameAs":["https:\/\/harshad-sonawane.com\/blog"],"url":"https:\/\/harshad-sonawane.com\/blog\/author\/admin\/"}]}},"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/posts\/338","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/comments?post=338"}],"version-history":[{"count":3,"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/posts\/338\/revisions"}],"predecessor-version":[{"id":343,"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/posts\/338\/revisions\/343"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/media\/397"}],"wp:attachment":[{"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/media?parent=338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/categories?post=338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/tags?post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}