Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
Why is it generally better practice for a queued job's payload to contain an ID rather than a full snapshot of the relevant object?
💻 Code Challenge | +75 XP
Design a job payload for a "generateReport" job that passes only a reportRequestId, and write the worker logic that fetches the current, fresh report request details using that ID before processing.
A background job sent an invoice with outdated pricing information because the job payload contained a full snapshot of the invoice taken when it was enqueued, and the price changed before the job actually ran. Reorder the steps to fix this.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Enqueueing a job with a full snapshot of an object instead of just its identifying ID
// Wrong: worker operates on data that may be stale by execution time
await queue.add("sendInvoice", { invoice: currentInvoiceSnapshot });
// Correct: worker fetches fresh data at execution time
await queue.add("sendInvoice", { invoiceId: invoice.id });The Solution //
If the underlying object changes between when the job is enqueued and when it actually executes (which could be seconds or hours later, depending on queue backlog), a job carrying a stale snapshot will operate on outdated data. Pass just an ID, and have the job processor fetch the current, fresh state when it actually runs.
The Error //
Allowing a job that exhausts all its retries to fail silently, with no alert or record for investigation
// Wrong: permanently failed job just... disappears
// (no failed-job handler configured at all)
// Correct: surfaces the problem for investigation
worker.on("failed", async (job, err) => {
if (job.attemptsMade >= job.opts.attempts) await alertOncall(job, err);
});The Solution //
A permanently failed job represents a real, unresolved problem — a payment that was never charged, an email that was never sent — and letting it disappear without a trace means nobody is aware the underlying issue exists, let alone that it needs investigation or manual remediation.