Why move work to the background
A web request should finish in well under a second. Calling an SMS provider, resizing ten photos or exporting a year of invoices can take much longer and may fail on a third party's side. Putting that work in a job means the page responds immediately ("Your report is being prepared") and the job can retry if the provider is temporarily down.
How it works
The app writes a job description to a queue (Redis, a database table, Amazon SQS and similar). Separate worker processes pick jobs up, run them and mark them done or failed. Frameworks include Laravel Queues, Sidekiq for Ruby, Celery and RQ for Python, BullMQ for Node.js and Hangfire for .NET. Scheduled jobs, which run at set times, are usually triggered by cron or a scheduler.
Things to get right
- Make jobs idempotent, because they may run twice after a crash.
- Set retry limits and send repeated failures to a dead-letter queue for review.
- Monitor queue length; a growing backlog is an early sign of trouble.
- Keep job payloads small and pass IDs, not whole records that may be outdated by the time the job runs.
Questions, answered
A cron job runs on a timetable; a background job is usually triggered by an event and queued.
A well-configured queue makes the job visible again after a timeout so another worker can retry it.