Skip to content

Commit 312d3b8

Browse files
committed
docs: add comprehensive rate limiting documentation and decorator usage notes
- Create complete rate limiting documentation (docs/usage/rate-limiting.md) - Overview of rate limiting features and backends - Configuration guide for in-memory and Redis backends - Usage examples and best practices - Security considerations and troubleshooting - 541 lines of comprehensive documentation - Add rate limiting feature to README.md and docs/index.md - Describe conservative limits for auth endpoints - Mention both in-memory and Redis backend support - Note HTTP 429 responses with Retry-After header - Highlight Prometheus metrics integration - Add decorator ordering notes to both caching and rate limiting docs - Document correct order when using both decorators - Explain security rationale (rate limit before cache) - Provide code examples with both decorators - Cross-reference between documentation pages - Update mkdocs.yml navigation - Add "Rate Limiting and Security" before Metrics section - Position logically in Usage section All documentation follows existing style and format.
1 parent 892b335 commit 312d3b8

File tree

5 files changed

+592
-0
lines changed

5 files changed

+592
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ following advantages to starting your own from scratch :
128128
collection tracks HTTP performance (requests, latency, in-flight), business
129129
metrics (auth failures, API key usage, login attempts), and custom
130130
application metrics. Exposed via `/metrics` endpoint when enabled.
131+
- **Rate limiting** for authentication endpoints to protect against brute force
132+
attacks, spam, and abuse. Disabled by default, supports both in-memory (for
133+
single-instance) and Redis (for multi-instance) backends. Conservative limits
134+
applied to login (5/15min), registration (3/hour), password recovery (3/hour),
135+
and other auth routes. Returns HTTP 429 with `Retry-After` header when limits
136+
exceeded. Violations tracked via Prometheus metrics when enabled.
131137
- **A command-line admin tool**. This allows to configure the project metadata
132138
very easily, add users (and make admin), and run a development server. This
133139
can easily be modified to add your own functionality (for example bulk add

docs/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ following advantages to starting your own from scratch :
7777
collection tracks HTTP performance (requests, latency, in-flight), business
7878
metrics (auth failures, API key usage, login attempts), and custom
7979
application metrics. Exposed via `/metrics` endpoint when enabled.
80+
- **Rate limiting** for authentication endpoints to protect against brute force
81+
attacks, spam, and abuse. Disabled by default, supports both in-memory (for
82+
single-instance) and Redis (for multi-instance) backends. Conservative limits
83+
applied to login (5/15min), registration (3/hour), password recovery (3/hour),
84+
and other auth routes. Returns HTTP 429 with `Retry-After` header when limits
85+
exceeded. Violations tracked via Prometheus metrics when enabled.
8086
- **A command-line admin tool**. This allows to configure the project metadata
8187
very easily, add users (and make admin), and run a development server. This
8288
can easily be modified to add your own functionality (for example bulk add

docs/usage/caching.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,24 @@ async def expensive_query(request: Request, response: Response):
212212
The `@cached()` decorator MUST be placed AFTER the route decorator
213213
(`@router.get()`, etc.) to work correctly.
214214

215+
!!! tip "Using with Rate Limiting"
216+
When using both `@cached()` and `@rate_limited()` decorators together,
217+
place rate limiting first for security. Rate limits should be checked
218+
before returning any response (including cached ones):
219+
220+
```python
221+
from app.cache import cached
222+
from app.rate_limit.decorators import rate_limited
223+
224+
@router.get("/endpoint")
225+
@rate_limited("10/minute") # Check rate limit first
226+
@cached(expire=300) # Then check cache
227+
async def handler(request: Request, response: Response):
228+
return data
229+
```
230+
231+
This ensures rate-limited users don't bypass limits via cached responses.
232+
215233
### With Custom Key Builders
216234

217235
For user-scoped caching, use built-in key builders:

0 commit comments

Comments
 (0)