cd /news/ai-infrastructure/day-22-of-60-i-built-a-production-ba… · home topics ai-infrastructure article
[ARTICLE · art-17490] src=dev.to pub= topic=ai-infrastructure verified=true sentiment=↑ positive

Day 22 of 60: I Built a Production Background Task Pipeline That Processes AI Jobs Asynchronously

A developer built a production background task pipeline using FastAPI and PostgreSQL that processes AI document jobs asynchronously, returning a job ID in milliseconds while Claude handles summarization, data extraction, and evaluation tasks in the background. The pipeline supports three task types—summarize, extract, and evaluate—with full audit trails stored as JSONB in PostgreSQL, and optional webhook support eliminates the need for client polling. The system is designed for real-world use cases including contract review, loan application screening, and insurance claims processing.

read2 min publishedMay 29, 2026

** The Problem**

Processing large documents through an AI model takes 30-60 seconds. A synchronous API makes the client wait the entire time. Browsers timeout. Users think it crashed. The experience feels broken.

Yesterday I learned why this happens. Today I built the fix.

## What I Built

A document processing pipeline with FastAPI and PostgreSQL that handles long-running AI tasks in the background. Three task types. Immediate response. Full audit trail.

Client submits a document and gets a job ID in milliseconds. Claude processes it in the background. Client polls for the result when ready. Everything logged to PostgreSQL.

## Three Task Types

Summarise: submit a document and receive a structured summary with executive overview and key points. Focus area is configurable.

Extract: specify which fields you want pulled out. Company name, net profit, revenue, key risks. Claude reads the document and returns exactly what you asked for as structured JSON.

Evaluate: provide a list of criteria and Claude checks whether the document meets each one. Returns a pass or fail with reasoning for every criterion.

**## How the Pipeline Works **

POST /jobs/summarise
↓
Job ID returned in milliseconds
status: pending
↓
Claude processes in background
status: running
↓
GET /jobs/{job_id}
status: completed
full result ready

Optional webhook support means the server can call your endpoint when the job completes and no polling needed.

## The Database Behind It

Every job is stored in PostgreSQL with full audit trail:

Job ID, status at every stage, task type, input data as JSONB, result as JSONB, error message if failed, webhook URL, created timestamp, completed timestamp.

If a job fails the error is recorded for debugging. Nothing disappears silently.

## Real Use Cases

Contract review for law firms. Loan application screening for SACCOs. Insurance claims processing. Report summarisation for enterprises.

The same pipeline. Different documents. Different criteria. One system.

## What I Learned

FastAPI's BackgroundTasks is the simplest way to separate submission from processing. The endpoint returns immediately. The heavy work happens after the response is sent.

JSONB in PostgreSQL stores the full input and result as structured data — not a string you have to parse later. Query it, index it, use it.

Webhooks flip the polling model entirely. Instead of the client asking if the job is done, the server tells the client when it is ready.

🔗 Full project on GitHub → https://github.com/mbuguacessy-glitch

38 more to go.

── more in #ai-infrastructure 4 stories · sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/day-22-of-60-i-built…] indexed:0 read:2min 2026-05-29 ·