Skip to main content

Overview

The JOIP API implements rate limiting using a token bucket algorithm to protect against abuse and ensure fair resource allocation.

Rate Limiting Algorithm

Token Bucket Implementation

The API uses an in-memory token bucket system:
How it works:
  1. Each user/IP starts with a full bucket of tokens
  2. Each request consumes one token
  3. Tokens refill gradually over time
  4. When tokens reach zero, requests are rejected with 429

Token Refill Logic

Rate Limit Policies

Public API Endpoints

Limit: 100 requests per 15 minutes per IP
Applied to:
  • /api/sessions/*
  • /api/media/*
  • /api/community/*
  • Most authenticated endpoints

Reddit API Proxy

Limit: 30 requests per 5 minutes per IP
Applied to:
  • /api/fetch-reddit
  • Reddit content fetching endpoints
Why more restrictive? Protects against hitting Reddit’s API rate limits.

Authentication Endpoints

Limit: 5 attempts per 15 minutes per IP
Applied to:
  • /api/login
  • Authentication-related endpoints
Special behavior: Only failed login attempts count toward the limit.

Import Operations

Limit: 5 imports per 15 minutes per user
Applied to:
  • /api/sessions/import-joip
  • Import-related endpoints
Key difference: Limited by user ID instead of IP address.

Payment Endpoints

Payment Callbacks

Limit: 60 requests per minute per IP
Why generous? Handles payment gateway retries and webhooks.

Payment Creation

Limit: 10 requests per 15 minutes per user

Telegram Webhooks

Limit: 100 requests per minute per IP

Rate Limit Headers

Every API response includes rate limit information:

Example Response Headers

Rate Limit Exceeded Response

When rate limit is exceeded, you’ll receive: Status Code: 429 Too Many Requests Response Body:

Example Response

Key Generation

Rate limits are applied per key. The key can be based on:

IP Address (Default)

Handles proxied requests by reading X-Forwarded-For header.

User ID (Authenticated Endpoints)

Used for user-specific limits like imports and payments.

Special Behaviors

Skip Successful Requests

Some limiters don’t count successful requests:
Example: Authentication endpoint only counts failed login attempts.

Skip Failed Requests

Some limiters don’t count failed requests:
Example: Reddit API limiter doesn’t penalize for Reddit’s errors.

Token Refund Logic

Memory Management

Automatic Cleanup

Old buckets are cleaned up every minute:
Cleanup policy: Delete buckets inactive for 2x the window duration.

Best Practices

1. Monitor Rate Limit Headers

Always check response headers to track your usage:

2. Implement Exponential Backoff

3. Batch Requests

Reduce API calls by batching when possible:

4. Cache Responses

Cache API responses to reduce redundant requests:

Rate Limit Summary Table

Common Issues

Rate Limit Exceeded on Login

Problem: Can’t login after multiple failed attempts Solution: Wait 15 minutes or use different test account

Rate Limit with VPN/Proxy

Problem: Shared IP hits rate limits quickly Solution:
  • Use authenticated endpoints (rate limited by user ID)
  • Disable VPN for development
  • Contact support for IP allowlist

Rate Limit in Development

Problem: Hitting limits during local testing Solution:
  • Use different test accounts to get separate limits
  • Restart server to clear in-memory buckets
  • Implement request caching

Next Steps