Messaging for the Serverless
Upstash is a serverless database platform that offers different products, including Redis, QStash and Vector database.
Upstash Redis: Upstash provides a serverless database service that is compatible with the Redis API.
Upstash QStash: QStash is a serverless messaging and scheduling solution provided by Upstash. It is designed to easily integrate into existing workflows and help developers build reliable systems without managing infrastructure.
Upstash Vector: Upstash Vector is a serverless vector database designed for working with vector embeddings. It's essential for managing numeric representations of objects (like images, sounds, text) in a multi-dimensional space.
Start by connecting to your existing project and then run vercel link in the CLI to link to the project locally. If you are starting fresh, you can use our Next.js template.
Run vercel env pull .env.development.local to make the latest environment variables available to your project locally.
Run the following command to install the Upstash QStash SDK:
npm install @upstash/qstashYou can find more details and documentation on the Upstash QStash SDK for TypeScript.
To start using the SDK in your project, import the client and use it in your API endpoint:
import { Client } from '@upstash/qstash'import { NextRequest, NextResponse } from 'next/server'
const client = new Client({ baseUrl: process.env.QSTASH_URL!, token: process.env.QSTASH_TOKEN!,})
export const POST = async (request: NextRequest) => {
const { messageId } = await client.publishJSON({ url: `${baseUrl}/${route}`, body: payload, })
return new NextResponse(JSON.stringify({ messageId }), { status: 200 })}If there are endpoints which should only be called by QStash, you can secure them using the verification utility:
import { verifySignatureAppRouter } from "@upstash/qstash/nextjs";import { NextRequest, NextResponse } from "next/server";
async function handler(_req: NextRequest) { return new NextResponse.json(JSON.stringify({ result: "finished" }), { status: 200 });}
// wrap the handler with the verifierexport const POST = verifySignatureAppRouter(handler);Workflow is a layer between the client and Upstash QStash. Here, the business logic can be seperated and run in steps via reliable workflow api. For further clarifications, please check out the docs: Workflow - Getting Started.
It will set the required environment variables which will be used by your project.
*** Redis is a trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd. Any use by Upstash is for referential purposes only and does not indicate any sponsorship, endorsement or affiliation between Redis and Upstash.