Skip to content

title: Architecture description: The problems qaechi solves and how: evidence for every value, structured and unstructured documents in one engine, a queue and worker pool for volume, and an outbox for business transactions.


Architecture

The problem: values you cannot check

Most extraction tools, and most LLM prompts, return a number or a name with nothing to show where it came from. Someone has to open the document to check it, or nobody does and a wrong value flows into an invoice, a contract system or a RAG answer.

Evidence first

qaechi-parser returns every value with the exact quote and page it was read from, and checks that the quote really is in the document. A value it cannot support comes back empty, not guessed.

flowchart LR
  doc["Document<br/>(PDF, PPTX, XLSX, CSV)"] --> ex["Extract"]
  ex --> v["value: 1,225,000<br/>page: 3<br/>quote: 'Total 1,225,000'"]
  v --> chk{"Is the quote<br/>in the document?"}
  chk -- "yes" --> ok["verified"]
  chk -- "no" --> bad["flagged, not trusted"]

Your application decides what to accept: verified values can flow straight through, the rest go to a person.

Any document, one result

Fixed forms and free-form documents go into the same engine and come back in the same shape: every value with its quote and page, checked against the source.

flowchart LR
  in["Structured or<br/>unstructured document"] --> x["qaechi-parser<br/>extracts"]
  x --> g["Evidence check"] --> r["Result with evidence"]

The problem with volume

One process parses one document at a time, and a request that waits minutes for an answer ties up the caller. When documents arrive from many systems all day, you need to accept work instantly and spread it over many workers, without losing or repeating any of it.

A queue and a pool of workers

In queue mode the API only accepts the job and publishes it to Kafka. Worker processes take jobs in parallel; you add replicas to go faster.

sequenceDiagram
  participant App as Your app
  participant API as parser API
  participant K as Kafka
  participant W as Worker
  participant DB as Job store
  App->>API: POST /jobs
  API->>DB: job queued
  API->>K: job message
  API-->>App: 202 jobId
  K->>W: deliver
  W->>DB: claim (once)
  W->>W: parse with evidence
  W->>DB: result saved
  W->>K: result event
  W->>K: commit offset

What makes it safe:

  • Claim once. A worker atomically claims the job before parsing, so a message delivered twice is skipped.
  • Commit after saving. If a worker dies mid-job, Kafka delivers the job again; after a few tries it is marked failed instead of looping.
  • Dead-letter topic. A message nobody can read is set aside with the reason, not retried forever.
  • One trace. The W3C traceparent travels in the message, so one trace shows the request, the queue and every pipeline step.

Getting results into your systems

Polling for results does not scale either. Every finished job is published as a result event, and qaechi-sink turns events into rows in the database you already run: PostgreSQL (Supabase too), MySQL or MongoDB, or calls your webhook.

flowchart LR
  r[("result events")] --> s["qaechi-sink"]
  s -- "GET /results/{id}" --> p["parser API"]
  s -- "upsert" --> db[("your tables:<br/>extractions,<br/>extraction_values")]
  r --> other["any other subscriber:<br/>search index, notifications"]

Writes are upserts, so a redelivered event changes nothing. Failed writes are retried and then set aside in a dead-letter topic.

The problem of the dual write

When a parse request belongs to a business change, say a new contract that must be read, the service has to save the contract and publish the request. Doing both separately means a crash in between loses one of them. A distributed transaction across the database and Kafka is not an option.

Transactional outbox and CDC

The service writes the business row and an outbox row in one local transaction. A change data capture relay reads the outbox and publishes it to Kafka. Either both happen or neither does.

sequenceDiagram
  participant S as Your service
  participant DB as Your database
  participant R as CDC relay
  participant K as Kafka
  S->>DB: BEGIN
  S->>DB: insert contract
  S->>DB: insert outbox (parse request)
  S->>DB: COMMIT
  R->>DB: read new outbox rows
  R->>K: publish job message

The outbox starter for Spring Boot and Python is part of the enterprise stage. The job message it publishes is the same contract the API uses, so workers cannot tell the difference.

Seeing it all

Every module exports OpenTelemetry metrics and traces. The bundled Grafana dashboard answers three questions: how much, how fast, and how well, meaning the share of values with verified evidence. A drop after a model or prompt change shows up at once.