A task’s journey.
Every moving part.

From a Python function to a fleet of workers. Here’s how TaskFlow moves the work, tracks its state, and responds when things change.

A look inside the system

The system, connected

Task flow Scaling signal
namespace: taskflow
Ready for the next burst160 task burst · timing compressed
Queued
0
Workers
2
Completed
0 / 160
Select a component to explore its role.Conceptual map · not live telemetry

Swipe the map to explore →

ENTRY POINT

FastAPI

Authenticates requests, accepts Python file uploads, and persists submitted tasks in PostgreSQL. Dispatch is handled by the queue manager.

Read the source ↗

A function goes in.
The system takes it from there.

Walk through the normal execution path. Each stage has one job.

01 / Shared code, ready to run

Your code has a home.

Upload a Python file with a handler(payload) function. The API and workers share the task files volume, so workers can load new code without an image rebuild.

async def handler(payload):
    return await process(payload)
At this stageFILE READY

Each part earns
its place.

The API accepts work. The scheduler dispatches it. Workers execute it. Redis and PostgreSQL connect the pieces.

01

Request layer

FastAPI · CLI

Authentication, uploads, task creation, and status queries through a REST interface.

api/routers/tasks.py ↗
02

Coordination layer

Queue manager · Redis

A leased leader schedules due tasks into high or low priority queues and checks for work needing recovery.

core/queue_manager.py ↗
03

Execution layer

Python · AsyncIO

Workers move tasks to a processing list, load uploaded handlers, and update execution status.

worker/main.py ↗
04

Persistence layer

PostgreSQL · PgBouncer · PVC

Task metadata and status live in PostgreSQL. PgBouncer pools connections. A shared volume holds Python files.

infrastructure/postgres.yaml ↗

A queue gets deeper.
A fleet gets bigger.

KEDA observes the low priority Redis queue and adjusts the worker deployment between 2 and 20 replicas.

The current manifest polls every 2 seconds, sets a target list length of 5, and configures a 30 second cooldown. Both priority queues are served by the same worker fleet.

Explore the scaling manifest ↗
worker-scaledobject.yamlKEDA
spec:
  minReplicaCount: 2
  maxReplicaCount: 20
  pollingInterval: 2
  cooldownPeriod: 30
  triggers:
    - type: redis
      metadata:
        listName: default
        listLength: "5"

A focused excerpt from the current manifest.

Work can fail.
Make it recoverable.

Heartbeats, leader leases, and reconciliation give the system ways to detect interrupted work. Handlers should tolerate being run again.

A worker disappears

Workers publish heartbeats every 3 seconds with a 10 second TTL. The queue manager scans running tasks every 10 seconds and requeues tasks whose worker heartbeat is missing, up to 3 retries.

Inspect heartbeat handling ↗
The queue manager loses leadership

Leadership uses a Redis lease with a 10 second TTL, renewed every 3 seconds. A contender can acquire the lock after the lease expires; the Kubernetes manifest currently runs one queue manager replica.

The queue and database disagree

A reconciliation loop republishes queued tasks every 30 seconds. This can produce duplicate delivery, so task handlers should be idempotent. A separate loop inspects stale entries in the low priority processing list.

A Python handler raises an error

The worker marks the task FAILED and removes its message from the processing list. The dynamic handler wrapper also sets a 180 second timeout. The current worker records task status rather than persisting the handler’s return value.

Inspect handler execution ↗

Trace the path.
Then run it yourself.

The source is open. The next task is yours.

Run TaskFlow locally