Imagine a busy warehouse receiving shipments of electronics and fulfilling customer orders. Boxes arrive, stack up in a storage area, and a single worker picks them to ship out. Should the worker pick the oldest boxes first, ensuring fairness, or the newest ones, which are easier to reach? These choices define two fundamental queue disciplines: FIFO (First-In, First-Out) and LIFO (Last-In, First-Out). In this chapter, we’ll explore FIFO and LIFO queues using the warehouse, learning how they affect wait times and queue behavior. You’ll test the formulas and experiment with a simulator to see when each discipline shines, helping you choose the right strategy for managing queues.
A queue discipline determines the order in which items are served. In the warehouse:
The worker picks the oldest boxes first, like a line where the first arrival is served first. This ensures fairness, as no box waits too long, and suits systems prioritizing order, like customer orders or perishable goods.
The worker picks the newest boxes first, like a stack where the top (most recent) box is taken. This prioritizes recent arrivals, useful when newer items are more relevant, like error logs or accessible inventory.
We’ll model this as an M/M/1 queue with:
The queue discipline (FIFO or LIFO) changes how boxes are picked, affecting wait times and system dynamics.
The choice depends on your goals: fairness and stability (FIFO) or recency and quick access for new items (LIFO).
For an M/M/1 queue, steady-state metrics like average wait time and queue length are the same for FIFO and LIFO under identical conditions, as they depend on λ and μ, not the discipline. However, wait time distributions differ: FIFO is more consistent, while LIFO favors newer boxes, potentially leaving older ones waiting longer. Test the formulas below to see how they apply in the warehouse.
How busy the worker is, calculated as ρ = λ/μ. For λ = 5, μ = 6, ρ = 5/6 ≈ 0.83 (83% busy). ρ must be less than 1 for stability. Try it:
The average number of boxes waiting (not being processed):
For λ = 5, μ = 6, boxes. This holds for both FIFO and LIFO. Test it:
How long a box waits before processing:
With λ = 5, μ = 6, minutes (50 seconds). This is the average for both disciplines, but LIFO may have higher variance. Try it:
These formulas give average metrics, but FIFO ensures more predictable waits, while LIFO benefits newer boxes at the expense of older ones.
The M/M/1 model helps you manage the warehouse. Suppose shipments arrive at λ = 5 boxes per minute, and the worker processes at μ = 6 boxes per minute:
In FIFO, boxes wait about 50 seconds on average, with older boxes served first, ensuring fairness. In LIFO, newer boxes are processed quickly, but older ones may wait much longer if arrivals are frequent. If λ increases to 5.9, the system nears instability (ρ ≈ 0.98), and wait times spike. In LIFO, older boxes face extreme delays, while FIFO spreads the wait more evenly. You might consider adding workers (M/M/c) or limiting arrivals, but the FIFO vs. LIFO choice hinges on prioritizing fairness or recency.
The simulator below lets you explore FIFO and LIFO in the warehouse. Adjust the arrival rate (λ), service rate (μ), and queue discipline to see how they affect wait times and queue length. Try a high λ to stress the system, then switch between FIFO and LIFO to compare. Does LIFO help newer boxes at the expense of older ones? Compare the simulator’s metrics to the formula calculators to understand the tradeoffs.
FIFO and LIFO queues are essential tools for managing systems where processing order matters. In the warehouse, FIFO ensures fair handling of inventory, while LIFO prioritizes recent shipments, each fitting different needs. These disciplines extend to computing—FIFO for task queues, LIFO for stack-based operations like undo functions. By experimenting with the formulas and simulator, you’re learning to choose the right discipline for your goals, whether fairness, recency, or efficiency.