# Background Jobs, Queues and Scheduled Tasks

> Move slow or unreliable work like emails, PDF generation and reminders out of the request into retryable background jobs. Free notes, key concepts, resources...

Canonical: https://www.internhack.in/roadmaps/tracks/full-stack/background-jobs
Last updated: 2026-11-28

Move slow or unreliable work like emails, PDF generation and reminders out of the request into retryable background jobs.

Advanced · about 5 hours · difficulty 4/5

Learn first: [Node.js Runtime Essentials](https://www.internhack.in/roadmaps/tracks/full-stack/nodejs-runtime), [Relational Data Modelling in PostgreSQL](https://www.internhack.in/roadmaps/tracks/full-stack/postgres-data-modeling)

A request should return in well under a second. Anything slow or unreliable (sending emails, generating offer letter PDFs, calling a flaky third-party API) belongs in a **background job**.

### The pattern

1. The request handler validates input, writes to the database and **enqueues** a job.
2. A separate **worker** process picks up the job and does the work.
3. Failed jobs are **retried** with backoff, and permanently failed ones are kept for inspection.

### Tools

- **BullMQ** with Redis is the common choice for Node.js.
- PostgreSQL-backed queues (pg-boss, Graphile Worker) avoid adding Redis.
- Hosted options (Inngest, Trigger.dev, QStash) fit serverless apps.
- **Cron jobs** or scheduled jobs handle periodic tasks like daily deadline reminders.

### Making jobs safe

- Jobs must be **idempotent**: running twice should not send two offer letters. Store a "sent" flag or use unique job ids.
- Pass ids, not whole objects, and re-read fresh data inside the job.
- Monitor queue length and failed jobs.

### Pitfalls

- Sending emails inline in the request, so a slow SMTP server slows every signup.
- Fire-and-forget promises in serverless functions that get killed before finishing.
- No retry limit, so a broken job loops forever.

You are ready to move on when your portal sends application emails and a daily deadline digest through a queue with retries, and a failed job is visible and replayable.

## Key concepts

- **Why move work off the request**
- **Queues and workers**
- **Retries and backoff**
- **Idempotent jobs**
- **BullMQ with Redis**
- **PostgreSQL-backed queues**
- **Scheduled and cron jobs**
- **Transactional email providers**

## Mini project

Add a job queue to your portal: send confirmation emails on application, generate a PDF summary for placement officers, and run a daily 8 am deadline reminder, all with retries and a simple failed-jobs view.

## Check yourself

A worker crashes after sending an email but before marking the job complete. What happens on retry, and how do you prevent a duplicate email?

## Free resources

- [BullMQ Documentation](https://docs.bullmq.io/) (BullMQ)
- [pg-boss](https://github.com/timgit/pg-boss) (pg-boss)
- [Inngest Documentation](https://www.inngest.com/docs) (Inngest)

Previous: [Realtime Features with WebSockets](https://www.internhack.in/roadmaps/tracks/full-stack/realtime) · Next: [Payments with Razorpay](https://www.internhack.in/roadmaps/tracks/full-stack/payments-razorpay)

## More in Beyond CRUD: Real-World Features

- [File Uploads and Object Storage](https://www.internhack.in/roadmaps/tracks/full-stack/file-uploads)
- [Realtime Features with WebSockets](https://www.internhack.in/roadmaps/tracks/full-stack/realtime)
- [Background Jobs, Queues and Scheduled Tasks](https://www.internhack.in/roadmaps/tracks/full-stack/background-jobs)
- [Payments with Razorpay](https://www.internhack.in/roadmaps/tracks/full-stack/payments-razorpay)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Full-Stack Developer Roadmap](https://www.internhack.in/roadmaps/tracks/full-stack)
