ShortyyDocs

Rate Limiting & Token-Bucket Algorithm

Understand Shortyy continuous token-bucket rate limiting, burst capacities, refill intervals, and HTTP 429 response handling.

Rate Limiting & Token-Bucket Algorithm

Shortyy implements a continuous Token-Bucket Rate Limiter powered by atomic Redis Lua scripts. Unlike traditional fixed-window limiters that cause artificial request spikes and lockouts at the boundary of an hour, the token-bucket allows natural burst traffic while continuously replenishing quota every second.


Token-Bucket Algorithm

Every API key has a virtual "bucket" with a maximum capacity $C$ and a continuous refill rate $R$ tokens per second:

▪
Each link creation request (POST /v1/links) consumes 1 token.
▪
If the bucket has at least 1 token, the request succeeds immediately and the token count decrements.
▪
Tokens continuously refill up to maximum capacity $C$.
▪
If the bucket is empty, the request is rejected with HTTP 429 Too Many Requests accompanied by exact retryAfterSeconds.

Plan Capacities & Refill Rates

Channel / TierBurst Capacity ($C$)Refill Rate ($R$)Refill IntervalMax Link ExpirationEquivalent Sustained Rate
Guest (Homepage)4 tokens1 token / 15 sec15 seconds1 hour240 links / hour (4/min)
Free Developer (SDK & API)4 tokens1 token / 75 sec75 seconds3 hours (SDK)24 hours (Web)48 links / hour
Basic20 tokens1 token / 5 sec5 seconds100 years720 links / hour
Pro100 tokens5 tokens / 1 sec0.2 seconds100 years18,000 links / hour
EnterpriseCustomCustomSub-second100 yearsDedicated throughput
Guest Link Rules: Unauthenticated visitors creating links on the homepage can burst up to 4 links immediately, replenishing 1 token every 15 seconds (4 links per minute sustained). To prevent abuse, guest links expire automatically after 1 hour.

>

Free Developer Rules: Creating a free account unlocks persistent dashboard management, official SDK access, scoped API keys, and extended expiration horizons up to 24 hours (or 3 hours via the SDK and REST API).

Standard Response Headers

Every API response returns standard, authoritative rate limit headers:

HeaderDescriptionExample
X-RateLimit-LimitThe maximum token capacity for the authenticated tier4
X-RateLimit-RemainingCurrent remaining tokens available right now3
X-RateLimit-ResetUTC timestamp (in seconds) when the bucket will be completely full1763040120
Retry-AfterPresent on 429 responses: seconds to wait before trying again15

Handling HTTP 429 Responses

When your bucket is exhausted, the API returns HTTP 429 Too Many Requests with both the standard Retry-After header and the typed retryAfterSeconds JSON field:

json
{
  "error": {
    "code": "RATE_LIMIT_EXCEEDED",
    "message": "That's four links already. Give us 15 seconds and try again.",
    "status": 429,
    "retryAfterSeconds": 15
  }
}

Always pause your worker or display a live countdown for retryAfterSeconds before sending another creation request. Avoid automatic blind retries without delay.