zeroae / zeroae/zae-limiter

📝 Write blog post: "Why Traditional Rate Limiters Break for Variable-Cost Operations"

Open
#167 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation
Dominant language
Python
Stars
0
Forks
0
Avg merge
6h 51m
Merged PRs (30d)
104

Description

Summary

Write and publish a blog post introducing the "estimate-execute-reconcile" pattern for rate limiting variable-cost operations. This is the primary content piece for the 1.0.0 launch.

Title Options

  • "Why Traditional Rate Limiters Break for Variable-Cost Operations"
  • "Rate Limiting for Variable-Cost Operations: The Estimate-Execute-Reconcile Pattern"
  • "The Rate Limiting Pattern Nobody Talks About"

Target Audience

Developers building APIs with variable-cost operations:

  • LLM/AI API builders
  • Video/media processing platforms
  • Metered SaaS products
  • Data pipeline engineers

Outline

# Why Traditional Rate Limiters Break for Variable-Cost Operations

## The Hook (Problem)

You're building an API that calls an LLM. You want to limit users to 
10,000 tokens per minute. Simple, right?

Except: you don't know how many tokens until AFTER the call completes.

Traditional rate limiters can't handle this. They need the cost upfront.

## The Pattern Nobody Talks About

Three types of operations:

1. **Fixed cost** (1 request = 1 unit) → Traditional rate limiters work
2. **Known variable cost** (file size, query params) → Check before, still works  
3. **Unknown variable cost** (LLM tokens, processing time) → ???

Category 3 is increasingly common:
- LLM APIs (tokens vary by response)
- Video/audio processing (duration unknown)
- Data pipelines (records scanned varies)
- Streaming responses (bytes unknown until done)

## The Solution: Estimate → Execute → Reconcile

\`\`\`python
# 1. Estimate and acquire
async with limiter.acquire(consume={"tokens": estimated}) as lease:
    # 2. Execute
    result = await call_llm(prompt)
    # 3. Reconcile
    actual = result.usage.total_tokens
    await lease.adjust(tokens=actual - estimated)
\`\`\`

Key insight: The lease holds a "reservation" that you adjust after.

## Why This Matters

### Without reconciliation:
- Over-estimate → Users blocked unnecessarily
- Under-estimate → Limits exceeded, costs explode

### With reconciliation:
- Estimate conservatively
- Actual usage tracked accurately
- Fair limits, predictable costs

## Implementation Considerations

### 1. Distributed coordination
Multiple servers need consistent view. Options:
- Redis (fast, but need to manage)
- DynamoDB (slower, but serverless)
- PostgreSQL (if you already have it)

### 2. What if reconciliation fails?
- Lease timeout releases reservation
- Next request sees accurate state
- Design for eventual consistency

### 3. Hierarchical limits
User → Org → Global cascade:
- User has 10K tokens/min
- Org has 100K tokens/min
- Check both in one call

## Real Numbers

From our production DynamoDB implementation:
- Latency: 36-51ms p50 (acceptable for LLM calls at 100ms+)
- Cost: ~$1 per million rate limit checks
- Consistency: TransactWriteItems for atomic updates

## When NOT to Use This Pattern

- Fixed-cost operations → Simpler options exist
- Sub-millisecond latency required → Use Redis
- Single process → In-memory is fine

## Conclusion

The "estimate-execute-reconcile" pattern fills a gap that traditional 
rate limiters ignore. As more APIs have variable/unknown costs, 
this pattern becomes essential.

---

We open-sourced our implementation: [zae-limiter](https://github.com/zeroae/zae-limiter)

Visuals Needed

  • Diagram: Three types of operations (fixed, known-variable, unknown-variable)
  • Code snippet: The estimate-execute-reconcile pattern
  • Comparison table: With vs without reconciliation
  • Architecture diagram: Distributed coordination options

Cross-Post Strategy

Platform Format Tags
Personal blog / zeroae.com Full post -
Dev.to Full post #python #aws #serverless #opensource
Medium Full post Python, AWS, Architecture publications
LinkedIn Summary + link Tag AWS connections
Twitter/X Thread (key insights) @awscloud @dynamodb
Hashnode Full post Backend, AWS
Reddit r/programming Link + summary -
Reddit r/aws Link + summary -
Hacker News "Show HN" with 1.0.0 -

Platform-Specific Adaptations

Dev.to Version
  • Full technical depth
  • All code samples
  • Tags for discovery
LinkedIn Version
  • Lead with business problem
  • Shorter, link to full post
  • Tag relevant connections
Twitter/X Thread
1/ Why do traditional rate limiters break for LLM APIs?

Because they need to know the cost BEFORE the request.

But you don't know token count until AFTER the response.

Thread 🧵

2/ Three types of operations:
- Fixed cost (1 req = 1 unit) ✅ Traditional works
- Known variable (file size) ✅ Check before works
- Unknown variable (LLM tokens) ❌ ???

3/ The pattern: Estimate → Execute → Reconcile
[code screenshot]

4/ Key insight: Hold a "reservation" and adjust it after.

Over-estimate? Release the excess.
Under-estimate? Record the actual.

5/ We open-sourced this: [link]

- DynamoDB backend (~$1/1M requests)
- Hierarchical limits (user → org)
- Python async/sync

[link to full post]
Hacker News
  • Straightforward title (no clickbait)
  • "Show HN: zae-limiter - Rate limiting for variable-cost operations"
  • Let discussion happen naturally

Timeline

When Action
Pre-1.0.0 Draft blog post
1.0.0 release day Publish on primary platform
+1 day Cross-post Dev.to, Medium
+2 days LinkedIn, Twitter thread
+3 days Reddit, Hacker News

Success Metrics

  • Blog post views (>1000 in first week)
  • GitHub stars increase
  • PyPI download increase
  • Social engagement (comments, shares)
  • Inbound links

Related

  • #165 - Positioning strategy (messaging alignment)
  • #166 - AWS marketing plan (cross-post strategy)
  • #147, #148 - Supporting documentation

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied outline, implementation considerations, and estimate-execute-reconcile code example. Draft the full post for the listed developer audiences, create the four requested visuals, and adapt or schedule it for the platforms and timeline described. Done means the primary post is published and the cross-post materials are prepared.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
content, documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.