Skip to content

Build a tiny job queue

Deep diveBuild alongNode + RedisYou need: Build a REST API
What you’ll build: A background job queue in about 100 lines on Redis lists: producers queue jobs, workers run them, failures retry with backoff, and jobs that keep failing land in a dead-letter list. Eight steps, each proved with a command.LPUSH enqueue a jobBLMOVE take it without losing itZADD retry later, with backoffDEAD park jobs that keep failing
Step 1 of 8

Start a project next to a running Redis

Make a folder, create a package.json, and install redis, the official Node client. You also need a Redis server, version 6.2 or later, listening on localhost:6379: start one with redis-server in its own terminal, or with Docker.

If your Redis is somewhere else, set REDIS_URL (for example redis://localhost:6380) before every node command in this build.

WHY

The queue is just keys in Redis. Redis already does the hard parts: it is shared by every process, it runs one command at a time, and it can block a client until a list has something in it.

No code yet. This step runs 3 commands:
terminal
$ mkdir job-queue && cd job-queue
$ npm init -y
$ npm install redis