Priority Queue
ELI5 — The Vibe Check
A priority queue is a job queue with a VIP lane. High-priority tasks jump ahead of low-priority ones. Password reset emails? High priority. Weekly newsletter? Low priority. It's like the ER triage system — heart attacks before paper cuts.
Real Talk
A priority queue processes messages based on assigned priority levels rather than strict FIFO ordering. Higher-priority messages are dequeued first, enabling critical tasks to bypass less urgent ones. Implementation varies by system: some use multiple queues per priority level, others use sorted data structures or dedicated priority fields.
Show Me The Code
// BullMQ priority (lower number = higher priority)
await queue.add('password-reset', { userId: 1 }, { priority: 1 });
await queue.add('newsletter', { batch: 500 }, { priority: 10 });
await queue.add('analytics', { event: 'click' }, { priority: 100 });
When You'll Hear This
"Payment confirmations go into the priority queue ahead of marketing emails." / "Use priority queues to ensure critical alerts aren't delayed by bulk jobs."
Related Terms
Background Job
A background job is work your app does behind the scenes that the user doesn't wait for.
Job Queue
A job queue is a to-do list for your server.
Message Queue
A Message Queue is a waiting room for tasks. Producers drop tasks in the queue, consumers pick them up and process them one at a time.
Queue
A queue is like a line at a coffee shop — first come, first served. The first person to get in line is the first to get their coffee.