Urgent.News

What's breaking now, across hundreds of outlets.

AI

One Redis, five jobs: how Upstash keeps my job board's AI costs and serverless state in check

Sponsored by Upstash . I picked the topic, the code is from my production app, and the opinions are mine. I was running Upstash Redis on this site before they reached out. Upstash found me through my earlier post on rate limiting Next.js routes for scrapers. This is the sequel: everything else Redis ended up doing. TL;DR PMHNP Hiring runs on Vercel, so no two requests are guaranteed to share…

Upstash discovered the writer before reaching out, through a post about rate limiting Next.js routes for scrapers. The writer uses Upstash Redis on a niche job board for psychiatric nurse practitioners, which is built with Next.js on Vercel and Postgres on Supabase through Prisma. Upstash Redis provides five key functions for the app: rate limiting, caching AI responses, capping AI usage per tenant, holding atomic daily quotas, and coordinating cron jobs and a shared Google API quota.

The app imports the Redis client from '@upstash/redis' and initializes it with the URL and token from environment variables. If these variables are not present, the Redis client is set to null. This setup allows the app to work seamlessly with serverless and edge functions using HTTP. Upstash Redis charges per request, making it an ideal choice for a site with fluctuating traffic.

The writer implements rate limiting for different API routes and crawlers using Upstash Ratelimit. Each limit is defined in a RATE_LIMITS table, with various limits such as "3 job posts a minute" and "10 candidate messages a day." The rate limiting is achieved using a sliding window algorithm, which keeps track of the number of requests within a specific time frame. The rate limit check returns success, reset time, and remaining requests.

An AI cache sits in front of the rate limiter for every AI call in the app. The cache lookup is free, and it does not spend rate-limit budget. If the cached response is found, it is returned immediately, saving costs and reducing API calls. The cache key is built using SHA-256 hashing of the input identifier and the prompt file itself, ensuring that each unique request has a distinct key.

In summary, Upstash Redis plays a crucial role in the job board's AI cost management and serverless state by providing rate limiting, AI response caching, tenant usage capping, atomic daily quotas, and coordination of cron jobs and Google API quotas.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in AI

I built two free Android apps for short-form creators: Klipora AI (long video to Shorts) and Capify AI (on-device captions)

Most "AI shorts" tools are paid web apps with watermarks and upload limits. I wanted something free that runs from a phone, so we (SimpleFy) built two small Android apps.

  • Klipora AI converts long videos to vertical Shorts with synced captions.
  • Capify AI adds clean, word-synced captions on-device without uploading videos.
  • Both apps support multiple languages and offer unique features for short-form creators.

More from Tuesday, 1 December 2026 →