What is a job queue? Explained with a kitchen ticket rail
A job queue holds slow tasks in a waiting line so the app can reply at once and workers can do the work in the background. Explained with the ticket rail in a restaurant kitchen.
- Author
Umair Mateen- Published
- Reading time
- 5 min
- Category
- Engineering
In one sentence: A job queue is a waiting line for slow tasks: the app writes each task down, tells you straight away that it is in hand, and separate workers pick the tasks up one by one in the background.
The everyday picture
Picture a busy restaurant. A waiter takes your order, but does not walk into the kitchen and cook it. That would leave every other table waiting. Instead, the waiter writes a ticket and clips it to the ticket rail above the kitchen counter. Then the waiter comes back and says, "Your order is in."
The cooks take the next ticket from the rail whenever they are free. If ten orders arrive at once, the rail just gets longer, and the cooks work through it at a steady pace.
Software has the same problem. Some tasks are slow, like building a big report, resizing photos or sending hundreds of emails. A job queue is the ticket rail. The work it holds is called a background job, because it happens away from the screen you are looking at.
The app writes the slow task on a ticket, clips it to the rail (the queue) and replies at once. A free worker takes the next ticket, does the work, and only then takes it off the rail.
How it works, step by step
- You ask the app for something slow (you order a dish). For example, you click "Export last year's sales".
- The app adds a job to the queue (the waiter clips a ticket to the rail). The job is a short message that says what to do, such as "build the sales report for this account".
- The app replies straight away (the waiter says "your order is in"). You see "We are preparing your report" and can carry on. The app is free to serve the next person.
- A worker takes the next job (a free cook takes the next ticket). The worker is a separate program. Many queue services hide the job from other workers while it is being done, so two cooks do not grab the same ticket.
- The worker finishes and removes the job (the dish goes to the pass and the ticket comes off the rail). The worker saves the result, for example the finished report, and only then deletes the job from the queue. If the worker crashes before that, the job becomes available again, and another worker can pick it up.
Try it · Put it in order
Put the ticket's journey in the right order
Tap the steps in the order they happen.
Where the picture stops
- A ticket can be cooked twice. Most queue services deliver each job "at least once". Microsoft's guidance says a worker can receive the same job more than once, so each job must be safe to repeat.
- The rail is not always in strict order. A kitchen rail runs left to right. Many software queues do not promise to hand out jobs in the order they arrived. When order matters, some services add features for it, such as message sessions in Azure Service Bus.
- A problem ticket goes to a separate rail. If one job fails again and again, it is moved to a "dead-letter queue" so it does not block the rest. A person then looks at it.
Why it matters for your business
- Faster screens for customers. Slow work moves off the page people are using. Microsoft notes this reduces the load on the app and shortens the time people wait for a response.
- Calm during rush hour. A queue soaks up sudden spikes, like a sale or a month-end deadline. Microsoft's Queue-Based Load Leveling guidance says delays in the workers then do not directly affect the app.
- Lower running cost. The same guidance says you only need enough workers for your average load, not your busiest moment.
- Risk you must manage. Because a job can run twice, a careless setup can send two emails or charge a card twice. A well-built worker checks whether a job was already done before doing it again.
An example
Imagine a small online furniture shop. After each order, its website creates a PDF invoice, emails it, and updates the stock list. At first the customer waits on the checkout page while all of this happens, and busy days make it slow.
The shop's developer adds a job queue. Now checkout just adds one job, "process order 1042", and shows "Thank you, your order is confirmed". A worker picks up the job a moment later and does the slow steps. During a sale, jobs pile up briefly, but checkout stays quick. If the email service is down, the job fails and is tried again later. If it keeps failing, it lands in the dead-letter queue for someone to check.
Frequently asked questions
What is the difference between a job queue and a background job?
The background job is the work itself, done away from the user's screen. The job queue is the waiting line that holds those jobs until a worker is free.
When should I not use a job queue?
When the person needs the answer right now, like checking a password at login. Microsoft's guidance says the pattern does not suit tasks that need an instant reply.
What happens if a worker crashes halfway through a job?
The job was never deleted, so it becomes available again and another worker can take it. Jobs that keep failing are usually moved to a dead-letter queue.
Is a job queue the same as batch processing?
No. A job queue hands out jobs as they arrive, to whichever worker is free. Batch processing gathers many items and runs them together, often on a schedule. Many systems use both.
Related explainers
- What is a webhook? Explained with a doorbell
- What is scaling? Explained with checkout lanes at rush hour
- What is rate limiting? Explained with a doorman and a tally book
- What is batch processing in AI? Explained with a print shop's drop-off tray
The DevDrift builds web platforms with background jobs, retries and checks built in: see how.
Sources
Could you explain this to a colleague now?
Mark it and posts that mention it will show a tick. Saved in this browser only.