jiayaoqijia/cryptoskill/0xklen-add-backpressure-to-a-queue-worker

Claude Code and agent skill by jiayaoqijia/cryptoskill

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when a consumer falls behind and the queue grows without bound — bounds in-flight work, handles visibility timeouts and dead-letters poison messages instead of losing them.

Install

npx vskill@latest install jiayaoqijia/cryptoskill/0xklen-add-backpressure-to-a-queue-worker

SKILL.md

The same SKILL.md was published earlier as jiayaoqijia/cryptoskill/0xklen-add-backpressure-to-a-queue-worker.

Add backpressure to a queue worker

A consumer that accepts work faster than it can process it is no consumer at all: the queue grows, memory grows, and the oldest messages expire unprocessed. Slow the intake to match the processing rate.

Procedure

  1. Measure the steady-state drain rate before tuning: processed-per-second and queue depth over an hour. Depth growing linearly at constant input means the worker is under-provisioned or blocked.
  1. Bound the in-flight work: RabbitMQ basic_qos(prefetch_count=2*concurrency), Kafka max.poll.records=500, SQS a fixed MaxNumberOfMessages with a fixed poller count. Unbounded prefetch pulls the whole queue into memory.
  1. Make processing idempotent so a redelivery (visibility timeout, rebalance) cannot double-apply:

if redis.set(f"done:{msg.id}", 1, nx=True, ex=86400) is None: ack(); return

  1. Set the visibility timeout above the p99 processing time, not the mean, and dead-letter after a bound:

maxReceiveCount = 5 → DLQ A message that times out mid-processing is redelivered; with a slow handler it is redelivered forever unless it reaches the DLQ.

  1. Apply backpressure to producers by exposing consumer lag and pausing intake when a downstream is slow: basic_cancel or consumer.pause(). The broker retains messages; dropping them is not backpressure.
  1. For Kafka, watch lag per partition. One hot partition with lag while others idle indicates a bad partition key — re-key or add partitions.
  1. Auto-scale on queue depth, not CPU: I/O-blocked workers show low CPU while lag grows. Scale when queue_depth / drain_rate > 60s.

Pitfalls

  • Unbounded prefetch_count, so one worker holds 100k messages in memory, crashes, and drops them all back onto the queue at once.
  • A visibility timeout shorter than the slowest handler, so messages loop forever and never reach the DLQ because each attempt looks like it is still running.
  • Non-idempotent side effects (charge, email) applied on every redelivery.
  • Scaling on CPU for an I/O-bound worker, so the autoscaler never fires during the actual backlog.

Verification

aws sqs get-queue-attributes --queue-url $Q --attribute-names ApproximateNumberOfMessages awk '/processed/{p++} END{print p}' worker.log # drain rate vs input rate # steady state: depth flat, NotVisible == prefetch * workers

Report: prefetch/poll settings, the measured drain rate against the input rate, a steady-state depth that is flat rather than growing, and the DLQ redrive policy (maxReceiveCount=5).

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/jiayaoqijia/cryptoskill/0xklen-add-backpressure-to-a-queue-worker/badge)](https://verified-skill.com/skills/jiayaoqijia/cryptoskill/0xklen-add-backpressure-to-a-queue-worker)

Something wrong with this skill or its page? Tell us.