Codele / System design
Queues and background jobs
A restaurant takes your order at once and cooks in the back. A website can do the same: answer you now and do the slow work later.
- A queue is a line of jobs waiting their turn. The first job in is the first job out.
- A worker is a program that takes jobs off the queue and does them in the background.
- Put slow work (emails, resizing pictures, reports) on a queue so the user gets an answer at once.
- More workers empty the queue faster. Two workers do twice the work per tick as one.
- The trade-off: the work is not done yet when the user sees “done”, so you must handle jobs that fail later.
Loading the playable lesson…