When dealing with heavy operations like generating PDF invoices in the Studio RSVP system, performing the work synchronously blocks the main thread and ruins the user experience.
The solution? Redis-backed background queues.
The Architecture
We deployed a Redis instance on our Coolify server alongside our Next.js containers.
When a booking is confirmed, the Next.js API route pushes a job to a Redis list:
import Redis from 'ioredis'
const redis = new Redis(process.env.REDIS_URL!)
export async function queueInvoiceGeneration(bookingId: string) {
await redis.lpush('queue:invoices', JSON.stringify({ bookingId, timestamp: Date.now() }))
}The Worker Node
A separate lightweight Node.js worker (also managed by Coolify) continuously pops jobs from this Redis queue, processes the heavy PDF rendering using Puppeteer, and uploads the result to S3.
This decoupled microservice architecture ensures that our Next.js application remains lightning fast and never succumbs to CPU bottlenecks.
