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