Skip to content

Interview Completion → SQS → Settlement + Report Enqueue

Bot marks the interview complete or failed; async settlement finalizes credits and enqueues report generation once.

Sequence

sequenceDiagram
  autonumber
  participant Bot as Interview bot
  participant API as Hono API
  participant BotSvc as bot-interview.service
  participant SQS1 as SQS interview-completed
  participant Lambda as interview-completed handler
  participant Settle as settlement.service
  participant Credits as credit.service
  participant SQS2 as SQS report-generate
  participant Mongo as MongoDB

  Bot->>API: POST /v1/bot/interviews/:id/complete
  BotSvc->>Mongo: status COMPLETED + timing
  BotSvc->>SQS1: publishInterviewCompleted

  SQS1->>Lambda: message
  Lambda->>Settle: settleCompletedInterview
  Settle->>Mongo: claim settledAt (idempotent)
  Settle->>Credits: settleCreditsInSession
  Settle->>SQS2: publishReportGenerate (first claim only)

Steps

  1. Bot posts complete (or fail) with timing; API updates terminal status and publishes to SQS.
  2. Lambda consumes the message and runs settlement for completed or failed interviews.
  3. Settlement claims settledAt once—duplicate deliveries skip without double-charging or double enqueue.
  4. Completed path bills consumed minutes, releases unused reservation, and enqueues report generation on first claim only.
  5. Failed path releases the full reservation with zero consumption.

Sophia AI Interview Platform — Internal Documentation