PyTaskFlow is a distributed task scheduling and execution system built using Python , FastAPI, gRPC, PostgreSQL, React, and Docker.
It enables reliable scheduling, asynchronous execution, automatic retries, worker health monitoring, and real-time observability.
The system uses gRPC for internal coordination, and is deployed using Docker in a production-style cloud setup.
Demo Video: Click here to watch the demo
- Distributed task scheduling and execution
- Time-based (future) task scheduling
- Asynchronous task execution
- Full task lifecycle tracking
- Automatic retries with exponential backoff
- Worker heartbeat and liveness detection
- Real-time monitoring dashboard
- Structured, color-coded logging
- Fully Dockerized microservices
- Cloud-deployable on AWS
In real-world systems, background jobs must be:
- Scheduled reliably
- Executed asynchronously
- Retried on failure
- Recoverable after restarts
- Scalable across multiple workers
- Observable in real time
PyTaskFlow addresses these challenges by separating responsibilities into well-defined services that communicate using REST and gRPC, while persisting system state in a durable PostgreSQL database.
User ↓ React Dashboard ↓ (REST / SSE) Scheduler (FastAPI) ↓ (Durable State) PostgreSQL ↓ (Periodic Querying) Coordinator ↓ (gRPC) Worker(s) ↑ (Heartbeat) Coordinator
- Separation of concerns
- Microservice-style architecture
- Control plane vs execution plane separation
- Async and non-blocking I/O
- Fault isolation and observability
- Python 3.12
- FastAPI (REST API)
- SQLAlchemy (Async ORM)
- PostgreSQL
- gRPC with Protocol Buffers
- asyncio
- React
- Vite
- Tailwind CSS
- Server-Sent Events (SSE)
- Docker
- Docker Compose
- Nginx
- AWS EC2
- Let’s Encrypt SSL (Certbot)
- DuckDNS
- structlog
- colorlog
- Health check endpoints
- Metrics endpoints (JSON and Prometheus-style)
- Accepts task submissions
- Validates input using Pydantic
- Persists tasks in PostgreSQL
- Exposes REST APIs for dashboard consumption
- Provides health and metrics endpoints
- Streams real-time updates via SSE
- Periodically queries the database for due tasks
- Dispatches tasks to workers via gRPC
- Tracks worker heartbeats
- Detects dead workers
- Handles retries with exponential backoff
- Executes task commands asynchronously
- Limits concurrency using semaphores
- Reports execution results
- Sends periodic heartbeats
- Schedule new tasks
- View task history
- Monitor worker health
- Observe live system metrics
- Full task lifecycle tracking
- created → scheduled → picked → running → completed / failed
- Execution timestamps
- Retry count and retry scheduling
- Worker identity
- Last heartbeat timestamp
- Alive / dead status
- Internal service communication via gRPC
- Strongly-typed contracts using Protocol Buffers
- Single source of truth:
task.proto
- Structured, service-specific logging
- Color-coded log levels
- Health check endpoints
- Metrics APIs
- Real-time worker monitoring via SSE
- AWS EC2
- Dockerized services:
- Scheduler
- Coordinator
- Worker(s)
- PostgreSQL
- Docker Compose for orchestration
- Nginx as reverse proxy and HTTPS termination