本文へスキップ
製品デスクトップツールTASTECAD図面の確認TASTEFILESファイル管理TASTEFTPファイル転送TASTESSHリモートワークスペースTASTEZIP圧縮と展開TASTEWINMファイル管理開発ツールTASTECODERust 統合開発環境TASTESTUDIO統合開発・テスト環境TASTEETLデータ統合(ETL)サーバーTASTEREMOTEリモートデスクトップサーバーTASTEGEO空間情報サーバーTASTEMAILメールワークスペース投資TASTESTOCK株式自動売買デスクトップアプリはじめるダウンロードドキュメント購入すべての製品
マーケットプレイス
ニュース
技術ニュース今日の開発ニュース開発ドキュメントプログラミング言語RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWebフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngularサーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Expressアプリ・デスクトップ フレームワークTauriFlutterReact NativeElectronアルゴリズムアルゴリズムの基礎主要アルゴリズム発展アルゴリズム実務のアルゴリズム
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケースコミュニティガイド
協業技術移転ウェブサイト構築デスクトップアプリ構築リリース・決済パイプライン販売パートナーお問い合わせ
サービスリモートデスクトップインストールパッケージのカスタマイズ
TASTEDEV
製品

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらくTASTEWINM2つの画面で整理する、キーボード中心のファイルマネージャー

開発ツール

TASTECODERust アプリの編集・ビルド・デバッグ・テストまでひとつのウィンドウでTASTESTUDIO編集からリモートテスト、承認した AI 修正までTASTEETL値を見ながら、データを運ぶ

サーバー

TASTEREMOTE自社サーバーで運用するリモートデスクトップTASTEGEOGeoServer 互換の空間情報サーバーを Rust で作り直しますTASTEMAILメールの主導権を、もう一度自分の手に

投資

TASTESTOCKいつ・何を。自分で決めたルールどおりに動く株式自動売買

はじめる

ダウンロード全製品の最新版ドキュメント各製品の使い方購入サブスクリプション・永久ライセンスすべての製品全製品を一覧で
すべての製品
マーケットプレイスニュース
技術

ニュース

今日の開発ニュース言語・フレームワーク・GitHub・AI の公式発表開発ドキュメント言語・フレームワーク・アルゴリズムのガイド

プログラミング言語

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

フレームワーク

Webフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngular
サーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
アプリ・デスクトップ フレームワークTauriFlutterReact NativeElectron

アルゴリズム

アルゴリズムの基礎計算量解析 · ソート · 探索 · 基本データ構造 · 木構造とヒープ主要アルゴリズムグラフ探索 · 最短経路と最小全域木 · 動的計画法 · 貪欲法 · 分割統治法 · バックトラッキング発展アルゴリズム文字列アルゴリズム · 数学と整数論 · ビット演算 · セグメント木 · Union-Find実務のアルゴリズムコーディング面接対策 · LRUキャッシュ · レート制限 · コンシステントハッシュ法
開発ドキュメントをすべて見る
コミュニティ
プロジェクトビルダーと作品を探す開発ログ決定と試行錯誤プロンプト再利用できる指示AIツールの問題Claude・Codex・Gemini の問題と回避策ショーケース完成した成果コミュニティガイドオープンにつくる方法
協業
技術移転Rust・egui でネイティブアプリを作るウェブサイト構築10言語、アカウント、ドキュメントとダウンロードデスクトップアプリ構築Rust・egui、WebView なしリリース・決済パイプライン署名・MSI・deb・rpm・AppImage・ハッシュ販売パートナー紹介して決済額の30%お問い合わせ構築・提携・投資のご相談
サービス
リモートデスクトップブラウザから自分のパソコンへインストールパッケージのカスタマイズ必要な機能だけ、設定は事前に
購入
JA
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
ログイン
ログイン
TASTEDEV

小さなツールから、より良い開発へ。

support@tastedev.netTASTEDEVを支援
製品製品ラインナップ購入ドキュメントダウンロードマーケットプレイスサポート
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケース
ポリシー会社概要プライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
昨日
累計閲覧
商号
GXSOFT
代表者
CHOI YOUNG GU
事業者登録番号
853-44-00368
所在地
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
メール
whitecalvin@tastedev.net
個人情報保護責任者
CHOI YOUNG GU

© 2026 TASTEDEV製品情報は検証済みの開発ソースに基づいています。リリース・改善中

レート制限 ドキュメント
レート制限
ConceptsHow It WorksImplementationComplexityPractice ProblemsReal-World Use
ディスカッション

レート制限 ガイド · 1/6

Concepts

この章は現在、英語でのみ提供しています。

A rate limiter caps how many requests are accepted within a period of time. You set a rule such as "100 requests per minute per user" or "5 login attempts per minute per IP", and requests beyond it are rejected or delayed. This chapter explains why we limit requests, which algorithms exist, and the vocabulary used throughout the rest of the guide.

Why limit requests

Server resources are finite. When one client floods a service in a short time, everyone else gets slower responses, and in the worst case the whole service goes down. A rate limiter protects against:

  • Overload: sudden traffic spikes or a buggy retry loop should not knock over your database and servers.
  • Unfairness: no single user should be able to monopolize shared capacity.
  • Abuse: password brute forcing, account enumeration and scraping become much slower.
  • Runaway cost: calls that cost money, such as paid third-party APIs or SMS, stay within budget.
  • Plan tiers: "60 requests per minute on Free, 1,000 on Pro" is a common way to differentiate products.

Vocabulary

TermMeaning
LimitMaximum number of requests allowed in one window
WindowThe time span over which requests are counted (1 second, 1 minute)
KeyThe unit that gets its own counter (user ID, API key, IP address)
BurstA group of requests arriving close together
RateThe long-run average speed allowed (for example 10 per second)
CapacityThe most tokens a token bucket can hold, which is the largest burst it admits

Five classic algorithms

  • Fixed window: cut time into slots such as one minute and keep one counter per slot. Simplest of all, but around a slot boundary a client can send up to twice the limit.
  • Sliding window log: store the timestamp of every request and count only those within the last minute. Exact, but memory grows with the limit.
  • Sliding window counter: blend the previous and current slot counters by how far into the current slot you are. Cheap and quite accurate.
  • Token bucket: tokens drip into a bucket at a fixed rate and each request takes one. It enforces an average rate while allowing bursts up to the capacity.
  • Leaky bucket: requests go into a queue that drains at a constant rate. Output is perfectly smooth, at the price of added waiting time.

A fixed window counter takes only a few lines. The following chapters fix its weaknesses one at a time.

import time
from collections import defaultdict

LIMIT, WINDOW = 5, 60          # 5 requests per minute
counters = defaultdict(int)    # (key, window number) -> count


def allow(key: str) -> bool:
    window_id = int(time.time() // WINDOW)
    counters[(key, window_id)] += 1
    return counters[(key, window_id)] <= LIMIT
この章について質問がありますか?
次の章How It Works

This sketch never deletes old counters. Real code cleans up past windows or uses a store with expiry, such as Redis.

Choosing the key

The same algorithm behaves very differently depending on what you count against.

  • User ID or API key: the fairest choice for authenticated traffic, and the natural place to attach per-plan limits.
  • IP address: used before login (sign-in, sign-up, password reset). Watch out for NAT, where an office or a mobile carrier puts many people behind one address, and for IPv6, where a user often controls a whole /64 block and can rotate addresses freely.
  • Endpoint: an expensive search API deserves a different limit than a cheap read.
  • Combinations: keys such as user:42:POST /search give fine-grained control.

Behind a reverse proxy, be careful with X-Forwarded-For. Clients can set it to anything, so only trust entries appended by proxies you operate.

def client_ip(remote_addr: str, forwarded_for: str | None,
              trusted_proxies: set[str]) -> str:
    # Only trust the header when the direct peer is our own proxy
    if forwarded_for and remote_addr in trusted_proxies:
        hops = [h.strip() for h in forwarded_for.split(",")]
        # Walk from the right; the first untrusted hop is the real client
        for hop in reversed(hops):
            if hop not in trusted_proxies:
                return hop
    return remote_addr

After rejecting: HTTP 429 and Retry-After

Over HTTP, a request that exceeds the limit normally gets 429 Too Many Requests, a status code defined in RFC 6585. Adding a Retry-After header, either a number of seconds or an HTTP date, tells well-behaved clients exactly how long to back off. Many APIs also report the remaining quota and reset time in headers, such as GitHub's x-ratelimit-remaining.

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

{"error": "rate_limited", "message": "Too many requests. Retry in 12 seconds."}

Summary

  • A rate limiter caps requests per key per period to prevent overload, monopolization, abuse and runaway cost.
  • The classic algorithms are fixed window, sliding window log, sliding window counter, token bucket and leaky bucket.
  • Picking the right key (user, IP, endpoint) matters as much as picking the algorithm.
  • When you reject, answer with 429 and Retry-After so clients know when to try again.

コメント 0件

人気のコメント順新しい順

ログイン · ログインするとコメントできます。