Running it end to end

You have a queue, a worker, and a placeOrder service that plays nicely with Redis outages. Time to run the whole thing end to end and watch an order flow from the API into the queue and out through the worker.

Open two terminals. In one, start the API with npm run start:before. In the other, start the worker with npm run start:worker. You should see the API listen on port 3000 and the worker log that it is watching OrderConfirmations.

terminal
bash
# Login to get a token
TOKEN=$(curl -s -X POST http://localhost:3000/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"password123"}' | jq -r .token)

# Place an order
curl -X POST http://localhost:3000/api/orders \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"bookId":1,"quantity":2}'

# Poll the status
curl http://localhost:3000/api/orders/1

Log in, grab a token, place an order, poll the order status until it flips to completed.

Watch the worker terminal. You should see a log line the moment the job arrives, a three-second pause while the simulated heavy work runs, and a completed log line at the end. Poll the order endpoint and the status flips from pending to completed. This is what every production order system looks like underneath the branding.

Validation checklist: Run the background job pipeline yourself

Loading practice…

Checkpoint: Background jobs checkpoint

Loading practice…