DEV Community

Alex Spinov
Alex Spinov

Posted on

Upstash Has Free Serverless Redis — Zero-Config Caching and Rate Limiting for Edge Functions

Why Upstash?

Upstash is serverless Redis with per-request pricing. Pay $0 for idle time. Works with Vercel Edge, Cloudflare Workers, Deno Deploy — any edge runtime.

npm install @upstash/redis
Enter fullscreen mode Exit fullscreen mode
import { Redis } from '@upstash/redis'

const redis = Redis.fromEnv()  // reads UPSTASH_REDIS_REST_URL + TOKEN

await redis.set('user:123', { name: 'John', plan: 'pro' })
const user = await redis.get('user:123')
Enter fullscreen mode Exit fullscreen mode

Rate Limiting

npm install @upstash/ratelimit
Enter fullscreen mode Exit fullscreen mode
import { Ratelimit } from '@upstash/ratelimit'
import { Redis } from '@upstash/redis'

const ratelimit = new Ratelimit({
  redis: Redis.fromEnv(),
  limiter: Ratelimit.slidingWindow(10, '60 s'),  // 10 requests per minute
})

export async function middleware(request) {
  const ip = request.headers.get('x-forwarded-for')
  const { success } = await ratelimit.limit(ip)
  if (!success) return new Response('Rate limited', { status: 429 })
}
Enter fullscreen mode Exit fullscreen mode

QStash (Message Queue)

import { Client } from '@upstash/qstash'

const qstash = new Client({ token: process.env.QSTASH_TOKEN })

await qstash.publishJSON({
  url: 'https://your-api.com/process',
  body: { orderId: '123' },
  retries: 3,
  delay: '10s',
})
Enter fullscreen mode Exit fullscreen mode

Upstash vs Redis Cloud vs ElastiCache

Feature Upstash Redis Cloud ElastiCache
Pricing Per-request Per-hour Per-hour
Free tier 10K/day 30MB None
Edge REST API TCP TCP
Setup 30 sec 5 min 30 min

Need to extract data from any website at scale? I build custom web scrapers — 77 production scrapers running on Apify Store. Email me at spinov001@gmail.com for a tailored solution.

Top comments (0)