Skip to content
OpenSmartRoute
Skillv1.0.0

replit-rate-limits

Handle Replit resource limits: KV database caps, deployment quotas, and request throttling. Use when hitting storage limits, managing deployment resources, or implementing rate limiting in your Replit

by jeremylongshore(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from jeremylongshore/tons-of-skills-marketplace (plugins/saas-packs/replit-pack/skills/replit-rate-limits/SKILL.md). Install upstream with npx skills add jeremylongshore/tons-of-skills-marketplace --skill replit-rate-limits. Copyright stays with the author (MIT).

Replit Rate Limits

Overview

Understand and work within Replit's resource limits: Key-Value Database size caps, Object Storage quotas, deployment compute budgets, and egress allowances. Implement rate limiting in your own app for production safety.

Prerequisites

  • Replit account with active Repls
  • Understanding of your current resource usage
  • For rate limiting: Express or Flask app

Replit Platform Limits

Key-Value Database

Limit Value
Total storage 50 MiB (keys + values combined)
Maximum keys 5,000
Key size 1,000 bytes
Value size 5 MiB per value

Object Storage (App Storage)

Limit Value
Object size Configurable per bucket
Bucket count Per Repl (auto-provisioned)
Rate Throttled at high request volume

PostgreSQL

Limit Value
Storage Plan-dependent (1-10+ GB)
Connections Pooled, plan-dependent
Dev + Prod Separate databases auto-provisioned

Deployments

Resource Autoscale Reserved VM
Scale behavior 0 to N based on traffic Always-on, fixed size
Min cost Pay per request $0.20/day (~$6.20/month)
Max resources Plan-dependent Up to 4 vCPU, 16 GiB RAM
Egress $0.10/GiB over allowance $0.10/GiB over allowance

Instructions

Step 1: Monitor KV Database Usage

// Check how close you are to KV limits
import Database from '@replit/database';

async function checkKVUsage() {
  const db = new Database();
  const keys = await db.list();
  let totalSize = 0;

  for (const key of keys) {
    const value = await db.get(key);
    const valueSize = JSON.stringify(value).length;
    totalSize += key.length + valueSize;
  }

  const limitMiB = 50;
  const usedMiB = totalSize / (1024 * 1024);
  const percentUsed = (usedMiB / limitMiB * 100).toFixed(1);

  console.log(`KV Usage: ${usedMiB.toFixed(2)} MiB / ${limitMiB} MiB (${percentUsed}%)`);
  console.log(`Keys: ${keys.length} / 5,000`);

  if (parseFloat(percentUsed) > 80) {
    console.warn('WARNING: KV database above 80%. Consider migrating large values to Object Storage.');
  }
}

Step 2: Implement App-Level Rate Limiting

// src/middleware/rate-limit.ts — protect your Replit-hosted API
import { Request, Response, NextFunction } from 'express';

interface RateLimitEntry {
  count: number;
  resetAt: number;
}

const store = new Map<string, RateLimitEntry>();

export function rateLimit(opts = { windowMs: 60000, max: 100 }) {
  return (req: Request, res: Response, next: NextFunction) => {
    const key = req.headers['x-replit-user-id'] as string || req.ip;
    const now = Date.now();
    const entry = store.get(key);

    if (!entry || now > entry.resetAt) {
      store.set(key, { count: 1, resetAt: now + opts.windowMs });
      setRateLimitHeaders(res, opts.max, opts.max - 1, now + opts.windowMs);
      return next();
    }

    entry.count++;
    const remaining = Math.max(0, opts.max - entry.count);
    setRateLimitHeaders(res, opts.max, remaining, entry.resetAt);

    if (entry.count > opts.max) {
      const retryAfter = Math.ceil((entry.resetAt - now) / 1000);
      res.set('Retry-After', String(retryAfter));
      return res.status(429).json({
        error: 'Too many requests',
        retryAfter,
      });
    }

    next();
  };
}

function setRateLimitHeaders(res: Response, limit: number, remaining: number, reset: number) {
  res.set('X-RateLimit-Limit', String(limit));
  res.set('X-RateLimit-Remaining', String(remaining));
  res.set('X-RateLimit-Reset', String(Math.ceil(reset / 1000)));
}

// Clean up expired entries periodically
setInterval(() => {
  const now = Date.now();
  for (const [key, entry] of store) {
    if (now > entry.resetAt) store.delete(key);
  }
}, 60000);

Step 3: Apply Rate Limiting

import express from 'express';
import { rateLimit } from './middleware/rate-limit';

const app = express();

// Global: 100 requests per minute
app.use(rateLimit({ windowMs: 60000, max: 100 }));

// Strict: 10 per minute for write operations
app.post('/api/*', rateLimit({ windowMs: 60000, max: 10 }));

// Generous: 500 per minute for reads
app.get('/api/*', rateLimit({ windowMs: 60000, max: 500 }));

Step 4: Exponential Backoff for External APIs

// When your Replit app calls external APIs
export async function withBackoff<T>(
  fn: () => Promise<T>,
  opts = { maxRetries: 5, baseMs: 1000, maxMs: 30000 }
): Promise<T> {
  for (let attempt = 0; attempt <= opts.maxRetries; attempt++) {
    try {
      return await fn();
    } catch (err: any) {
      if (attempt === opts.maxRetries) throw err;
      const status = err.status || err.response?.status;
      if (status && status !== 429 && status < 500) throw err;

      const delay = Math.min(opts.baseMs * 2 ** attempt, opts.maxMs);
      const jitter = Math.random() * delay * 0.1;
      await new Promise(r => setTimeout(r, delay + jitter));
    }
  }
  throw new Error('Unreachable');
}

Step 5: Request Queue for Burst Protection

import PQueue from 'p-queue';

// Limit concurrent requests to external services
const queue = new PQueue({
  concurrency: 5,       // max parallel requests
  interval: 1000,       // per this window
  intervalCap: 10,      // max requests in window
});

async function rateLimitedFetch(url: string, opts?: RequestInit) {
  return queue.add(() => fetch(url, opts));
}

Error Handling

Error Cause Solution
KV Max storage exceeded Over 50 MiB Migrate large values to Object Storage
KV Max keys exceeded Over 5,000 keys Archive old data, use prefix namespacing
429 from your API Client hitting your limits Return Retry-After header
Object Storage throttled Too many rapid requests Add client-side request queue
High egress costs Large responses Compress, paginate, or cache at CDN

Resources

Next Steps

For security configuration, see replit-security-basics.

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/jeremylongshore-tons-of-skills-marketplace-replit-rate-limits/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

jeremylongshore-tons-of-skills-marketplace-replit-rate-limits.ocm.jsonjson
{
  "ocm": "1",
  "id": "jeremylongshore-tons-of-skills-marketplace-replit-rate-limits",
  "kind": "skill",
  "name": "replit-rate-limits",
  "description": "Handle Replit resource limits: KV database caps, deployment quotas, and request throttling. Use when hitting storage limits, managing deployment resources, or implementing rate limiting in your Replit-hosted app. Trigger with phrases like \"replit rate limit\", \"replit throttling\", \"replit 429\", \"replit storage limit\", \"replit quota\".",
  "publisher": "jeremylongshore",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "general"
    ],
    "tags": [
      "skill-md",
      "saas",
      "replit",
      "api",
      "limits",
      "database",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Handle Replit resource limits: KV database caps, deployment quotas, and request throttling. Use when hitting storage limits, managing deployment resources, or implementing rate limiting in your Replit-hosted app. Trigger with phrases like \"replit rate limit\", \"replit throttling\", \"replit 429\", \"replit storage limit\", \"replit quota\"."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/jeremylongshore/tons-of-skills-marketplace",
      "path": "plugins/saas-packs/replit-pack/skills/replit-rate-limits/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/jeremylongshore/tons-of-skills-marketplace/blob/HEAD/plugins/saas-packs/replit-pack/skills/replit-rate-limits/SKILL.md",
      "key": "jeremylongshore/tons-of-skills-marketplace/plugins/saas-packs/replit-pack/skills/replit-rate-limits/SKILL.md"
    },
    "compatibility": "Designed for Claude Code",
    "allowed_tools": [
      "Read,",
      "Write,",
      "Edit"
    ],
    "license": "MIT"
  },
  "instructions": "# Replit Rate Limits\n\n## Overview\n\nUnderstand and work within Replit's resource limits: Key-Value Database size caps, Object Storage quotas, deployment compute budgets, and egress allowances. Implement rate limiting in your own app for production safety.\n\n## Prerequisites\n\n- Replit account with active Repls\n- Understanding of your current resource usage\n- For rate limiting: Express or Flask app\n\n## Replit Platform Limits\n\n### Key-Value Database\n\n| Limit | Value |\n|-------|-------|\n| Total storage | 50 MiB (keys + values combined) |\n| Maximum keys | 5,000 |\n| Key size | 1,000 bytes |\n| Value si",
  "cost": {
    "context_tokens": 1588
  }
}

Fetch it by URL: GET /api/v1/registry/jeremylongshore-tons-of-skills-marketplace-replit-rate-limits/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.