Overview
Running a personal system on free or hobby tiers offers significant cost savings, but it also pushes engineers into strict resource limitation challenges. The tech stack includes Next.js deployed on Vercel Hobby, a NestJS backend on Render Hobby, MongoDB Atlas M0 database, and Upstash Redis combined with BullMQ for background tasks.
Everything ran smoothly until the system started experiencing modest growth and free-tier quotas were reached. This article dives into the causes and solutions for each specific bottleneck.
Problem 1: Vercel ISR and the Write Units nightmare
Cause
The Next.js system is currently using Incremental Static Regeneration (ISR) with SSR. But the misuse of the cookies() function on pages that appear to be public effectively turns these requests into dynamic renders, forcing Vercel to perform constant recalculations.
Additionally, the habit of releasing code multiple times a day along with caching bloated objects due to directly embedding base64 data pushed Write Units to a peak of about 32,000 requests per day, exceeding the allowed Vercel Hobby limit.
Solutions
- Move public routes entirely to Static or standard ISR instead of relying on
cookies()at the render layer. - Use a CSS auth toggle pattern: render the static UI on the server, then use client-side fetching combined with tokens stored in localStorage to show or hide components reserved for logged-in users.
- Separate heavy files like
.gpand.pdfformat documents from the main payload, store them directly on AWS S3, and return only the file path along with slim projection optimization from MongoDB.
Problem 2: BullMQ and Upstash Redis burning through the 500k commands quota
Cause
BullMQ defaults to continuous polling mechanisms in Redis to check for new jobs. With default configurations, workers maintain connections and constantly send commands even in an idle state.
As a result, the free limit of 500,000 commands on Upstash Redis was depleted in a short time, causing a series of background processing pipelines to grind to a halt.
flowchart LR A["NestJS Worker"] -->|"Polling 24/7 (Default)"| B["Upstash Redis"] B -->|"Reach 500k commands"| C["Rate Limit Exceeded"] C --> D["System Crash"] Solutions
Optimize BullMQ connection configurations by fine-tuning polling time parameters:
- Increase
drainDelayandstalledIntervalto reduce the frequency of workers pinging Redis when the queue is empty. - Apply an exponential backoff strategy for retrying jobs to avoid bombarding the system with failed requests.
- Build a temporary in-memory fallback mechanism so the system does not crash completely when Redis hits its limits.
const queue = new Queue('pet-tasks', { connection: redisConnection, defaultJobOptions: { attempts: 3, backoff: { type: 'exponential', delay: 5000, }, }, settings: { drainDelay: 30, stalledInterval: 60000, }, }); Optimization checklist for Free/Hobby Tier
Distilled from practical experience, here is a quick checklist to help maintain a stable system without spending money:
- Review all usage of
cookies()andheaders()in Next.js to avoid accidentally forcing static pages to become dynamic. - Avoid embedding heavy base64 strings into state or cache; push large files to object storage like S3.
- Reconfigure
drainDelayfor BullMQ workers to save Redis commands during idle time. - Set up alerts close to quota limits for Vercel, Render, and Upstash to address issues early before the system goes down.
Conclusion
Running a system on free/hobby tiers requires great care in architectural design and resource management. By refining the Next.js caching strategy and optimizing the BullMQ polling lifecycle, the cat-raising management system is running smoothly again [add result].