Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Redis + BullMQ for AI Workloads: Retries Are Not Enough — You Also Need Idempotency and Ordering

说明与用途

文章说明在支持系统中使用 BullMQ 进行 AI 处理时,由于重试不保证幂等性和顺序,导致竞争条件和重复处理。

问题

A message can be persisted and queued for AI analysis before the HTTP response is sent, leading to race conditions, duplicate processing, and stale or overwritten results because BullMQ jobs are retried without idempotency or ordering guarantees.

结果

The article identifies that retries alone do not guarantee correct AI processing. Without idempotency and per-ticket ordering, jobs can produce inconsistent ticket data and duplicate AIInteraction records.

工作流

  • Create message in database
  • Update ticket timestamp
  • Publish BullMQ job with ticketId and messageId
  • Return HTTP 201 to client
  • Worker picks job, loads all ticket messages sorted by createdAt
  • Generate ticket summary via OpenAI (or Gemini fallback)
  • Generate sentiment via OpenAI
  • Detect priority via OpenAI
  • Update ticket with aiSummary, sentiment, priority
  • Insert AIInteraction record with prompt, response, tokensUsed

证据

The request waits for database writes and queue publication, then returns without waiting for the AI results.

来源

The worker may start before HTTP 201 is sent; the diagram shows two execution paths, not a guarantee that background processing begins after the response.

来源

Five jobs can run concurrently within this worker instance, including jobs for the same ticket.

来源

  • 记录日期: 2026-10-04T13:40:49.572Z