Skip to content
Agentmart
Submit a tool

rate-limiting-persistent

Persistent rate limiting using PostgreSQL for atomic counters.

Skill by JimmyBlanquet

IndexedMIT
Write a review

Chalk Labs

Need help deploying rate-limiting-persistent?

Chalk Labs sets up agents like this inside real teams: connected to your tools, tested on your data, with a human in the loop where it matters.

Book a call

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/jimmyblanquet-rate-limiting-persistent-22d8b9

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Persistent rate limiting using PostgreSQL for atomic counters. Survives serverless cold starts and deployments with automatic in-memory fallback.

Use cases: cloud

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found
Runs as
Node.js package

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/rate-limiting-persistent

What's inside

Skill name
rate-limiting-persistent
Description
Persistent rate limiting using PostgreSQL for atomic counters. Survives serverless cold starts and deployments with automatic in-memory fallback.
License
MIT
Instructions
378 lines in SKILL.md · view on GitHub

Before installing

  • Ships executable scripts
  • Instructions call the network

Files (6)

  • README.md
  • SKILL.md
  • persistent-limiter.ts · files/lib/rate-limit/
  • install.sh
  • 20251223100001_create_rate_limits.sql · supabase/migrations/
  • persistent-limiter.test.ts · tests/

SKILL.md (first lines)

# Rate Limiting Persistent Skill

**Version:** 1.0.0
**Category:** Core
**Extracted from:** Production-tested in a real-world SaaS
**Production-ready:** ✅ Yes

## Description

Persistent rate limiting using PostgreSQL for atomic counters. Survives serverless cold starts and deployments with automatic in-memory fallback.

**Key Features:**
- 🗄️ **Persistent Storage**: Uses PostgreSQL for atomic rate limit tracking
- ⚡ **Serverless-Ready**: Survives Vercel/Railway cold starts
- 🛡️ **Automatic Fallback**: In-memory limiter if database unavailable
- ⚙️ **Flexible Configuration**: Per-action rate limits
- 🔒 **Thread-Safe**: Atomic PostgreSQL function prevents race conditions
- 🧹 **Auto-Cleanup**: Periodic cleanup of expired entries

## What This Skill Provides

### Core Components

1. **checkRateLimit()** - Main rate limiting function
   - Uses PostgreSQL `increment_rate_limit()` function
   - Automatic fallback to in-memory limiter
   - Returns: `{ allowed, remaining, resetAt }`

2. **PostgreSQL Function** - Atomic counter increment
   - UPSERT with ON CONFLICT
   - Automatic window reset when expired
   - Returns allowed status + remaining count

3. **In-Memory Fallback** - Resilience when DB unavailable
   - Map-based storage
   - Automatic cleanup every 5 minutes
   - Same interface as persistent limiter

## Installation

### 1. Run Installation Script

```bash
cd skills/core/rate-limiting-persistent
bash install.sh
```

### 2. Apply Supabase Migration

In your Supabase dashboard or CLI:

```bash
supabase migration new create_rate_limits
# Copy contents from supabase/migrations/20251223100001_create_rate_limits.sql
supabase db push
```

Or manually:

```sql
-- See supabase/migrations/20251223100001_create_rate_limits.sql
CREATE TABLE rate_limits (...);
CREATE FUNCTION increment_rate_limit(...);
```

### 3. Install Dependencies

Already included if you have Supabase:

```bash
npm install @supabase/supabase-js
```

## Usage

### Basic Usage

```typescript
import { checkRateLimit } from '@/lib/rate-limit/persistent-limiter'

// In your API route
export async function POST(request: Request) {
  const { userId } = await getUser()

  const rateLimit = await checkRateLimit(userId, {
    action: 'api_call',
    maxRequests: 60,
    windowSeconds: 60
  })

  if (!rateLimit.allowed) {
    return new Response('Rate limit exceeded', {
      status: 429,
      headers: {
        'X-RateLimit-Remaining': '0',
        'X-RateLimit-Reset': new Date(rateLimit.resetAt).toISOString()
      }
    })
  }

  // Process request...
  return Response.json({ success: true })
}
```

### With Rate Limit Headers

```typescript
async function handleRateLimitedRequest(userId: string) {
  const rateLimit = await checkRateLimit(userId, {
    action: 'api',
    maxRequests: 100,
    windowSeconds: 60
  })

  const headers = new Headers({
    'X-RateLimit-Limit': '100',
    'X-RateLimit-Remaining': String(rateLimit.remaining),
    'X-RateLimit-Reset': String(rateLimit.resetAt)

From JimmyBlanquet/project-forge, MIT.

More from JimmyBlanquet/project-forge

Signals

Stars
0
Forks
0
Open issues
2
Last commit (this folder)
May 10, 2026 (5 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from JimmyBlanquet

Done for you

Rather not set it up yourself?

Chalk Labs scopes, builds and runs agents for your team: the task audit, the eval harness, the integrations and the weekly ops report. Fixed scope, priced before we start.

See how we build AI agents →Read the case studies

Chalk Labs is a two-founder AI and growth studio. We build AI agents, CRMs and MVPs for Web3 and AI companies, and have shipped 50+ product and token launches.

launches shipped
50+
launches shipped
media placements
500+
media placements
founders on every account
2
founders on every account

Press we've placed: Forbes · CoinDesk · Decrypt · Cointelegraph · The Block

Rahil Jain, Co-founder, Chalk Labs. Ex-Goldman Sachs engineer. You talk to the person who builds it.

Get rate-limiting-persistent running in your business

Tell us what you want to automate. A founder replies within one working day with a plan, not a pitch deck.

Goes to the Chalk Labs founders, not the newsletter. Privacy

Need help deploying rate-limiting-persistent?

CallGet help
Cite this page

rate-limiting-persistent skill. Agent Mart. https://agentmart.dev/skills/jimmyblanquet-rate-limiting-persistent-22d8b9 (last updated 2026-10-24)