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.
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.
cookies() at the render layer..gp and .pdf format documents from the main payload, store them directly on AWS S3, and return only the file path along with slim projection optimization from MongoDB.
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"]
Optimize BullMQ connection configurations by fine-tuning polling time parameters:
drainDelay and stalledInterval to reduce the frequency of workers pinging Redis when the queue is empty.
const queue = new Queue('pet-tasks', {
connection: redisConnection,
defaultJobOptions: {
attempts: 3,
backoff: {
type: 'exponential',
delay: 5000,
},
},
settings: {
drainDelay: 30,
stalledInterval: 60000,
},
});
Distilled from practical experience, here is a quick checklist to help maintain a stable system without spending money:
headers() in Next.js to avoid accidentally forcing static pages to become dynamic.
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].