-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bced2c2
commit 0bc2f79
Showing
1 changed file
with
15 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# 设计API限流器 | ||
|
||
我们来设计一个API限流器,用于根据用户发送请求的数量进行限流。 | ||
|
||
**难度级别:中等** | ||
|
||
## 1. 什么是限流器? | ||
假设我们有一个服务正在接收大量请求,但只能处理有限数量的每秒请求。为了解决这一问题,我们需要某种限流机制,允许在特定时间内仅接收一定数量的请求,以确保服务能够正常响应所有请求。 | ||
|
||
从高层次来看,限流器限制一个实体(用户、设备、IP等)在特定时间窗口内可以执行的事件数量。例如: | ||
- 用户每秒只能发送一条消息。 | ||
- 用户每天最多允许三次信用卡交易失败。 | ||
- 单个IP每天只能创建二十个账户。 | ||
|
||
通常,限流器会限制发送方在特定时间窗口内发出的请求数量,并在达到限制时阻止后续请求。 |