AlgoViz

Queue

easy 15 min

A queue is a linear data structure where items join at the rear and leave from the front.

Where it shows up

The same pattern appears across everyday software.

  • Web servers and load balancers

    Incoming HTTP requests are queued until a worker thread or process is free, so a burst of traffic waits in line instead of being dropped. When the queue fills up, servers answer 503 or 429.

  • Print spoolers

    The operating system's print spooler holds documents in a queue and sends them to the printer one at a time, in the order they were submitted.

  • Message queues

    RabbitMQ, Amazon SQS and Kafka decouple services: producers enqueue messages and consumers dequeue them at their own pace, surviving bursts and restarts.

  • Breadth-first search

    Shortest paths in unweighted graphs, level-order tree traversal, flood fill in image editors, social-network degrees of separation and web crawlers all run on a FIFO queue.

  • Task and CPU schedulers

    Operating systems run ready processes round-robin from a queue, and job runners such as Celery and Sidekiq pull background jobs in arrival order, re-queuing those that need more time.

  • Call centres and ring buffers

    Callers on hold are answered in the order they called. At the hardware level, keyboard input, audio and serial (UART) drivers use fixed-size circular buffers so no memory is allocated while data streams in.