[{"data":1,"prerenderedAt":2236},["ShallowReactive",2],{"blog-en-ats-resume-scanner-ai":3,"blog-related-en-ats-resume-scanner-ai":759},{"id":4,"title":5,"author":6,"body":7,"date":743,"description":744,"extension":745,"featured":139,"image":746,"meta":747,"navigation":139,"path":748,"readingTime":236,"seo":749,"slug":750,"stem":751,"tags":752,"__hash__":758},"blog\u002Fblog\u002Fen\u002Fats-resume-scanner-ai.md","How I Built an ATS Resume Scanner with Nuxt 4, HuggingFace & Mistral-7B","Adam Abdel-Djamal",{"type":8,"value":9,"toc":736},"minimark",[10,19,38,41,46,49,71,73,77,85,423,425,429,432,439,667,670,672,676,687,699,706,708,712,732],[11,12,13,14,18],"p",{},"Over 75% of job applications are filtered out by automated ",[15,16,17],"strong",{},"Applicant Tracking Systems (ATS)"," before an actual recruiter reads them. Candidates often spend hours applying, only to be rejected by an algorithm due to missing keywords or unparsed formatting.",[11,20,21,22,25,26,29,30,33,34,37],{},"I built ",[15,23,24],{},"Talenta"," to demystify this hiring black box. In this article, I break down the architectural challenges of building a production AI resume scoring application using ",[15,27,28],{},"Nuxt 4",", ",[15,31,32],{},"HuggingFace Inference",", and ",[15,35,36],{},"Supabase",".",[39,40],"hr",{},[42,43,45],"h2",{"id":44},"_1-the-architecture-at-a-glance","1. The Architecture at a Glance",[11,47,48],{},"The core pipeline consists of three decoupled stages:",[50,51,52,59,65],"ol",{},[53,54,55,58],"li",{},[15,56,57],{},"Document Parsing",": Extracting raw structured text from arbitrary PDF and DOCX files without losing section hierarchies (Experience, Education, Skills).",[53,60,61,64],{},[15,62,63],{},"AI Semantic Matching",": Comparing the extracted resume tokens against the target job description using Mistral-7B-Instruct.",[53,66,67,70],{},[15,68,69],{},"Deterministic Scoring Engine",": Combining semantic AI matching with strict rule-based scoring (keyword coverage, section completeness, contact info presence).",[39,72],{},[42,74,76],{"id":75},"_2-fast-secure-document-parsing","2. Fast & Secure Document Parsing",[11,78,79,80,84],{},"Parsing PDFs in Node.js server environments often leads to memory leaks if not handled carefully. Rather than relying on heavy headless browsers, I leveraged a lightweight stream-based PDF text extractor inside a Nuxt server route (",[81,82,83],"code",{},"server\u002Fapi\u002Fparse-cv.post.ts",").",[86,87,92],"pre",{"className":88,"code":89,"language":90,"meta":91,"style":91},"language-typescript shiki shiki-themes github-light github-dark","\u002F\u002F server\u002Fapi\u002Fparse-cv.post.ts\nimport { readMultipartFormData } from 'h3'\nimport { extractTextFromPdf } from '~\u002Fserver\u002Futils\u002Fpdf'\n\nexport default defineEventHandler(async (event) => {\n  const form = await readMultipartFormData(event)\n  const file = form?.find(item => item.name === 'resume')\n\n  if (!file || file.type !== 'application\u002Fpdf') {\n    throw createError({ statusCode: 400, message: 'Valid PDF required' })\n  }\n\n  \u002F\u002F Enforce 5MB limit to protect memory\n  if (file.data.length > 5 * 1024 * 1024) {\n    throw createError({ statusCode: 413, message: 'File exceeds 5MB limit' })\n  }\n\n  const extractedText = await extractTextFromPdf(file.data)\n  return { text: extractedText, wordCount: extractedText.split(\u002F\\s+\u002F).length }\n})\n","typescript","",[81,93,94,103,121,134,141,176,198,234,239,268,292,298,303,309,338,357,362,367,385,417],{"__ignoreMap":91},[95,96,99],"span",{"class":97,"line":98},"line",1,[95,100,102],{"class":101},"sJ8bj","\u002F\u002F server\u002Fapi\u002Fparse-cv.post.ts\n",[95,104,106,110,114,117],{"class":97,"line":105},2,[95,107,109],{"class":108},"szBVR","import",[95,111,113],{"class":112},"sVt8B"," { readMultipartFormData } ",[95,115,116],{"class":108},"from",[95,118,120],{"class":119},"sZZnC"," 'h3'\n",[95,122,124,126,129,131],{"class":97,"line":123},3,[95,125,109],{"class":108},[95,127,128],{"class":112}," { extractTextFromPdf } ",[95,130,116],{"class":108},[95,132,133],{"class":119}," '~\u002Fserver\u002Futils\u002Fpdf'\n",[95,135,137],{"class":97,"line":136},4,[95,138,140],{"emptyLinePlaceholder":139},true,"\n",[95,142,144,147,150,154,157,160,163,167,170,173],{"class":97,"line":143},5,[95,145,146],{"class":108},"export",[95,148,149],{"class":108}," default",[95,151,153],{"class":152},"sScJk"," defineEventHandler",[95,155,156],{"class":112},"(",[95,158,159],{"class":108},"async",[95,161,162],{"class":112}," (",[95,164,166],{"class":165},"s4XuR","event",[95,168,169],{"class":112},") ",[95,171,172],{"class":108},"=>",[95,174,175],{"class":112}," {\n",[95,177,179,182,186,189,192,195],{"class":97,"line":178},6,[95,180,181],{"class":108},"  const",[95,183,185],{"class":184},"sj4cs"," form",[95,187,188],{"class":108}," =",[95,190,191],{"class":108}," await",[95,193,194],{"class":152}," readMultipartFormData",[95,196,197],{"class":112},"(event)\n",[95,199,201,203,206,208,211,214,216,219,222,225,228,231],{"class":97,"line":200},7,[95,202,181],{"class":108},[95,204,205],{"class":184}," file",[95,207,188],{"class":108},[95,209,210],{"class":112}," form?.",[95,212,213],{"class":152},"find",[95,215,156],{"class":112},[95,217,218],{"class":165},"item",[95,220,221],{"class":108}," =>",[95,223,224],{"class":112}," item.name ",[95,226,227],{"class":108},"===",[95,229,230],{"class":119}," 'resume'",[95,232,233],{"class":112},")\n",[95,235,237],{"class":97,"line":236},8,[95,238,140],{"emptyLinePlaceholder":139},[95,240,242,245,247,250,253,256,259,262,265],{"class":97,"line":241},9,[95,243,244],{"class":108},"  if",[95,246,162],{"class":112},[95,248,249],{"class":108},"!",[95,251,252],{"class":112},"file ",[95,254,255],{"class":108},"||",[95,257,258],{"class":112}," file.type ",[95,260,261],{"class":108},"!==",[95,263,264],{"class":119}," 'application\u002Fpdf'",[95,266,267],{"class":112},") {\n",[95,269,271,274,277,280,283,286,289],{"class":97,"line":270},10,[95,272,273],{"class":108},"    throw",[95,275,276],{"class":152}," createError",[95,278,279],{"class":112},"({ statusCode: ",[95,281,282],{"class":184},"400",[95,284,285],{"class":112},", message: ",[95,287,288],{"class":119},"'Valid PDF required'",[95,290,291],{"class":112}," })\n",[95,293,295],{"class":97,"line":294},11,[95,296,297],{"class":112},"  }\n",[95,299,301],{"class":97,"line":300},12,[95,302,140],{"emptyLinePlaceholder":139},[95,304,306],{"class":97,"line":305},13,[95,307,308],{"class":101},"  \u002F\u002F Enforce 5MB limit to protect memory\n",[95,310,312,314,317,320,323,326,329,332,334,336],{"class":97,"line":311},14,[95,313,244],{"class":108},[95,315,316],{"class":112}," (file.data.",[95,318,319],{"class":184},"length",[95,321,322],{"class":108}," >",[95,324,325],{"class":184}," 5",[95,327,328],{"class":108}," *",[95,330,331],{"class":184}," 1024",[95,333,328],{"class":108},[95,335,331],{"class":184},[95,337,267],{"class":112},[95,339,341,343,345,347,350,352,355],{"class":97,"line":340},15,[95,342,273],{"class":108},[95,344,276],{"class":152},[95,346,279],{"class":112},[95,348,349],{"class":184},"413",[95,351,285],{"class":112},[95,353,354],{"class":119},"'File exceeds 5MB limit'",[95,356,291],{"class":112},[95,358,360],{"class":97,"line":359},16,[95,361,297],{"class":112},[95,363,365],{"class":97,"line":364},17,[95,366,140],{"emptyLinePlaceholder":139},[95,368,370,372,375,377,379,382],{"class":97,"line":369},18,[95,371,181],{"class":108},[95,373,374],{"class":184}," extractedText",[95,376,188],{"class":108},[95,378,191],{"class":108},[95,380,381],{"class":152}," extractTextFromPdf",[95,383,384],{"class":112},"(file.data)\n",[95,386,388,391,394,397,399,402,405,408,410,412,414],{"class":97,"line":387},19,[95,389,390],{"class":108},"  return",[95,392,393],{"class":112}," { text: extractedText, wordCount: extractedText.",[95,395,396],{"class":152},"split",[95,398,156],{"class":112},[95,400,401],{"class":119},"\u002F",[95,403,404],{"class":184},"\\s",[95,406,407],{"class":108},"+",[95,409,401],{"class":119},[95,411,84],{"class":112},[95,413,319],{"class":184},[95,415,416],{"class":112}," }\n",[95,418,420],{"class":97,"line":419},20,[95,421,422],{"class":112},"})\n",[39,424],{},[42,426,428],{"id":427},"_3-forcing-strict-json-from-llms-with-zod","3. Forcing Strict JSON from LLMs with Zod",[11,430,431],{},"One of the biggest issues with LLMs in production is hallucinated format changes: missing brackets, conversational filler (\"Sure, here is your evaluation...\"), or malformed JSON.",[11,433,434,435,438],{},"To guarantee that the frontend receives type-safe data every time, the backend validates the raw model response against a strict ",[15,436,437],{},"Zod schema",":",[86,440,442],{"className":88,"code":441,"language":90,"meta":91,"style":91},"import { z } from 'zod'\n\nexport const AtsAnalysisSchema = z.object({\n  overallScore: z.number().min(0).max(100),\n  matchedKeywords: z.array(z.string()),\n  missingKeywords: z.array(z.string()),\n  sectionFeedback: z.object({\n    experience: z.string(),\n    skills: z.string(),\n    education: z.string(),\n  }),\n  actionableRewrites: z.array(z.object({\n    originalSentence: z.string(),\n    improvedSentence: z.string(),\n    reason: z.string(),\n  })),\n})\n\nexport type AtsAnalysis = z.infer\u003Ctypeof AtsAnalysisSchema>\n",[81,443,444,456,460,481,513,530,543,552,562,571,580,585,598,607,616,625,630,634,638],{"__ignoreMap":91},[95,445,446,448,451,453],{"class":97,"line":98},[95,447,109],{"class":108},[95,449,450],{"class":112}," { z } ",[95,452,116],{"class":108},[95,454,455],{"class":119}," 'zod'\n",[95,457,458],{"class":97,"line":105},[95,459,140],{"emptyLinePlaceholder":139},[95,461,462,464,467,470,472,475,478],{"class":97,"line":123},[95,463,146],{"class":108},[95,465,466],{"class":108}," const",[95,468,469],{"class":184}," AtsAnalysisSchema",[95,471,188],{"class":108},[95,473,474],{"class":112}," z.",[95,476,477],{"class":152},"object",[95,479,480],{"class":112},"({\n",[95,482,483,486,489,492,495,497,500,502,505,507,510],{"class":97,"line":136},[95,484,485],{"class":112},"  overallScore: z.",[95,487,488],{"class":152},"number",[95,490,491],{"class":112},"().",[95,493,494],{"class":152},"min",[95,496,156],{"class":112},[95,498,499],{"class":184},"0",[95,501,84],{"class":112},[95,503,504],{"class":152},"max",[95,506,156],{"class":112},[95,508,509],{"class":184},"100",[95,511,512],{"class":112},"),\n",[95,514,515,518,521,524,527],{"class":97,"line":143},[95,516,517],{"class":112},"  matchedKeywords: z.",[95,519,520],{"class":152},"array",[95,522,523],{"class":112},"(z.",[95,525,526],{"class":152},"string",[95,528,529],{"class":112},"()),\n",[95,531,532,535,537,539,541],{"class":97,"line":178},[95,533,534],{"class":112},"  missingKeywords: z.",[95,536,520],{"class":152},[95,538,523],{"class":112},[95,540,526],{"class":152},[95,542,529],{"class":112},[95,544,545,548,550],{"class":97,"line":200},[95,546,547],{"class":112},"  sectionFeedback: z.",[95,549,477],{"class":152},[95,551,480],{"class":112},[95,553,554,557,559],{"class":97,"line":236},[95,555,556],{"class":112},"    experience: z.",[95,558,526],{"class":152},[95,560,561],{"class":112},"(),\n",[95,563,564,567,569],{"class":97,"line":241},[95,565,566],{"class":112},"    skills: z.",[95,568,526],{"class":152},[95,570,561],{"class":112},[95,572,573,576,578],{"class":97,"line":270},[95,574,575],{"class":112},"    education: z.",[95,577,526],{"class":152},[95,579,561],{"class":112},[95,581,582],{"class":97,"line":294},[95,583,584],{"class":112},"  }),\n",[95,586,587,590,592,594,596],{"class":97,"line":300},[95,588,589],{"class":112},"  actionableRewrites: z.",[95,591,520],{"class":152},[95,593,523],{"class":112},[95,595,477],{"class":152},[95,597,480],{"class":112},[95,599,600,603,605],{"class":97,"line":305},[95,601,602],{"class":112},"    originalSentence: z.",[95,604,526],{"class":152},[95,606,561],{"class":112},[95,608,609,612,614],{"class":97,"line":311},[95,610,611],{"class":112},"    improvedSentence: z.",[95,613,526],{"class":152},[95,615,561],{"class":112},[95,617,618,621,623],{"class":97,"line":340},[95,619,620],{"class":112},"    reason: z.",[95,622,526],{"class":152},[95,624,561],{"class":112},[95,626,627],{"class":97,"line":359},[95,628,629],{"class":112},"  })),\n",[95,631,632],{"class":97,"line":364},[95,633,422],{"class":112},[95,635,636],{"class":97,"line":369},[95,637,140],{"emptyLinePlaceholder":139},[95,639,640,642,645,648,650,653,655,658,661,664],{"class":97,"line":387},[95,641,146],{"class":108},[95,643,644],{"class":108}," type",[95,646,647],{"class":152}," AtsAnalysis",[95,649,188],{"class":108},[95,651,652],{"class":152}," z",[95,654,37],{"class":112},[95,656,657],{"class":152},"infer",[95,659,660],{"class":112},"\u003C",[95,662,663],{"class":108},"typeof",[95,665,666],{"class":112}," AtsAnalysisSchema>\n",[11,668,669],{},"If the LLM output fails schema validation, an automated one-shot repair prompt fixes the JSON formatting before returning the payload to the client.",[39,671],{},[42,673,675],{"id":674},"_4-reactive-ui-and-quota-management","4. Reactive UI and Quota Management",[11,677,678,679,682,683,686],{},"On the frontend, ",[15,680,681],{},"Vue 3"," and ",[15,684,685],{},"Nuxt UI"," provide instantaneous feedback. When an analysis starts, the user sees real-time progress indicators:",[688,689,690,693,696],"ul",{},[53,691,692],{},"Keyword extraction radar chart",[53,694,695],{},"Ranked missing skills list",[53,697,698],{},"Live score gauge animated with SVG circle dashes",[11,700,701,702,705],{},"Users on the Free tier receive 3 complimentary analyses, authenticated via ",[15,703,704],{},"Supabase Auth"," with Row-Level Security (RLS) policies preventing quota tampering on the PostgreSQL level.",[39,707],{},[42,709,711],{"id":710},"key-takeaways","Key Takeaways",[50,713,714,720,726],{},[53,715,716,719],{},[15,717,718],{},"Never rely on raw LLM output for critical UI rendering",": Always place a schema validator like Zod between the model and your client.",[53,721,722,725],{},[15,723,724],{},"Combine AI with deterministic heuristics",": An LLM is great at semantic understanding, but deterministic regex checks are faster and cheaper for checking email presence or phone formatting.",[53,727,728,731],{},[15,729,730],{},"Optimistic UI with clear error boundaries",": Resume parsing can fail on scanned image PDFs. Provide clear feedback prompting the user to upload a text-based document.",[733,734,735],"style",{},"html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}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 .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 .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}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":91,"searchDepth":105,"depth":105,"links":737},[738,739,740,741,742],{"id":44,"depth":105,"text":45},{"id":75,"depth":105,"text":76},{"id":427,"depth":105,"text":428},{"id":674,"depth":105,"text":675},{"id":710,"depth":105,"text":711},"2026-07-15","A deep dive into engineering Talenta: extracting text from complex PDFs, streaming structured AI evaluations with HuggingFace, and preventing rate limit bottlenecks.","md",null,{},"\u002Fblog\u002Fen\u002Fats-resume-scanner-ai",{"title":5,"description":744},"ats-resume-scanner-ai","blog\u002Fen\u002Fats-resume-scanner-ai",[753,754,755,756,757],"ai","nuxt","vue","huggingface","fullstack","kkSX6pM11yqC_TlxrKuJm9oHeseRnwok5QpsvC2Fvl4",[760,1590],{"id":761,"title":762,"author":6,"body":763,"date":1577,"description":1578,"extension":745,"featured":1579,"image":746,"meta":1580,"navigation":139,"path":1581,"readingTime":178,"seo":1582,"slug":746,"stem":1583,"tags":1584,"__hash__":1589},"blog\u002Fblog\u002Fen\u002Fapi-common-mistakes.md","6 Common API Mistakes (And How to Fix Them)",{"type":8,"value":764,"toc":1568},[765,768,770,774,785,816,836,838,842,849,933,938,1057,1059,1063,1066,1126,1129,1131,1135,1138,1271,1278,1280,1284,1287,1460,1463,1465,1469,1472,1506,1513,1515,1519,1522,1565],[11,766,767],{},"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.",[39,769],{},[42,771,773],{"id":772},"_1-using-the-wrong-http-method","1. Using the Wrong HTTP Method",[11,775,776,777,780,781,784],{},"The most visible mistake. Using ",[81,778,779],{},"GET"," to delete a resource, or ",[81,782,783],{},"POST"," for everything because \"it works.\"",[86,786,790],{"className":787,"code":788,"language":789,"meta":91,"style":91},"language-http shiki shiki-themes github-light github-dark","# ❌ Deleting with GET — catastrophic if a browser prefetches this URL\nGET \u002Fapi\u002Fusers\u002F42\u002Fdelete\n\n# ✅ Correct\nDELETE \u002Fapi\u002Fusers\u002F42\n","http",[81,791,792,797,802,806,811],{"__ignoreMap":91},[95,793,794],{"class":97,"line":98},[95,795,796],{},"# ❌ Deleting with GET — catastrophic if a browser prefetches this URL\n",[95,798,799],{"class":97,"line":105},[95,800,801],{},"GET \u002Fapi\u002Fusers\u002F42\u002Fdelete\n",[95,803,804],{"class":97,"line":123},[95,805,140],{"emptyLinePlaceholder":139},[95,807,808],{"class":97,"line":136},[95,809,810],{},"# ✅ Correct\n",[95,812,813],{"class":97,"line":143},[95,814,815],{},"DELETE \u002Fapi\u002Fusers\u002F42\n",[11,817,818,819,821,822,824,825,401,828,831,832,835],{},"HTTP methods carry semantic meaning that clients, proxies, and caches rely on. ",[81,820,779],{}," must be idempotent and safe (no side effects). ",[81,823,783],{}," creates. ",[81,826,827],{},"PUT",[81,829,830],{},"PATCH"," update. ",[81,833,834],{},"DELETE"," removes. Violating these conventions breaks caching, browser history, and every HTTP client that follows the spec.",[39,837],{},[42,839,841],{"id":840},"_2-wrong-status-codes","2. Wrong Status Codes",[11,843,844,845,848],{},"Returning ",[81,846,847],{},"200 OK"," for an error response is the most common mistake in junior APIs.",[86,850,854],{"className":851,"code":852,"language":853,"meta":91,"style":91},"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",[81,855,856,861,866,880,890,895,899,904,908,919,929],{"__ignoreMap":91},[95,857,858],{"class":97,"line":98},[95,859,860],{"class":101},"\u002F\u002F ❌ Status 200, but it's an error\n",[95,862,863],{"class":97,"line":105},[95,864,865],{"class":112},"{\n",[95,867,868,871,874,877],{"class":97,"line":123},[95,869,870],{"class":184},"  \"success\"",[95,872,873],{"class":112},": ",[95,875,876],{"class":184},"false",[95,878,879],{"class":112},",\n",[95,881,882,885,887],{"class":97,"line":136},[95,883,884],{"class":184},"  \"error\"",[95,886,873],{"class":112},[95,888,889],{"class":119},"\"User not found\"\n",[95,891,892],{"class":97,"line":143},[95,893,894],{"class":112},"}\n",[95,896,897],{"class":97,"line":178},[95,898,140],{"emptyLinePlaceholder":139},[95,900,901],{"class":97,"line":200},[95,902,903],{"class":101},"\u002F\u002F ✅ Status 404 — the client knows immediately without parsing the body\n",[95,905,906],{"class":97,"line":236},[95,907,865],{"class":112},[95,909,910,912,914,917],{"class":97,"line":241},[95,911,884],{"class":184},[95,913,873],{"class":112},[95,915,916],{"class":119},"\"User not found\"",[95,918,879],{"class":112},[95,920,921,924,926],{"class":97,"line":270},[95,922,923],{"class":184},"  \"code\"",[95,925,873],{"class":112},[95,927,928],{"class":119},"\"USER_NOT_FOUND\"\n",[95,930,931],{"class":97,"line":294},[95,932,894],{"class":112},[11,934,935],{},[15,936,937],{},"The codes that matter most:",[939,940,941,954],"table",{},[942,943,944],"thead",{},[945,946,947,951],"tr",{},[948,949,950],"th",{},"Code",[948,952,953],{},"When to use it",[955,956,957,968,978,988,997,1007,1017,1027,1037,1047],"tbody",{},[945,958,959,965],{},[960,961,962],"td",{},[81,963,964],{},"200",[960,966,967],{},"Success with a body",[945,969,970,975],{},[960,971,972],{},[81,973,974],{},"201",[960,976,977],{},"Resource created (POST)",[945,979,980,985],{},[960,981,982],{},[81,983,984],{},"204",[960,986,987],{},"Success, no body (DELETE)",[945,989,990,994],{},[960,991,992],{},[81,993,282],{},[960,995,996],{},"Invalid input from the client",[945,998,999,1004],{},[960,1000,1001],{},[81,1002,1003],{},"401",[960,1005,1006],{},"Not authenticated",[945,1008,1009,1014],{},[960,1010,1011],{},[81,1012,1013],{},"403",[960,1015,1016],{},"Authenticated but not authorized",[945,1018,1019,1024],{},[960,1020,1021],{},[81,1022,1023],{},"404",[960,1025,1026],{},"Resource doesn't exist",[945,1028,1029,1034],{},[960,1030,1031],{},[81,1032,1033],{},"422",[960,1035,1036],{},"Input syntactically valid but semantically wrong",[945,1038,1039,1044],{},[960,1040,1041],{},[81,1042,1043],{},"429",[960,1045,1046],{},"Rate limit exceeded",[945,1048,1049,1054],{},[960,1050,1051],{},[81,1052,1053],{},"500",[960,1055,1056],{},"Server error (never the client's fault)",[39,1058],{},[42,1060,1062],{"id":1061},"_3-trusting-client-input","3. Trusting Client Input",[11,1064,1065],{},"Every value sent by a client is a potential attack vector.",[86,1067,1071],{"className":1068,"code":1069,"language":1070,"meta":91,"style":91},"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",[81,1072,1073,1078,1083,1088,1093,1097,1102,1107,1112,1117,1121],{"__ignoreMap":91},[95,1074,1075],{"class":97,"line":98},[95,1076,1077],{},"\u002F\u002F ❌ Never do this\n",[95,1079,1080],{"class":97,"line":105},[95,1081,1082],{},"$id = $_GET['id'];\n",[95,1084,1085],{"class":97,"line":123},[95,1086,1087],{},"$query = \"SELECT * FROM users WHERE id = $id\";\n",[95,1089,1090],{"class":97,"line":136},[95,1091,1092],{},"\u002F\u002F SQL injection: ?id=1 OR 1=1\n",[95,1094,1095],{"class":97,"line":143},[95,1096,140],{"emptyLinePlaceholder":139},[95,1098,1099],{"class":97,"line":178},[95,1100,1101],{},"\u002F\u002F ✅ Always validate and sanitize\n",[95,1103,1104],{"class":97,"line":200},[95,1105,1106],{},"$id = filter_var($_GET['id'], FILTER_VALIDATE_INT);\n",[95,1108,1109],{"class":97,"line":236},[95,1110,1111],{},"if (!$id) {\n",[95,1113,1114],{"class":97,"line":241},[95,1115,1116],{},"    return response()->json(['error' => 'Invalid ID'], 400);\n",[95,1118,1119],{"class":97,"line":270},[95,1120,894],{},[95,1122,1123],{"class":97,"line":294},[95,1124,1125],{},"$user = User::findOrFail($id); \u002F\u002F parameterized query\n",[11,1127,1128],{},"Validate: type, format, length, range. Sanitize before any database or filesystem operation. Never trust what arrives in the request body, headers, or query string.",[39,1130],{},[42,1132,1134],{"id":1133},"_4-leaking-sensitive-data","4. Leaking Sensitive Data",[11,1136,1137],{},"Returning the full database object without filtering is an invitation to a data breach.",[86,1139,1141],{"className":851,"code":1140,"language":853,"meta":91,"style":91},"\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",[81,1142,1143,1148,1152,1164,1176,1188,1200,1212,1222,1226,1230,1235,1239,1249,1259,1267],{"__ignoreMap":91},[95,1144,1145],{"class":97,"line":98},[95,1146,1147],{"class":101},"\u002F\u002F ❌ Returning the raw User model\n",[95,1149,1150],{"class":97,"line":105},[95,1151,865],{"class":112},[95,1153,1154,1157,1159,1162],{"class":97,"line":123},[95,1155,1156],{"class":184},"  \"id\"",[95,1158,873],{"class":112},[95,1160,1161],{"class":184},"42",[95,1163,879],{"class":112},[95,1165,1166,1169,1171,1174],{"class":97,"line":136},[95,1167,1168],{"class":184},"  \"email\"",[95,1170,873],{"class":112},[95,1172,1173],{"class":119},"\"user@example.com\"",[95,1175,879],{"class":112},[95,1177,1178,1181,1183,1186],{"class":97,"line":143},[95,1179,1180],{"class":184},"  \"password\"",[95,1182,873],{"class":112},[95,1184,1185],{"class":119},"\"$2b$12$...\"",[95,1187,879],{"class":112},[95,1189,1190,1193,1195,1198],{"class":97,"line":178},[95,1191,1192],{"class":184},"  \"stripe_customer_id\"",[95,1194,873],{"class":112},[95,1196,1197],{"class":119},"\"cus_xxx\"",[95,1199,879],{"class":112},[95,1201,1202,1205,1207,1210],{"class":97,"line":200},[95,1203,1204],{"class":184},"  \"internal_notes\"",[95,1206,873],{"class":112},[95,1208,1209],{"class":119},"\"flagged for review\"",[95,1211,879],{"class":112},[95,1213,1214,1217,1219],{"class":97,"line":236},[95,1215,1216],{"class":184},"  \"created_at\"",[95,1218,873],{"class":112},[95,1220,1221],{"class":119},"\"2024-01-01\"\n",[95,1223,1224],{"class":97,"line":241},[95,1225,894],{"class":112},[95,1227,1228],{"class":97,"line":270},[95,1229,140],{"emptyLinePlaceholder":139},[95,1231,1232],{"class":97,"line":294},[95,1233,1234],{"class":101},"\u002F\u002F ✅ Return only what the client actually needs\n",[95,1236,1237],{"class":97,"line":300},[95,1238,865],{"class":112},[95,1240,1241,1243,1245,1247],{"class":97,"line":305},[95,1242,1156],{"class":184},[95,1244,873],{"class":112},[95,1246,1161],{"class":184},[95,1248,879],{"class":112},[95,1250,1251,1253,1255,1257],{"class":97,"line":311},[95,1252,1168],{"class":184},[95,1254,873],{"class":112},[95,1256,1173],{"class":119},[95,1258,879],{"class":112},[95,1260,1261,1263,1265],{"class":97,"line":340},[95,1262,1216],{"class":184},[95,1264,873],{"class":112},[95,1266,1221],{"class":119},[95,1268,1269],{"class":97,"line":359},[95,1270,894],{"class":112},[11,1272,1273,1274,1277],{},"Use serializers, DTOs, or API Resources (Laravel) to explicitly define what gets exposed. The rule: ",[15,1275,1276],{},"opt-in, not opt-out."," Start with nothing, add what's needed.",[39,1279],{},[42,1281,1283],{"id":1282},"_5-inconsistent-error-format","5. Inconsistent Error Format",[11,1285,1286],{},"When every endpoint returns errors differently, every client has to handle every format.",[86,1288,1290],{"className":851,"code":1289,"language":853,"meta":91,"style":91},"\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",[81,1291,1292,1297,1312,1316,1321,1357,1361,1366,1371,1375,1380,1384,1391,1403,1415,1423,1447,1452,1456],{"__ignoreMap":91},[95,1293,1294],{"class":97,"line":98},[95,1295,1296],{"class":101},"\u002F\u002F ❌ Endpoint A\n",[95,1298,1299,1302,1305,1307,1310],{"class":97,"line":105},[95,1300,1301],{"class":112},"{ ",[95,1303,1304],{"class":184},"\"message\"",[95,1306,873],{"class":112},[95,1308,1309],{"class":119},"\"Not found\"",[95,1311,416],{"class":112},[95,1313,1314],{"class":97,"line":123},[95,1315,140],{"emptyLinePlaceholder":139},[95,1317,1318],{"class":97,"line":136},[95,1319,1320],{"class":101},"\u002F\u002F ❌ Endpoint B\n",[95,1322,1323,1325,1328,1330,1333,1335,1338,1340,1343,1345,1348,1351,1354],{"class":97,"line":143},[95,1324,1301],{"class":112},[95,1326,1327],{"class":184},"\"error\"",[95,1329,873],{"class":112},[95,1331,1332],{"class":184},"true",[95,1334,29],{"class":112},[95,1336,1337],{"class":184},"\"msg\"",[95,1339,873],{"class":112},[95,1341,1342],{"class":119},"\"Validation failed\"",[95,1344,29],{"class":112},[95,1346,1347],{"class":184},"\"fields\"",[95,1349,1350],{"class":112},": [",[95,1352,1353],{"class":119},"\"email\"",[95,1355,1356],{"class":112},"] }\n",[95,1358,1359],{"class":97,"line":178},[95,1360,140],{"emptyLinePlaceholder":139},[95,1362,1363],{"class":97,"line":200},[95,1364,1365],{"class":101},"\u002F\u002F ❌ Endpoint C\n",[95,1367,1368],{"class":97,"line":236},[95,1369,1370],{"class":119},"\"Internal server error\"\n",[95,1372,1373],{"class":97,"line":241},[95,1374,140],{"emptyLinePlaceholder":139},[95,1376,1377],{"class":97,"line":270},[95,1378,1379],{"class":101},"\u002F\u002F ✅ One format, everywhere\n",[95,1381,1382],{"class":97,"line":294},[95,1383,865],{"class":112},[95,1385,1386,1388],{"class":97,"line":300},[95,1387,884],{"class":184},[95,1389,1390],{"class":112},": {\n",[95,1392,1393,1396,1398,1401],{"class":97,"line":305},[95,1394,1395],{"class":184},"    \"code\"",[95,1397,873],{"class":112},[95,1399,1400],{"class":119},"\"VALIDATION_FAILED\"",[95,1402,879],{"class":112},[95,1404,1405,1408,1410,1413],{"class":97,"line":311},[95,1406,1407],{"class":184},"    \"message\"",[95,1409,873],{"class":112},[95,1411,1412],{"class":119},"\"The request contains invalid fields.\"",[95,1414,879],{"class":112},[95,1416,1417,1420],{"class":97,"line":340},[95,1418,1419],{"class":184},"    \"details\"",[95,1421,1422],{"class":112},": [\n",[95,1424,1425,1428,1431,1433,1435,1437,1440,1442,1445],{"class":97,"line":359},[95,1426,1427],{"class":112},"      { ",[95,1429,1430],{"class":184},"\"field\"",[95,1432,873],{"class":112},[95,1434,1353],{"class":119},[95,1436,29],{"class":112},[95,1438,1439],{"class":184},"\"issue\"",[95,1441,873],{"class":112},[95,1443,1444],{"class":119},"\"Invalid email format\"",[95,1446,416],{"class":112},[95,1448,1449],{"class":97,"line":364},[95,1450,1451],{"class":112},"    ]\n",[95,1453,1454],{"class":97,"line":369},[95,1455,297],{"class":112},[95,1457,1458],{"class":97,"line":387},[95,1459,894],{"class":112},[11,1461,1462],{},"Define your error envelope once. Apply it everywhere via a global exception handler. Clients — including your own frontend — will thank you.",[39,1464],{},[42,1466,1468],{"id":1467},"_6-no-api-versioning","6. No API Versioning",[11,1470,1471],{},"Changing an endpoint response breaks every client using it. Without versioning, you can never evolve the API.",[86,1473,1475],{"className":787,"code":1474,"language":789,"meta":91,"style":91},"# ❌ 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",[81,1476,1477,1482,1487,1491,1496,1501],{"__ignoreMap":91},[95,1478,1479],{"class":97,"line":98},[95,1480,1481],{},"# ❌ No version — any breaking change affects all clients immediately\n",[95,1483,1484],{"class":97,"line":105},[95,1485,1486],{},"GET \u002Fapi\u002Fusers\n",[95,1488,1489],{"class":97,"line":123},[95,1490,140],{"emptyLinePlaceholder":139},[95,1492,1493],{"class":97,"line":136},[95,1494,1495],{},"# ✅ Versioned — v1 stays stable, v2 introduces breaking changes safely\n",[95,1497,1498],{"class":97,"line":143},[95,1499,1500],{},"GET \u002Fapi\u002Fv1\u002Fusers\n",[95,1502,1503],{"class":97,"line":178},[95,1504,1505],{},"GET \u002Fapi\u002Fv2\u002Fusers\n",[11,1507,1508,1509,1512],{},"Version from day one, even if you only have v1. The cost of adding ",[81,1510,1511],{},"\u002Fv1\u002F"," later — after clients are in production — is much higher than the cost of including it from the start.",[39,1514],{},[42,1516,1518],{"id":1517},"the-takeaway","The Takeaway",[11,1520,1521],{},"None of these mistakes require advanced knowledge to fix. They require discipline: a checklist before every endpoint ships.",[688,1523,1526,1535,1541,1547,1553,1559],{"className":1524},[1525],"contains-task-list",[53,1527,1530,1534],{"className":1528},[1529],"task-list-item",[1531,1532],"input",{"disabled":139,"type":1533},"checkbox"," HTTP method matches the operation's semantics",[53,1536,1538,1540],{"className":1537},[1529],[1531,1539],{"disabled":139,"type":1533}," Status code is accurate",[53,1542,1544,1546],{"className":1543},[1529],[1531,1545],{"disabled":139,"type":1533}," All input is validated before use",[53,1548,1550,1552],{"className":1549},[1529],[1531,1551],{"disabled":139,"type":1533}," Response only exposes necessary fields",[53,1554,1556,1558],{"className":1555},[1529],[1531,1557],{"disabled":139,"type":1533}," Errors follow the global format",[53,1560,1562,1564],{"className":1561},[1529],[1531,1563],{"disabled":139,"type":1533}," URL includes an API version",[733,1566,1567],{},"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":91,"searchDepth":105,"depth":105,"links":1569},[1570,1571,1572,1573,1574,1575,1576],{"id":772,"depth":105,"text":773},{"id":840,"depth":105,"text":841},{"id":1061,"depth":105,"text":1062},{"id":1133,"depth":105,"text":1134},{"id":1282,"depth":105,"text":1283},{"id":1467,"depth":105,"text":1468},{"id":1517,"depth":105,"text":1518},"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.",false,{},"\u002Fblog\u002Fen\u002Fapi-common-mistakes",{"title":762,"description":1578},"blog\u002Fen\u002Fapi-common-mistakes",[1585,1586,1587,1588],"api","backend","rest","best-practices","z2NMprz3c9WpXKotgDMzEF9WM_LLLolyFqidBZu4I6s",{"id":1591,"title":1592,"author":6,"body":1593,"date":2224,"description":2225,"extension":745,"featured":1579,"image":746,"meta":2226,"navigation":139,"path":2227,"readingTime":178,"seo":2228,"slug":2229,"stem":2230,"tags":2231,"__hash__":2235},"blog\u002Fblog\u002Fen\u002Fapi-rate-limiting-redis.md","API Rate Limiting in Practice: Token Bucket vs. Sliding Window with Redis",{"type":8,"value":1594,"toc":2215},[1595,1598,1601,1611,1613,1617,1622,1629,1633,1636,1644,1648,1651,1653,1657,1664,2143,2145,2149,2152,2209,2212],[11,1596,1597],{},"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,1599,1600],{},"Rate limiting is the first line of defense against bot attacks, credential stuffing, and API resource abuse. But which algorithm should you implement?",[11,1602,1603,1604,682,1607,1610],{},"In this article, we compare the two industry-standard algorithms — ",[15,1605,1606],{},"Token Bucket",[15,1608,1609],{},"Sliding Window Log"," — and show how to implement a high-speed sliding window rate limiter in Redis.",[39,1612],{},[42,1614,1616],{"id":1615},"_1-comparing-the-algorithms","1. Comparing the Algorithms",[1618,1619,1621],"h3",{"id":1620},"a-fixed-window-counter-the-flawed-default","A. Fixed Window Counter (The Flawed Default)",[11,1623,1624,1625,1628],{},"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 ",[15,1626,1627],{},"200 requests in 2 seconds"," — double the intended burst limit!",[1618,1630,1632],{"id":1631},"b-token-bucket","B. Token Bucket",[11,1634,1635],{},"A bucket holds a fixed number of tokens (burst capacity). Tokens are continuously replenished at a constant rate. Each incoming request consumes one token.",[688,1637,1638],{},[53,1639,1640,1643],{},[15,1641,1642],{},"Great for",": APIs that want to allow legitimate temporary traffic spikes while capping sustained throughput.",[1618,1645,1647],{"id":1646},"c-sliding-window-counter-the-production-standard","C. Sliding Window Counter (The Production Standard)",[11,1649,1650],{},"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.",[39,1652],{},[42,1654,1656],{"id":1655},"_2-sliding-window-rate-limiter-with-redis-sorted-sets","2. Sliding Window Rate Limiter with Redis Sorted Sets",[11,1658,1659,1660,1663],{},"Redis Sorted Sets (",[81,1661,1662],{},"ZSET",") allow us to track requests by timestamp with microsecond accuracy:",[86,1665,1667],{"className":88,"code":1666,"language":90,"meta":91,"style":91},"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",[81,1668,1669,1681,1685,1711,1715,1759,1777,1803,1820,1824,1829,1846,1851,1867,1872,1882,1887,1921,1926,1936,1940,1960,1997,2002,2016,2024,2034,2044,2073,2079,2084,2089,2096,2106,2124,2133,2138],{"__ignoreMap":91},[95,1670,1671,1673,1676,1678],{"class":97,"line":98},[95,1672,109],{"class":108},[95,1674,1675],{"class":112}," Redis ",[95,1677,116],{"class":108},[95,1679,1680],{"class":119}," 'ioredis'\n",[95,1682,1683],{"class":97,"line":105},[95,1684,140],{"emptyLinePlaceholder":139},[95,1686,1687,1690,1693,1695,1698,1701,1704,1707,1709],{"class":97,"line":123},[95,1688,1689],{"class":108},"const",[95,1691,1692],{"class":184}," redis",[95,1694,188],{"class":108},[95,1696,1697],{"class":108}," new",[95,1699,1700],{"class":152}," Redis",[95,1702,1703],{"class":112},"(process.env.",[95,1705,1706],{"class":184},"REDIS_URL",[95,1708,249],{"class":108},[95,1710,233],{"class":112},[95,1712,1713],{"class":97,"line":136},[95,1714,140],{"emptyLinePlaceholder":139},[95,1716,1717,1719,1722,1725,1728,1730,1733,1735,1738,1740,1743,1745,1748,1750,1753,1755,1757],{"class":97,"line":143},[95,1718,146],{"class":108},[95,1720,1721],{"class":108}," async",[95,1723,1724],{"class":108}," function",[95,1726,1727],{"class":152}," checkRateLimit",[95,1729,156],{"class":112},[95,1731,1732],{"class":165},"identifier",[95,1734,438],{"class":108},[95,1736,1737],{"class":184}," string",[95,1739,29],{"class":112},[95,1741,1742],{"class":165},"limit",[95,1744,188],{"class":108},[95,1746,1747],{"class":184}," 60",[95,1749,29],{"class":112},[95,1751,1752],{"class":165},"windowInSeconds",[95,1754,188],{"class":108},[95,1756,1747],{"class":184},[95,1758,267],{"class":112},[95,1760,1761,1763,1766,1768,1771,1774],{"class":97,"line":178},[95,1762,181],{"class":108},[95,1764,1765],{"class":184}," now",[95,1767,188],{"class":108},[95,1769,1770],{"class":112}," Date.",[95,1772,1773],{"class":152},"now",[95,1775,1776],{"class":112},"()\n",[95,1778,1779,1781,1784,1786,1789,1792,1795,1798,1801],{"class":97,"line":200},[95,1780,181],{"class":108},[95,1782,1783],{"class":184}," windowStart",[95,1785,188],{"class":108},[95,1787,1788],{"class":112}," now ",[95,1790,1791],{"class":108},"-",[95,1793,1794],{"class":112}," (windowInSeconds ",[95,1796,1797],{"class":108},"*",[95,1799,1800],{"class":184}," 1000",[95,1802,233],{"class":112},[95,1804,1805,1807,1810,1812,1815,1817],{"class":97,"line":236},[95,1806,181],{"class":108},[95,1808,1809],{"class":184}," key",[95,1811,188],{"class":108},[95,1813,1814],{"class":119}," `ratelimit:${",[95,1816,1732],{"class":112},[95,1818,1819],{"class":119},"}`\n",[95,1821,1822],{"class":97,"line":241},[95,1823,140],{"emptyLinePlaceholder":139},[95,1825,1826],{"class":97,"line":270},[95,1827,1828],{"class":101},"  \u002F\u002F Atomic Redis Pipeline (Runs in a single round-trip)\n",[95,1830,1831,1833,1836,1838,1841,1844],{"class":97,"line":294},[95,1832,181],{"class":108},[95,1834,1835],{"class":184}," multi",[95,1837,188],{"class":108},[95,1839,1840],{"class":112}," redis.",[95,1842,1843],{"class":152},"multi",[95,1845,1776],{"class":112},[95,1847,1848],{"class":97,"line":300},[95,1849,1850],{"class":101},"  \u002F\u002F 1. Remove all request timestamps older than the active window\n",[95,1852,1853,1856,1859,1862,1864],{"class":97,"line":305},[95,1854,1855],{"class":112},"  multi.",[95,1857,1858],{"class":152},"zremrangebyscore",[95,1860,1861],{"class":112},"(key, ",[95,1863,499],{"class":184},[95,1865,1866],{"class":112},", windowStart)\n",[95,1868,1869],{"class":97,"line":311},[95,1870,1871],{"class":101},"  \u002F\u002F 2. Count requests currently in the active window\n",[95,1873,1874,1876,1879],{"class":97,"line":340},[95,1875,1855],{"class":112},[95,1877,1878],{"class":152},"zcard",[95,1880,1881],{"class":112},"(key)\n",[95,1883,1884],{"class":97,"line":359},[95,1885,1886],{"class":101},"  \u002F\u002F 3. Add the current timestamp as a new request\n",[95,1888,1889,1891,1894,1897,1900,1902,1905,1908,1910,1913,1916,1919],{"class":97,"line":364},[95,1890,1855],{"class":112},[95,1892,1893],{"class":152},"zadd",[95,1895,1896],{"class":112},"(key, now, ",[95,1898,1899],{"class":119},"`${",[95,1901,1773],{"class":112},[95,1903,1904],{"class":119},"}-${",[95,1906,1907],{"class":112},"Math",[95,1909,37],{"class":119},[95,1911,1912],{"class":152},"random",[95,1914,1915],{"class":119},"()",[95,1917,1918],{"class":119},"}`",[95,1920,233],{"class":112},[95,1922,1923],{"class":97,"line":369},[95,1924,1925],{"class":101},"  \u002F\u002F 4. Set key expiration to auto-clean idle users\n",[95,1927,1928,1930,1933],{"class":97,"line":387},[95,1929,1855],{"class":112},[95,1931,1932],{"class":152},"expire",[95,1934,1935],{"class":112},"(key, windowInSeconds)\n",[95,1937,1938],{"class":97,"line":419},[95,1939,140],{"emptyLinePlaceholder":139},[95,1941,1943,1945,1948,1950,1952,1955,1958],{"class":97,"line":1942},21,[95,1944,181],{"class":108},[95,1946,1947],{"class":184}," results",[95,1949,188],{"class":108},[95,1951,191],{"class":108},[95,1953,1954],{"class":112}," multi.",[95,1956,1957],{"class":152},"exec",[95,1959,1776],{"class":112},[95,1961,1963,1965,1968,1970,1973,1976,1979,1981,1984,1987,1990,1992,1994],{"class":97,"line":1962},22,[95,1964,181],{"class":108},[95,1966,1967],{"class":184}," currentCount",[95,1969,188],{"class":108},[95,1971,1972],{"class":112}," (results?.[",[95,1974,1975],{"class":184},"1",[95,1977,1978],{"class":112},"]?.[",[95,1980,1975],{"class":184},[95,1982,1983],{"class":112},"] ",[95,1985,1986],{"class":108},"as",[95,1988,1989],{"class":184}," number",[95,1991,169],{"class":112},[95,1993,255],{"class":108},[95,1995,1996],{"class":184}," 0\n",[95,1998,2000],{"class":97,"line":1999},23,[95,2001,140],{"emptyLinePlaceholder":139},[95,2003,2005,2007,2010,2013],{"class":97,"line":2004},24,[95,2006,244],{"class":108},[95,2008,2009],{"class":112}," (currentCount ",[95,2011,2012],{"class":108},">=",[95,2014,2015],{"class":112}," limit) {\n",[95,2017,2019,2022],{"class":97,"line":2018},25,[95,2020,2021],{"class":108},"    return",[95,2023,175],{"class":112},[95,2025,2027,2030,2032],{"class":97,"line":2026},26,[95,2028,2029],{"class":112},"      allowed: ",[95,2031,876],{"class":184},[95,2033,879],{"class":112},[95,2035,2037,2040,2042],{"class":97,"line":2036},27,[95,2038,2039],{"class":112},"      remaining: ",[95,2041,499],{"class":184},[95,2043,879],{"class":112},[95,2045,2047,2050,2053,2056,2058,2061,2063,2066,2068,2070],{"class":97,"line":2046},28,[95,2048,2049],{"class":112},"      retryAfter: Math.",[95,2051,2052],{"class":152},"ceil",[95,2054,2055],{"class":112},"(windowInSeconds ",[95,2057,1791],{"class":108},[95,2059,2060],{"class":112}," ((now ",[95,2062,1791],{"class":108},[95,2064,2065],{"class":112}," windowStart) ",[95,2067,401],{"class":108},[95,2069,1800],{"class":184},[95,2071,2072],{"class":112},"))\n",[95,2074,2076],{"class":97,"line":2075},29,[95,2077,2078],{"class":112},"    }\n",[95,2080,2082],{"class":97,"line":2081},30,[95,2083,297],{"class":112},[95,2085,2087],{"class":97,"line":2086},31,[95,2088,140],{"emptyLinePlaceholder":139},[95,2090,2092,2094],{"class":97,"line":2091},32,[95,2093,390],{"class":108},[95,2095,175],{"class":112},[95,2097,2099,2102,2104],{"class":97,"line":2098},33,[95,2100,2101],{"class":112},"    allowed: ",[95,2103,1332],{"class":184},[95,2105,879],{"class":112},[95,2107,2109,2112,2114,2117,2119,2122],{"class":97,"line":2108},34,[95,2110,2111],{"class":112},"    remaining: limit ",[95,2113,1791],{"class":108},[95,2115,2116],{"class":112}," currentCount ",[95,2118,1791],{"class":108},[95,2120,2121],{"class":184}," 1",[95,2123,879],{"class":112},[95,2125,2127,2130],{"class":97,"line":2126},35,[95,2128,2129],{"class":112},"    retryAfter: ",[95,2131,2132],{"class":184},"0\n",[95,2134,2136],{"class":97,"line":2135},36,[95,2137,297],{"class":112},[95,2139,2141],{"class":97,"line":2140},37,[95,2142,894],{"class":112},[39,2144],{},[42,2146,2148],{"id":2147},"_3-returning-standard-http-rate-limit-headers","3. Returning Standard HTTP Rate Limit Headers",[11,2150,2151],{},"Whenever your server answers a request, communicate rate limit states in the response headers (following IETF draft standards):",[86,2153,2155],{"className":787,"code":2154,"language":789,"meta":91,"style":91},"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",[81,2156,2157,2162,2167,2172,2177,2182,2187,2191,2195,2200,2205],{"__ignoreMap":91},[95,2158,2159],{"class":97,"line":98},[95,2160,2161],{},"HTTP\u002F1.1 429 Too Many Requests\n",[95,2163,2164],{"class":97,"line":105},[95,2165,2166],{},"Retry-After: 32\n",[95,2168,2169],{"class":97,"line":123},[95,2170,2171],{},"X-RateLimit-Limit: 60\n",[95,2173,2174],{"class":97,"line":136},[95,2175,2176],{},"X-RateLimit-Remaining: 0\n",[95,2178,2179],{"class":97,"line":143},[95,2180,2181],{},"X-RateLimit-Reset: 1773489240\n",[95,2183,2184],{"class":97,"line":178},[95,2185,2186],{},"Content-Type: application\u002Fjson\n",[95,2188,2189],{"class":97,"line":200},[95,2190,140],{"emptyLinePlaceholder":139},[95,2192,2193],{"class":97,"line":236},[95,2194,865],{},[95,2196,2197],{"class":97,"line":241},[95,2198,2199],{},"  \"error\": \"Too Many Requests\",\n",[95,2201,2202],{"class":97,"line":270},[95,2203,2204],{},"  \"message\": \"Rate limit exceeded. Please retry in 32 seconds.\"\n",[95,2206,2207],{"class":97,"line":294},[95,2208,894],{},[11,2210,2211],{},"This ensures honest third-party API clients and mobile SDKs can automatically back off and retry without overwhelming your infrastructure.",[733,2213,2214],{},"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":91,"searchDepth":105,"depth":105,"links":2216},[2217,2222,2223],{"id":1615,"depth":105,"text":1616,"children":2218},[2219,2220,2221],{"id":1620,"depth":123,"text":1621},{"id":1631,"depth":123,"text":1632},{"id":1646,"depth":123,"text":1647},{"id":1655,"depth":105,"text":1656},{"id":2147,"depth":105,"text":2148},"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":1592,"description":2225},"api-rate-limiting-redis","blog\u002Fen\u002Fapi-rate-limiting-redis",[1585,2232,2233,1586,2234],"security","redis","performance","KXTsuQOwj895dkbCDObhyO_wOncRKtB2ufJbjc-AUyc",1792236099936]