Skip to contentমূল লেখায় যান

Topic 14 · Architectureটপিক 14 · Architecture

Rate Limiting

A cash machine lets you take out only a set amount of money each day. If you try again, it says "no" and tells you to come back tomorrow. This protects you and the bank, even if someone steals your card. Rate limiting does the same for an API: it lets each user send only a set number of requests in a time window, and then it says "wait".

5 min read5 মিনিটে পড়া যায় · 6 sections6টি সেকশন · 7 sources7টি সোর্স · updated Nov 2026আপডেট: Nov 2026

A token bucket and the 429টোকেন বাকেট আর 429

Send a burst, watch the tokens run out, get 429, and see the tokens come back.একঝাঁক request পাঠান, টোকেন ফুরানো দেখুন, 429 পান, আর টোকেন ফিরে আসা দেখুন।

2 min2 মিনিট7 steps7টি ধাপ
  • Tokensটোকেন3 / 3
  • Windowউইন্ডো5 min
clientক্লায়েন্টBucketবাকেট3 / 33 / 3tokens 3 / 3টোকেন 3 / 3APIAPIidleঅলসwaitingঅপেক্ষায়tokensটোকেন

You’ll learnআপনি শিখবেন

  • A token bucket holds a limited number of tokensটোকেন বাকেটে সীমিত সংখ্যক টোকেন থাকে✓
  • Each request takes one tokenপ্রতিটি request একটি টোকেন নেয়
  • No token means HTTP 429 and a Retry-Afterটোকেন না থাকলে HTTP 429 আর Retry-After
  • Tokens refill at a steady rate, up to the limitটোকেন স্থির হারে ফেরে, limit পর্যন্ত

In plain words

A rate limit has two numbers: a time window (the period) and the number of requests that the client can send in that period Source 5সোর্স 5. "3 requests in 5 minutes" is one rate limit.

Who the client is. The system must decide who "the client" is. It can count by user, IP address, API key, or phone number. The HTTP standard does not fix this choice. A server can identify the user by login details or a cookie, for example Source 1সোর্স 1.

Why limit. Rate limits protect the system from abuse. They protect a login page from brute-force attacks and cap how many API calls one client can make Source 5সোর্স 5. They also stop one user from taking all the resources Source 3সোর্স 3. And they protect money: each OTP SMS or each AI call costs the company.

The 429 response. When a client goes over the limit, the server usually answers with HTTP 429 Too Many Requests Source 3সোর্স 3. When a Cloudflare rate limiting rule blocks a request, the default response code is 429 Source 7সোর্স 7. The standard defines 429 as "too many requests in a given amount of time" Source 1সোর্স 1.

Retry-After. The response may include a Retry-After header that says how long to wait Source 1সোর্স 1. Its value is a number of seconds or a date. Retry-After: 120 means "wait 2 minutes" Source 2সোর্স 2. A cache must not store a 429 response Source 1সোর্স 1.

Retry-After and retryAfterSeconds

The owner's diagram shows retryAfterSeconds. The standard place for the wait time is the Retry-After header. Some APIs also put a field such as retryAfterSeconds in the JSON body. That field is an app choice, not a standard. It is still useful: Azure advises to name the limit and its scope, so the client does not guess Source 3সোর্স 3.

There are four common ways to count Source 3সোর্স 3:

AlgorithmHow it behaves
Fixed windowSimple. A client can send a burst at the end of one window and another at the start of the next.
Sliding windowSmooths the burst at the window edge, but keeps more data.
Token bucketAllows short bursts, then refills at a steady rate.
Leaky bucketLets requests out at a constant rate.

Shared counter. The counter must live in one shared place. If each server counts in its own memory, a client that reaches many servers gets more requests than the limit. A shared counter in Redis sees every request, but each check takes a little time Source 3সোর্স 3.

Redis example. The Redis docs show a classic rate limiter. It increases a counter for each request, and gives the counter an expiry so that Redis removes it after the window Source 4সোর্স 4.

A flow chart. An incoming request reaches the check 'Rate Limit OK?'. If yes, the API processes the request and updates a Redis counter with a TTL. If no, the API returns 429 Too Many Requests with a retryAfterSeconds value.Open the image in full sizeছবিটি পূর্ণ আকারে খুলুন

সহজ English

A rate limit has two numbers: a time window and the number of requests that a client can send in that window Source 5সোর্স 5. "3 requests in 5 minutes" is one rate limit.

The system must decide who "the client" is: a user, an IP address, an API key, or a phone number. The HTTP standard does not fix this choice Source 1সোর্স 1.

Rate limits protect a login page from brute-force attacks and cap the API calls of one client Source 5সোর্স 5. They stop one user from taking all the resources Source 3সোর্স 3. They save money too: each OTP SMS or AI call costs the company.

A client over the limit usually gets HTTP 429 Too Many Requests Source 3সোর্স 3. A Retry-After header can tell the client how long to wait Source 1সোর্স 1. Retry-After: 120 means "wait 2 minutes" Source 2সোর্স 2. A cache must not store a 429 response Source 1সোর্স 1.

There are four common ways to count Source 3সোর্স 3. Keep the counter in one shared place, such as Redis. If each server counts alone, a client that reaches many servers gets more than the limit Source 3সোর্স 3.

বাংলা ব্যাখ্যা

Rate limit-এ দুটি সংখ্যা থাকে: একটি time window (সময়কাল), আর সেই সময়ে client কতগুলো request পাঠাতে পারে Source 5সোর্স 5। "5 মিনিটে 3টি request" হলো একটি rate limit।

"Client" কে, তা system-কে ঠিক করতে হয়: user, IP address, API key, বা phone number। HTTP standard এই পছন্দ ঠিক করে দেয় না। যেমন, server login details বা cookie দিয়ে user-কে চিনতে পারে Source 1সোর্স 1।

Rate limit login page-কে brute-force attack থেকে রক্ষা করে, আর একজন client কতগুলো API call করতে পারে তার সীমা ঠিক করে Source 5সোর্স 5। এটি একজন user-কে সব resource দখল করা থেকেও আটকায় Source 3সোর্স 3। এটি টাকাও বাঁচায়, কারণ প্রতিটি OTP SMS বা AI call-এ company-র খরচ হয়।

Client limit পার হলে server সাধারণত HTTP 429 Too Many Requests দিয়ে উত্তর দেয় Source 3সোর্স 3। Cloudflare rate limiting rule কোনো request block করলে default response code হলো 429 Source 7সোর্স 7। Response-এ একটি Retry-After header থাকতে পারে, যা বলে কতক্ষণ অপেক্ষা করতে হবে Source 1সোর্স 1। এর value হয় সেকেন্ডের একটি সংখ্যা, অথবা একটি তারিখ। Retry-After: 120 মানে "2 মিনিট অপেক্ষা করুন" Source 2সোর্স 2। কোনো cache একটি 429 response store করতে পারবে না Source 1সোর্স 1।

গোনার চারটি সাধারণ উপায় হলো fixed window, sliding window, token bucket, আর leaky bucket Source 3সোর্স 3। Counter-টি একটি shared জায়গায় থাকতে হবে। প্রতিটি server নিজের memory-তে গুনলে, অনেক server-এ পৌঁছানো একজন client limit-এর চেয়ে বেশি request পাঠাতে পারে। Redis-এর shared counter প্রতিটি request দেখে, তবে প্রতিটি check-এ একটু সময় লাগে Source 3সোর্স 3। Redis docs-এর classic rate limiter প্রতিটি request-এ একটি counter বাড়ায় এবং counter-কে একটি expiry দেয়, যাতে window শেষে Redis সেটি মুছে দেয় Source 4সোর্স 4।

When you need it

  • You have login, OTP, or password reset endpoints.
  • You have payment start or payment callback endpoints.
  • Search, file upload, AI calls, or report generation costs a lot.
  • You expose a public API.
  • You pay for each SMS or email.

সহজ English

You need rate limiting in these cases:

  • You have login, OTP, or password reset endpoints.
  • You have endpoints that start a payment or receive a payment callback.
  • Search, file upload, AI calls, or report generation cost a lot.
  • You give the public access to an API.
  • You pay for each SMS or email.

বাংলা ব্যাখ্যা

নিচের যেকোনো একটি অবস্থা আপনার system-এর সাথে মিলে গেলে, আপনার rate limiting দরকার:

  • আপনার login, OTP, বা password reset endpoint আছে।
  • আপনার payment শুরু করার বা payment callback-এর endpoint আছে।
  • Search, file upload, AI call, বা report generation-এ অনেক খরচ হয়।
  • আপনি একটি public API দেন।
  • আপনি প্রতিটি SMS বা email-এর জন্য টাকা দেন।

A real-life example

An LMS has OTP login. The team sets two rules:

  • At most 3 OTP requests from the same phone number in 5 minutes.
  • At most 10 OTP requests from the same IP address in 10 minutes.

The fourth request from one phone gets this answer:

HTTP/1.1 429 Too Many Requests
Retry-After: 180
Content-Type: application/json

{ "error": "too_many_otp_requests", "retryAfterSeconds": 180 }

The two rules cut SMS cost, spam, and brute-force attempts.

সহজ English

An LMS has OTP login. The team sets two rules:

  • At most 3 OTP requests from the same phone number in 5 minutes.
  • At most 10 OTP requests from the same IP address in 10 minutes.

The fourth request from one phone gets HTTP/1.1 429 Too Many Requests. The response has the header Retry-After: 180. Its JSON body has the error too_many_otp_requests and "retryAfterSeconds": 180.

The two rules cut SMS cost, spam, and brute-force attempts.

বাংলা ব্যাখ্যা

ধরুন, একটি LMS-এ OTP login আছে। Team দুটি নিয়ম ঠিক করে:

  • একই phone number থেকে 5 মিনিটে সর্বোচ্চ 3টি OTP request।
  • একই IP address থেকে 10 মিনিটে সর্বোচ্চ 10টি OTP request।

একটি phone থেকে চতুর্থ request-টি HTTP/1.1 429 Too Many Requests উত্তর পায়। Response-এ Retry-After: 180 header থাকে। এর JSON body-তে error too_many_otp_requests এবং "retryAfterSeconds": 180 থাকে।

এই দুটি নিয়ম SMS-এর খরচ, spam, আর brute-force চেষ্টা কমায়।

Common mistakes

  • Only IP-based limits. Many devices behind NAT can share one IP address Source 7সোর্স 7. A school or an office network often works this way, so one strict IP limit can block a whole class. Combine IP limits with user or phone limits.
  • The same limit for every endpoint. OTP and verify endpoints are frequent brute-force targets Source 6সোর্স 6. Give them stricter limits. One option is to count only failed attempts, so real users with valid codes are not blocked Source 6সোর্স 6.
  • No wait time in the 429. Without Retry-After, the client cannot pick a retry plan and must guess Source 3সোর্স 3.
  • Counters in local memory. Each server counts on its own, so the servers undercount, and a client that reaches many servers can go over the limit Source 3সোর্স 3.
  • Forgetting admin and internal endpoints. An admin login or an internal report API can be abused too.

সহজ English

Look out for these common mistakes:

  • Only IP-based limits. Many devices behind NAT can share one IP address Source 7সোর্স 7. A school or an office network often works this way, so one strict IP limit can block a whole class. Use IP limits together with user or phone limits.
  • The same limit for every endpoint. Attackers often try to guess codes on OTP and verify endpoints Source 6সোর্স 6. Give these endpoints stricter limits. You can count only failed attempts, so real users with valid codes are not blocked Source 6সোর্স 6.
  • No wait time in the 429. Without Retry-After, the client must guess when to try again Source 3সোর্স 3.
  • Counters in local memory. Each server counts on its own. So the total count is too low, and a client that reaches many servers can go over the limit Source 3সোর্স 3.
  • Forgetting admin and internal endpoints. People can abuse an admin login or an internal report API too.

বাংলা ব্যাখ্যা

এই সাধারণ ভুলগুলোর দিকে খেয়াল রাখুন:

  • শুধু IP-ভিত্তিক limit। NAT-এর পেছনে অনেক device একটি IP address share করতে পারে Source 7সোর্স 7। School বা office network প্রায়ই এভাবে কাজ করে, তাই একটি কড়া IP limit পুরো একটি class-কে block করতে পারে। IP limit-এর সাথে user বা phone limit মিলিয়ে ব্যবহার করুন।
  • সব endpoint-এ একই limit। OTP আর verify endpoint প্রায়ই brute-force attack-এর লক্ষ্য হয় Source 6সোর্স 6। এগুলোতে আরও কড়া limit দিন। একটি উপায় হলো শুধু failed attempt গোনা, যাতে valid code থাকা আসল user-রা block না হন Source 6সোর্স 6।
  • 429-এ অপেক্ষার সময় নেই। Retry-After না থাকলে client retry-র পরিকল্পনা করতে পারে না, অনুমান করতে হয় Source 3সোর্স 3।
  • Local memory-তে counter। প্রতিটি server নিজে নিজে গোনে, তাই server-গুলো কম গোনে, আর অনেক server-এ পৌঁছানো একজন client limit পার হতে পারে Source 3সোর্স 3।
  • Admin আর internal endpoint ভুলে যাওয়া। একটি admin login বা internal report API-ও অপব্যবহার হতে পারে।

What a tester can check

Tutorial advice

  • The edge of the limit. Send exactly the limit, then one more. Check that only the extra request gets 429.
  • The wait time. Check the Retry-After header (and any body field). Wait that long, then check that the next request passes.
  • Many servers. Send requests through the load balancer so that they reach different servers. Check that the limit still holds in total.
  • Different keys. Use one phone from many IPs, and many phones from one IP. Check that each rule fires on its own.
  • Window edges. For a fixed window, send a burst just before and just after the window resets.
  • Sensitive endpoints. Check that OTP, password reset, and payment endpoints have stricter limits than read-only pages.

সহজ English

These test ideas are the tutorial's own advice.

  • The edge of the limit. Send exactly the limit, then one more request. Make sure that only the extra request gets 429.
  • The wait time. Look at the Retry-After header and any body field. Wait that long. Then make sure that the next request passes.
  • Many servers. Send requests through the load balancer, so that they reach different servers. Make sure that the total limit still holds.
  • Different keys. Use one phone from many IPs, and many phones from one IP. Make sure that each rule works on its own.
  • Window edges. For a fixed window, send a burst just before and just after the window resets.
  • Sensitive endpoints. Make sure that OTP, password reset, and payment endpoints have stricter limits than read-only pages.

বাংলা ব্যাখ্যা

নিচের test ধারণাগুলো এই tutorial-এর নিজস্ব পরামর্শ।

  • Limit-এর সীমানা। ঠিক limit পরিমাণ request পাঠান, তারপর আরও একটি। দেখুন, শুধু বাড়তি request-টি 429 পায় কি না।
  • অপেক্ষার সময়। Retry-After header (আর body-র কোনো field থাকলে সেটিও) দেখুন। ততক্ষণ অপেক্ষা করুন, তারপর দেখুন পরের request pass করে কি না।
  • অনেক server। Load balancer-এর মাধ্যমে request পাঠান, যাতে সেগুলো আলাদা server-এ পৌঁছায়। দেখুন, মোট হিসেবে limit এখনও কাজ করে কি না।
  • আলাদা key। অনেক IP থেকে একটি phone, আর একটি IP থেকে অনেক phone ব্যবহার করুন। দেখুন, প্রতিটি নিয়ম আলাদাভাবে কাজ করে কি না।
  • Window-এর কিনারা। Fixed window-এর ক্ষেত্রে, window reset হওয়ার ঠিক আগে আর ঠিক পরে একঝাঁক request পাঠান।
  • সংবেদনশীল endpoint। দেখুন, OTP, password reset, আর payment endpoint-এ read-only page-এর চেয়ে কড়া limit আছে কি না।

Key words

WordMeaning
Rate limitA cap on requests per client in a time window
Time windowThe period in which requests are counted, such as 5 minutes
429 Too Many RequestsThe HTTP status code for "you sent too many requests"
Retry-AfterThe HTTP header that tells the client how long to wait
Brute forceTrying many guesses, such as every OTP code, until one works
NATNetwork address translation: many devices share one public IP address
Token bucketAn algorithm that allows short bursts and then a steady rate

Reels on this topicএই টপিকের রিলস

Short videos from other creators, picked for this topic. They are not part of this page's fact-checked text. Nothing loads from YouTube until you press Play.অন্য ক্রিয়েটরদের বানানো ছোট ভিডিও, এই টপিকের জন্য বাছাই করা। এগুলো এই পেজের ফ্যাক্ট-চেক করা লেখার অংশ নয়। চালান বাটন চাপার আগে YouTube থেকে কিছুই লোড হয় না।

  1. [1]
    RFC 6585: Additional HTTP Status Codes

    IETF · accessed 2026-10-20দেখা হয়েছে: 2026-10-20

  2. [2]
    RFC 9110: HTTP Semantics (Retry-After)

    IETF · accessed 2026-10-20দেখা হয়েছে: 2026-10-20

  3. [3]
    Throttling pattern

    Microsoft Azure Architecture Center · accessed 2026-10-20দেখা হয়েছে: 2026-10-20

  4. [4]
    INCR (Pattern: rate limiter)

    Redis docs · accessed 2026-10-20দেখা হয়েছে: 2026-10-20

  5. [5]
    Rate limiting rules

    Cloudflare docs · accessed 2026-10-20দেখা হয়েছে: 2026-10-20

  6. [6]
    Rate limiting best practices

    Cloudflare docs · accessed 2026-10-20দেখা হয়েছে: 2026-10-20

  7. [7]
    Rate limiting parameters

    Cloudflare docs · accessed 2026-10-20দেখা হয়েছে: 2026-10-20