DEV Community

Alex Spinov
Alex Spinov

Posted on

Upstash Has a Free API You're Not Using

Upstash provides serverless Redis and Kafka with a REST API. It works from Edge Functions, Cloudflare Workers, Vercel — anywhere HTTP works.

The Free APIs You're Missing

1. REST API — Redis from Anywhere

import { Redis } from "@upstash/redis";

const redis = Redis.fromEnv();

await redis.set("user:123", { name: "Alice", plan: "pro" });
const user = await redis.get("user:123");

// Works in Edge Functions, Cloudflare Workers, Vercel Edge
// No TCP connection needed — pure HTTP
Enter fullscreen mode Exit fullscreen mode

2. Rate Limiting — Built-In

import { Ratelimit } from "@upstash/ratelimit";

const ratelimit = new Ratelimit({
  redis: Redis.fromEnv(),
  limiter: Ratelimit.slidingWindow(10, "10 s"),
});

export async function middleware(req) {
  const ip = req.headers.get("x-forwarded-for");
  const { success, limit, remaining } = await ratelimit.limit(ip);

  if (!success) {
    return new Response("Too many requests", { status: 429 });
  }
}
Enter fullscreen mode Exit fullscreen mode

3. QStash — Serverless Message Queue

import { Client } from "@upstash/qstash";

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

// Publish message to your endpoint
await qstash.publishJSON({
  url: "https://myapp.com/api/process",
  body: { orderId: "order-123", action: "fulfill" },
  retries: 3,
  delay: "30s",
});

// Schedule recurring messages
await qstash.publishJSON({
  url: "https://myapp.com/api/cleanup",
  cron: "0 */6 * * *",
});
Enter fullscreen mode Exit fullscreen mode

4. Vector — Serverless Vector Database

import { Index } from "@upstash/vector";

const index = new Index();

// Upsert vectors
await index.upsert([
  { id: "doc-1", vector: [0.1, 0.2, ...], metadata: { title: "How to cook pasta" } },
  { id: "doc-2", vector: [0.3, 0.1, ...], metadata: { title: "Italian recipes" } },
]);

// Query similar vectors
const results = await index.query({
  vector: [0.15, 0.18, ...],
  topK: 5,
  includeMetadata: true,
});
Enter fullscreen mode Exit fullscreen mode

5. Workflow — Durable Serverless Functions

import { serve } from "@upstash/workflow/nextjs";

export const { POST } = serve(async (context) => {
  const order = context.requestPayload;

  await context.run("validate", async () => {
    return validateOrder(order);
  });

  await context.run("charge", async () => {
    return chargePayment(order);
  });

  await context.sleep("wait-confirmation", 60);

  await context.run("fulfill", async () => {
    return fulfillOrder(order);
  });
});
Enter fullscreen mode Exit fullscreen mode

Getting Started

npm install @upstash/redis @upstash/ratelimit
Enter fullscreen mode Exit fullscreen mode

Free tier: 10K commands/day.


Need data from any website delivered as clean JSON? I build production web scrapers that handle anti-bot, proxies, and rate limits. 77 scrapers running in production. Email me: Spinov001@gmail.com

Check out my awesome-web-scraping list for the best scraping tools and resources.

Top comments (0)