资源 · 77
API配额与速率限制
限制影响容量、重试及客户间分配。
已更新 · 13 min
本指南有助于实现的目标
- 明确预算
- 限制恢复过程
- 处理不确定操作
- 指定重试责任层
- 停止已无用工作
快速检查
- 记录配额范围、响应头、等待和重试预算;测试受控耗尽。
- 同时重试可能加剧过载。
分步指南
- 1
明确预算
记录配额针对账户、密钥还是资源,以及客户端允许的并发操作数。即使平均频率不高,无限队列也可能压垮服务。
记录配额单位、并发数和队列大小。
- 2
限制恢复过程
收到429时,若有Retry-After则解析并等待再请求。把逐步增加的等待和客户端间的时间分散,与最大尝试次数和总期限结合。
保留尝试顺序及时间。
- 3
处理不确定操作
写入响应丢失时,先检查状态再重试。在模拟测试中组合限流、迟到响应和取消,确认队列结束且效果不重复。
保留最终效果和待处理操作。
- 4
指定重试责任层
列出应用、SDK、代理及依赖的自动尝试。选择负责层,按契约关闭或协调额外重试。将首次尝试计入总预算。保留业务操作ID,重试非幂等操作前检查不确定效果。
重试地图与每操作总预算。
- 5
停止已无用工作
根据客户端真实限制,定义覆盖等待、连接和处理的整体期限。入队前拒绝过期任务。本地取消不能证明服务器停止,应核对状态。测试逐步恢复流量,避免同时重启所有队列。
传递期限与停止或核对证据。
可复现的验收案例
虚构示例:数据不代表客户或实际观察结果。
查看案例输入
{
"http_status": 429,
"retry_after_seconds": 30,
"workers": 20,
"retry_budget": 3,
"retry_budget_scope": "per_worker_retries_excluding_initial_request",
"scheduling_example": {
"response_received_at_seconds": 0,
"illustrative_retry_seconds": [
30,
31,
32,
33,
34
],
"workers_per_second": 4,
"alternative_deadline_seconds": 25,
"total_attempts_if_all_retries_used": 80
}
}预期判断
遵守30秒等待,错开20个工作进程的重试,并限制次数。
二十个客户端:错开并计算重试
虚构示例:20个工作进程在 +0 s 各收到429响应和 Retry-After: 30。时间表仅展示一种分布,不保证服务器容量。每个进程除初次请求外可重试3次。
| 策略 | 计算或时间安排 | 效果与限制 |
|---|---|---|
| 同时重试 | 20 × 1 = 20 @ +30 s | 等待30秒遵守了延迟要求,但20个请求会一起返回,流量尖峰可能再次出现。 |
| 错开重试 | 4 × 5 = 20 @ +30…+34 s | 每秒4个请求,持续5秒,将20次重试分散,但不减少总数。这个示例时间表不能替代带随机抖动的退避策略。 |
| 25秒后截止 | 25 s < 30 s → 0 | 剩余时间少于要求的30秒时,应按契约停止或延期,不要为了截止时间缩短等待。 |
| 最大预算 | 20 × (1 + 3) = 80 | 用完所有尝试时,初次20个请求加60次重试,共80个请求。上限不保证成功或重复操作安全。 |
待验证的虚构变体
Retry-After包含HTTP日期,而不是秒数。
按文档解释格式并核对时钟。记录算出的等待时间,不要把日期替换成随意设置的延迟。
每个工作进程都有自己的重试预算。
同时计算总负载。协调共享配额并分散重试,避免再次出现同步请求高峰。
产生业务影响的操作没有返回响应。
重试前核实权威状态和幂等约定。超时并不能证明操作没有执行。
应保留的证据
- 收到的响应头、等待格式及使用的时钟。
- 累计尝试预算和最长持续时间。
- 操作标识符与已核对的结果。
验证步骤
- 记录配额范围及重试预算。
- 仅在授权测试中耗尽配额。
- 保留429、Retry-After及受限时间线。 区分技术限流与业务结果,配额耗尽不应被转换为库存为零的响应。
- 在无外部负载模拟中,统计四层各三次总调用的尝试。
- 使虚构排队任务过期,确认不启动新操作。
- 模拟故障后逐步恢复授权工作,保留调用、期限与唯一业务结果。
API:防止多层重试相乘
应用、SDK、代理和服务都可能重试同一次调用。虚构的四层各执行三次总尝试,最多会向故障依赖发出81次调用。在既有配额管理上加入共享预算和有效截止时间。
虚构示例
示例情境
记录配额范围、响应头、等待和重试预算;测试受控耗尽。
决策及预期证据
不能。响应丢失的操作需要独立核对;其他尝试的响应不能证明其状态。
管理指标
| 指标 | 衡量内容 | 首要行动 |
|---|---|---|
| 每次操作的尝试数 | 同一逻辑操作发出的尝试次数 | 调整预算并终止循环 |
| 队列等待时间 | 任务被接受后的等待时间 | 取消或升级处理超期任务 |
| 调用放大 | 依赖调用 / 同一窗口初始业务操作 | 区分总尝试、重试和计划子调用 |
| 接受过期工作 | 有效截止时间后开始的任务 | 同时观察队列、取消和已开始效果 |
常见错误
- 同时重试可能加剧过载。
常见问题解答
429能证明之前的写入没有执行吗?
不能。响应丢失的操作需要独立核对;其他尝试的响应不能证明其状态。
每层三次就是总计三次吗?
不是。虚构四层各三次总尝试会产生最多3⁴ = 81次最终调用。
任务过期能取消远端效果吗?
不一定。应阻止新的无用工作;已开始远端操作需检查状态并在可行时补偿。
Retry-After:等待、预算与重试决策
此语言版本的详细参考说明以英语提供。
Decide whether to retry after 429 or 503
A waiting period answers “when?”, not “may this operation be repeated?”. Before retrying, identify the intended effect, read the provider contract and bound total work. An error status or a lost response does not prove that no earlier attempt produced an effect.
Local teaching model with no request, timer, storage or real write. It considers one decision after 429 or 503 using six predefined headers. Dates are read at the fictional instant 22 October 2026, 10:00:00 UTC, assuming an accurate clock. This is neither a complete HTTP parser nor a Stripe client. Obsolete HTTP-date forms, clock skew, transport and SDK-specific policies are outside the calculation.
Twelve ways to read Retry-After
Durations are seconds. Absolute dates need an explicit clock policy; calculations here assume the stated accurate clock. Past dates become zero in this model without permitting an immediate loop. Integer syntax alone does not define a client’s numeric limits.
| Illustrative value | Reading within this scope | Interpretation decision |
|---|---|---|
30 | Non-negative decimal integer: wait 30 seconds after receipt. | This means seconds, not 30 milliseconds. |
0005 | The 1*DIGIT syntax accepts these digits: 5 seconds. | Do not treat the leading zero as octal. |
0 | A declared delay of zero seconds. | Local policy, budgets and permission to repeat still require checking. |
Thu, 22 Oct 2026 10:00:45 GMT | An HTTP date 45 seconds after the fictional receipt time. | Clock uncertainty must not be silently treated as certainty. |
Thu, 22 Oct 2026 09:59:50 GMT | A date 10 seconds in the past; the model uses zero server wait. | A past date requires neither negative waiting nor unlimited replay. |
Field absent | No server wait is supplied. | This model uses its selected local delay, not a normative default. |
1.5 | 1.5 does not meet integer delay-seconds syntax. | Do not silently round it and call the field valid. |
-1 | -1 is not a non-negative decimal integer for this field. | Do not interpret it as a special permission. |
30s | The s unit suffix is not part of delay-seconds syntax. | Seconds are already implied; 30s is not the form 30. |
30, 60 | Two comma-separated durations are not one valid Retry-After value. | Do not split every comma: a valid HTTP date itself contains one. |
Empty value | The field exists but contains neither expected form. | Keep absent and malformed values distinct in records. |
9999999999999999999999 | The digit string meets integer syntax but exceeds this model’s numeric bounds. | Record the local limit without claiming the RFC sets it; never truncate to retry sooner. |
Compare waiting, remaining budget and duplicate risk
Five parameters cover 144 combinations. Fictional policy: wait for the greater of an interpretable server delay and the already selected local delay, then reserve 10 seconds for one attempt. If the remaining budget is insufficient, stop this interactive retry without shortening the server wait. The reserve is not a measured duration and the selected local delay is not a jitter generator.
Teaching decision :
The selected operation type and budget allow considering a retry in this model. This proves neither success nor authorisation on a real service.
- Interpretable server wait
- 30 s
- Selected wait
- 30 s
- Attempt reserve
- 10 s
- Wait + reserve
- 40 s
- Budget margin
- 20 s
Absent or invalid field: this wait comes from local policy. A real API can require a different decision.
Eight reproducible cases
| Fictional situation | Relevant parameters | Decision and limit |
|---|---|---|
| 429, read and 30-second wait | 429 · 30 seconds Conforming GET read Remaining budget after receipt : 60 s | Retry candidate With 60 seconds remaining, 30 + 10 leaves a 20-second margin. |
| Waiting exceeds the budget | 429 · 30 seconds Conforming GET read Remaining budget after receipt : 20 s | Stop this retry With 20 seconds remaining, do not shorten 30 just to force an attempt. |
| Write with unknown contract | 503 · Future date: +45 seconds POST write: retry contract unverified Remaining budget after receipt : 60 s | Check business state Even positive margin does not validate repeating POST. |
| Write with verified contract | 503 · Future date: +45 seconds POST write: retry contract verified Remaining budget after receipt : 60 s | Retry candidate Verified contract is an assumption, not a test of your provider. |
| Invalid fractional value | 503 · Invalid value: 1.5 Conforming GET read Remaining budget after receipt : 20 s | Retry candidate The five-second fallback is a local teaching choice; retain the parse error. |
| Absent field, long local delay | 429 · Field absent Conforming GET read Remaining budget after receipt : 60 s | Retry candidate The 40-second delay comes from the client rather than the server. |
| HTTP date already passed | 503 · Past date: −10 seconds Conforming GET read Remaining budget after receipt : 20 s | Retry candidate The model retains a five-second local delay; the past date triggers no immediate call. |
| Zero does not remove the budget | 429 · 0 seconds Conforming GET read Remaining budget after receipt : 20 s | Stop this retry The 40-second local delay plus reserve exceed the 20 seconds remaining. |
Five distinctions that change client behaviour
| Reference point | Documented meaning | Practical limit |
|---|---|---|
| 429 | RFC 6585 describes too many requests within a period. Retry-After may be present; a 429 response must not be stored by a cache. | The RFC does not set the provider’s counted identity, window or algorithm. |
| 503 | Retry-After can indicate the expected duration of service unavailability. | A 5xx alone does not establish whether a write can be replayed. |
| HTTP idempotence | PUT, DELETE and safe methods are idempotent in their intended effect. | Responses and logs may differ. Controlled POST retries need an additional contract. |
| Retries at multiple layers | Client, SDK and proxy attempts can multiply load. | In a fictional three-layer example with three total attempts at each layer, one request can generate up to 3 × 3 × 3 = 27 calls at the last layer. |
| Jitter and budget | AWS describes spreading retries to avoid synchronised clients. | Randomness makes no write idempotent and replaces neither a deadline nor an attempt limit. |
Five items for retry acceptance evidence
- Method, route, contract version and logical operation identity; keep secrets out of keys and logs.
- Status, raw field, receipt time, interpretation and clock assumption.
- Selected delay, current attempt, remaining budget and the layer actually controlling retries.
- Known or unknown business state, retry key, associated context and parameters, and reconciliation evidence when needed.
- Verified final outcome and user behaviour: understandable waiting, retained input and no button that unintentionally recreates an operation.
Compare idempotency contracts →
Primary sources and limits
The RFCs define the cited HTTP elements. AWS describes design choices and Stripe documents its own APIs. Budgets, local waits, cases and diagrams are educational: they neither measure your service nor execute requests.
- IETF · RFC 9110 — Retry-After et idempotence HTTP · June 2022 · STD 97
§5.6.7; §9.2.2; §10.2.3; §15.6.4 - IETF · RFC 6585 — 429 Too Many Requests · April 2012 · Standards Track
§4 - AWS Builders’ Library · Timeouts, retries, and backoff with jitter · Published 2019-12-05; accessed 2026-10-22
Retries; jitter; timeout scope - Stripe · Idempotent requests · Documentation accessed 2026-10-22
API v1: saved results, parameters, key pruning, execution boundary - Stripe · API v2 overview — Idempotency · Documentation accessed 2026-10-22
POST/DELETE; same API and account/sandbox; 30-day replay window - Stripe · Advanced error handling · Documentation accessed 2026-10-22
Stripe-Should-Retry; status codes; idempotency
References reviewed
GraphQL:错误、列表和部分数据
此语言版本的详细参考说明以英语提供。
GraphQL cost and partial results: two separate checks
An authorized query can still be too costly; a partial response measures none of its resource consumption.
- Compare absent data, partial data and data: null.
- Keep the original path even when a parent becomes null.
- Test permissions, quotas and interface states separately.
Explore GraphQL responses and nullability →
GraphQL Specification · September 2025 · Published edition · September 2025
官方参考文献
参考文献支持该方法。 请根据您的实际情况调整检查;它们并非认证。 原始参考文献标题和源文档可能使用其他语言。
参考资料查阅日期 .
- IETF — RFC 6585, HTTP 429
- IETF — RFC 9110, Retry-After
- AWS — Timeouts, retries, and backoff with jitter
- IETF — RFC 9110, Retry-After
- GraphQL Specification · September 2025
- IETF · RFC 9110 — Retry-After et idempotence HTTP
- IETF · RFC 6585 — 429 Too Many Requests
- Stripe · Idempotent requests
- Stripe · API v2 overview — Idempotency
- Stripe · Advanced error handling
