The short answer
- Draw the queue between the service and the worker, so the wait is visible.
- Label each arrow with what happens, such as "adds a job".
- Agree now what happens when a job fails, before one does.
A finished example
This is what the Background jobs diagram template can look like once it is filled in. This one is for a shop sending order emails.
Read the example as words
- On the board
- Person: Shopper
- Web page: Shop website
- Server: Order service
- Queue: Emails to send
- Gear: Email sender
- Orders database
- Page: Emails that failed
- Questions
- The shopper sees “Order placed” straight away
- A failed email is tried 3 times
- Someone checks the failed list each morning
- How the boxes are joined
- Shopper, asks, leads to Shop website
- Shop website, places an order, leads to Order service
- Order service, adds an email, leads to Emails to send
- Emails to send, takes the next email, leads to Email sender
- Email sender, marks it sent, leads to Orders database
- Email sender, gives up after 3 tries, leads to Emails that failed
What a background job is
Some work is too slow to do while a person waits. Sending an email, making a large report and resizing a photo can each take seconds or minutes. If a website did that work before it answered, the person would stare at a spinning circle.
So the website does something else. It writes down what needs doing, answers the person straight away, and lets another part of the system do the work a moment later. The note of what needs doing is called a job. The part that does it is called a worker.
Between the two sits a queue. A queue is a waiting line for jobs. The service adds jobs at one end. The worker takes them from the other, one at a time.
This pattern is everywhere. An order confirmation email is a background job. So is a bank statement that arrives as a file, or a video that says "processing" after you upload it.
It is also where things go wrong quietly. A job can fail and nobody is told. A queue can grow faster than the worker empties it. Drawing the path makes the team answer those questions early.
The parts to draw
A background jobs diagram has six kinds of part. Use the same shape for the same kind of thing each time.
- The person who starts it, and the page or app they use.
- The service that receives the request and decides a job is needed.
- The queue where jobs wait.
- The worker that takes each job and does it.
- Where the result goes, such as a database or an inbox.
- Where failed jobs go.
Join them with arrows in the order things happen. Label each arrow with what happens, such as "asks", "sends", "adds a job", "takes the next job" and "saves the result".
Draw the queue as its own shape, never as a plain arrow. The whole point of the pattern is that work waits there. If the queue is only a line, nobody asks how long the wait is or what happens when it fills up.
Keep to one kind of job per diagram. A system may have twenty kinds. Start with the one that matters most, or the one that failed last week.
Questions the diagram should answer
Once the parts are drawn, walk one job along the arrows with the team. Stop at each shape and ask what could go wrong there.
What does the person see? They get an answer before the work is done. Decide what it says. "Order placed" is honest. "Email sent" would not be true yet.
What if the job fails? Networks drop and other services go down. Most teams try again a few times, with a longer wait between each try. Write down how many tries, and where a job goes when they run out.
What if the same job runs twice? It happens, usually after a failure halfway through. Running it twice must not charge a card twice or send two parcels. Note how the worker can tell it has done this job before.
Who finds out? A list of failed jobs that nobody reads is the same as no list. Name the person or team who checks it, and how they are told.
How long is too long? Agree what a normal wait is, and at what point somebody should be warned.
Put the answers in the Questions frame, next to the diagram they belong to.
Using the template on doodleboard
The Background jobs diagram template on doodleboard has the whole path drawn. A person uses a website. The website sends to a service. The service adds a job to a queue called Jobs waiting. A worker takes the next job and saves the result to a database. An arrow from the worker to a Failed jobs page is labelled "gives up after 3 tries".
The shapes come from the software shapes on the board. There is a person, a web page, a server and a queue. A gear stands for the worker, and a page shape holds the failed jobs. A Questions frame holds a note that asks "What if a job fails?"
Rename each shape for your own system. Double-click a shape to change its words, and double-click a connector to change its label.
To add a second worker or another queue, select Shapes in the toolbar, then select Shapes again. On the Software tab, pick one and drag it out on the board. Draw a connector to it from the part that hands it work.
When the diagram is agreed, link it from the place your team keeps its notes. The next person to ask "where do the emails come from?" can then be sent a picture.
Questions people ask
What is the difference between a queue and a database?
A database keeps records for as long as you need them. A queue holds jobs only until a worker takes them. Things pass through a queue. They stay in a database.
Do small systems need background jobs?
Often, yes. Any site that sends email or makes files benefits from doing that work after it has answered the person. One queue and one worker is enough for most small systems.
Which shapes should I use for the parts?
Any, as long as each kind of part always gets the same shape. The software shapes on doodleboard include a queue, a server, a person and a gear, which suit this diagram well.
