All articles

Splitting Audio Transcription and Summaries into Reliable Async Jobs

Separating audio pipelines into independent async stages, clarifying RabbitMQ confirms, consumer acks, and DLX semantics, and guarding versioned AI outputs and cache invalidation.

  • Async jobs
  • RabbitMQ
  • AI engineering

Why Upload, Transcription, and Summaries Should Not Share One Job

On the AI smartwatch project, I worked on file management and access APIs, scheduled transcription and mind-map jobs with RabbitMQ, integrated speech transcription, AI summaries, and mind maps, and used Redis to cache file lists and AI outputs. Audio post-processing combines stages with distinct runtime profiles: uploads depend on device connectivity, transcription is compute-heavy, and summary or mind-map generation depends on upstream model rate limits and timeouts. The following is an illustrative design grounded in that background rather than an exact blueprint of a shipped backend.

Consider a hypothetical scenario. A watch finishes syncing a 30-minute meeting recording. If one synchronous request or monolithic worker job stores the audio, transcribes it, creates a summary, and generates a mind map together, a brief model timeout at the last step either fails the whole request or forces expensive transcription work to rerun. Splitting the pipeline into discrete async stages lets each stage scale, time out, and retry independently while letting users inspect the transcript as soon as it finishes.

Clarifying Publisher Confirms, Consumer Acknowledgements, and DLX

In RabbitMQ, confirmations operate across two independent hops. Per the official documentation, Publisher Confirms sit between producer and broker: they confirm broker handling and—when messages route to durable queues with persistence configured—queue acceptance/persistence semantics. Crucially, a publisher confirm does not prove a message routed to a queue; unroutable messages can still be positively confirmed. When silent drops are unacceptable, pair confirms with the mandatory flag and basic.return (or explicit unroutable handling / an alternate exchange) plus proper queue and message durability settings.

Consumer Acknowledgements operate independently between broker and worker: with manual acks, a queue removes a message only after basic.ack. On failure, blindly calling basic.nack(requeue=true) pushes poison messages straight back to the queue head. Separating transient faults from terminal errors requires bounded retries—using a configured retry-queue/TTL arrangement or an application scheduler for delay—and a Dead Letter Exchange (DLX) to route rejected (requeue=false), expired, or retry-exhausted messages. A DLX is routing rather than a delay scheduler on its own, and DLX forwarding is not lossless by default unless dead-letter bindings and persistence are configured deliberately.

Mechanism Scope Semantic boundary Common misconception
Publisher Confirms Producer -> Broker Confirms broker handling/persistence; use mandatory/basic.return for unroutable messages Treating a confirm as proof of queue routing and completed consumption
Consumer Acknowledgements Broker -> Worker Independent of confirms; controls when the queue deletes a message Using auto-ack (losing in-flight work) or infinite requeue=true loops
Dead Letter Exchange (DLX) Queue -> Dead-letter route Routes dead-lettered messages; delay requires retry-queue/TTL or scheduler with finite retries Treating DLX as a built-in delay scheduler or lossless by default

Versioned Result Identity, Atomic Stage Chaining, and Cache Windows

Retries and user-triggered regenerations naturally create races. Suppose a slow version=1 summary job finishes after a user’s regenerated version=2 job already committed. Without explicit state checks, the stale job can overwrite newer results.

In this illustrative design, each artifact is identified by (fileId, stage, inputHash, version). Workers first check whether the artifact is already complete or superseded so redundant AI calls are skipped whenever possible. On completion, a single transaction verifies job.version == current_requested_version and that (fileId, stage, inputHash, version) is not already completed—and writes any downstream stage intent to an outbox table inside the same transaction so a crash between commit and broker publish does not stall the pipeline:

// Pseudocode: skip completed work, guard completion against stale versions, record downstream outbox atomically
function onStageJob(job):
  if job.attempt > MAX_ATTEMPTS:
    markJobFailed(job.fileId, job.stage, job.version)
    return NACK_TO_DLX

  if db.isArtifactCompleted(job.fileId, job.stage, job.inputHash, job.version):
    return ACK // Already complete; skip redundant AI generation

  if db.getRequestedVersion(job.fileId, job.stage) != job.version:
    return ACK // Superseded by a newer requested version

  artifact = runAiStage(job)

  db.beginTransaction()
  try:
    currentVersion = db.lockAndGetRequestedVersion(job.fileId, job.stage)
    alreadyDone = db.isArtifactCompleted(job.fileId, job.stage, job.inputHash, job.version)

    if currentVersion == job.version and (not alreadyDone):
      db.insertCompletedArtifact(job.fileId, job.stage, job.inputHash, job.version, artifact)
      if job.stage == "TRANSCRIBE":
        db.insertOutboxJob(fileId = job.fileId, stage = "SUMMARY", inputHash = hash(artifact))
      db.commit()
      invalidateCacheWithRetry(cacheKey(job.fileId, job.stage))
    else:
      db.rollback()
    return ACK
  catch err:
    db.rollback()
    throw err

Database commit and Redis invalidation are not atomic: a failure or concurrent cache fill between commit and DEL leaves a bounded stale window. Pairing retryable invalidation with a finite Redis TTL keeps that window bounded rather than pretending cache consistency is instantaneous.

Tradeoffs and Verification

Stage tables, transactional outbox records, and bounded retry topology add coordination overhead and require carrying fileId and traceId headers across queues. Even so, those guardrails prevent silent pipeline stalls and stale overwrites.

Three targeted tests exercise the critical failure paths:

  • Unroutable publish and crash before ack: publish with mandatory to an unbound key to verify basic.return triggers; kill a worker after DB commit and before basic.ack to confirm redelivery hits the early completion check and skips regeneration.
  • Bounded retries to DLX: inject a corrupted recording and confirm it routes to a bound dead-letter queue via requeue=false after exhausting its finite retry limit without blocking healthy jobs.
  • Version race: force version=1 to return after version=2 commits and confirm the completion guard rejects the stale write while cache invalidation and TTL converge on version=2.

References