A Small Queue Simulation
An example post with prose, code, a table, and an image.
This is the kind of post I want the site to support: a short explanation, a little code, and a small result that makes the idea easier to see.
The example is a queue where more work arrives than the system can process. Nothing dramatic happens at first. The queue just grows by one item per step, which is exactly the kind of slow signal that is easy to miss in production.
const queue = [];
const arrivalRate = 3;
const serviceRate = 2;
for (let time = 0; time < 10; time++) {
queue.push(...Array(arrivalRate).fill("request"));
queue.splice(0, serviceRate);
console.log({ time, queued: queue.length });
}
| Time | Arrivals | Processed | Queue Length |
|---|---|---|---|
| 0 | 3 | 2 | 1 |
| 1 | 3 | 2 | 2 |
| 2 | 3 | 2 | 3 |
| 3 | 3 | 2 | 4 |
| 4 | 3 | 2 | 5 |
The point is not the simulation itself. The point is that a tiny model can make the shape of a production problem more concrete before the real system is under pressure.