We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
System Design Masterclass · Api Design Protocols
Free preview: the first 2 parts of this 7-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Api Design Protocols
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
It is easy and good
“It is really nice and good Please join the course”
controls speed: "no more than 100 requests per minute." Quota management controls volume: "no more than 10,000 requests this month."
Rate limits protect infrastructure from overload. Quotas protect your business model. Free-tier users get 1,000 API calls per month, pro users get 100,000, enterprise gets unlimited. Rate limits reset every second or minute. Quotas reset daily, monthly, or per billing cycle.
OpenAI gives you a monthly token quota based on your tier. Tier 1 gets 100,000 tokens per minute and 500,000 tokens per day. Tier 5 gets 10,000,000 per minute. Google Maps gives you $200 of free API calls per month, then charges per call. AWS has service quotas (formerly "limits") on everything from Lambda concurrent executions (1,000 default) to S3 bucket counts (100 per account).
The distinction matters for responses too. Rate limit exceeded returns 429 Too Many Requests. Quota exceeded returns 403 Forbidden. The semantics are different: 429 says "slow down, try again soon." 403 says "you have used your allowance for this period."
Quotas are typically tracked in a database (not just ) because they span long periods and the numbers are billable:
CREATE TABLE api_quotas (
api_key_id UUID REFERENCES api_keys(id),
period_start TIMESTAMP NOT NULL,
period_end TIMESTAMP NOT NULL,
usage_count BIGINT DEFAULT 0,
quota_limit BIGINT NOT NULL,
PRIMARY KEY (api_key_id, period_start)
);
Per-request flow:
The hot path never touches the database. Redis INCR is atomic and costs one round trip. A update would need a row lock and a transaction. At ten thousand requests per second, only the Redis path keeps up. But the billing system reads from Postgres, not Redis. Redis is for gating. Postgres is for billing.
Quota headers (every response):
X-Quota-Limit: 10000
X-Quota-Remaining: 3456
X-Quota-Reset: 2024-02-01T00:00:00Z
Overage handling strategies: