Guides / Monitoring

Monitor Queue Depth and Backlogs

4 min read·Monitoring

Why Queue Depth Matters

A queue backlog is usually a leading indicator of a bigger problem: a worker crashed, a downstream service is slow, or a deploy introduced a bug that causes jobs to fail and retry. Logging depth metrics lets you catch this before users see delays.

Step 1: Log Queue Depth on a Schedule

ts
// jobs/queue-depth-check.ts (runs every 5 minutes via cron)
import { logit } from "@/lib/logit";
import { Queue } from "bullmq";

const emailQueue = new Queue("email-jobs", { connection: redisClient });

export async function checkQueueDepths() {
  const waiting = await emailQueue.getWaitingCount();
  const active = await emailQueue.getActiveCount();

  await logit.now("queue-health", {
    event: "Queue depth check",
    description: `email-jobs: ${waiting} waiting, ${active} active`,
    icon: waiting > 100 ? "🔴" : waiting > 20 ? "🟡" : "🟢",
    notify: false,
    tags: {
      queue: "email-jobs",
      severity: waiting > 100 ? "high" : waiting > 20 ? "medium" : "low",
    },
    metadata: {
      queue: "email-jobs",
      waiting,
      active,
      checkedAt: new Date().toISOString(),
    },
  });
}

Step 2: Alert on Sustained Backlog

The depth check runs every 5 minutes. If the queue stays backed up, you'll see consecutive "high" severity events. Smart Actions detects the pattern:

FieldValue
NameEmail queue backlog
Channelqueue-health
Event nameQueue depth check
Threshold3
Window15 minutes
Cooldown30 minutes
ActionPush notification

Step 3: Log Worker Failures Separately

ts
emailQueue.on("failed", async (job, err) => {
  await logit.now("queue-failures", {
    event: "Job failed",
    description: `[${job?.name}] ${err.message}`,
    icon: "❌",
    notify: false,
    tags: { queue: "email-jobs", jobName: job?.name ?? "unknown" },
    metadata: { jobId: job?.id, error: err.message, attempts: job?.attemptsMade },
  });
});

Tips

  • Log to queue-health every 5 minutes for depth snapshots, and queue-failures on every failure — different channels, different signal types.
  • Use the severity tag to filter in the dashboard for only "high" events.
  • A Smart Action on queue-failures with threshold 10/5min catches worker crashes early.

Try LogIt free

7-day trial. No credit card required.

Start free