Queue
ELI5 — The Vibe Check
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. In code, queues process tasks in the order they arrive. Job queues, message queues, print queues — they are all FIFO structures.
Real Talk
A queue is a FIFO (First In, First Out) abstract data structure supporting enqueue (add to back) and dequeue (remove from front) operations. Queues are fundamental to task scheduling, message brokers (RabbitMQ, Kafka), BFS graph traversal, and async job processing. Priority queues (heap-based) serve highest-priority items first instead of arrival order.
Show Me The Code
// Array-based queue in JavaScript:
const queue = [];
queue.push('task1'); // enqueue — add to back
queue.push('task2');
queue.push('task3');
const next = queue.shift(); // dequeue — remove from front
console.log(next); // 'task1' (FIFO)
// Real-world: job queue
async function processQueue() {
while (queue.length > 0) {
const job = queue.shift();
await processJob(job);
}
}
When You'll Hear This
"Add it to the job queue and the worker will pick it up." / "Message queues decouple producers from consumers."
Related Terms
Async
Async means 'don't wait around'. You order food at a restaurant, then chat with friends instead of standing at the kitchen window staring.
Data Structure
A data structure is a way of organizing information in your code so it is easy to use and fast to access.
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.
Stack
A stack is a pile of things where you can only add to the top and take from the top — like a stack of plates.