Prompt
I'm building ETL jobs that run in the background, what architecture makes sense?
Latest observation
For background ETL jobs, the architecture that usually makes the most sense is a queue + worker + durable state setup, with a scheduler on top if jobs are periodic.
Recommended architecture
1. Job ingestion layer
A small API or internal service that:
- accepts ETL job requests
- validates parameters
- creates a job record in a database
- enqueues work for workers
2. Durable job state store
Use a relational DB or similar durable store to track:
- job id
- status:
queued,running,succeeded,failed,retrying - timestamps
- inputs/parameters
- progress/checkpoints
- error details
- output metadata
This is important so jobs are observable and recoverable even if workers die.
3. Queue / message broker
Put jobs onto a queue such as:
- SQS
- RabbitMQ
- Kafka
- Redis Queue
- Celery broker, etc.
The queue decouples job submission from execution and gives you:
- buffering
- retry handling
- backpressure
- horizontal scaling
4. Worker fleet
Run stateless worker processes/containers that:
- pull jobs from the queue
- execute ETL steps
- write progress back to the job store
- retry transient failures
- emit logs/metrics
Workers should be designed to be:
- idempotent where possible
- able to resume from checkpoints
- safe to run multiple times without duplicating outputs
5. Scheduler / orchestrator
If jobs run on schedules or have multi-step dependencies, use an orchestrator such as:
- Airflow
- Prefect
- Dagster
- Temporal
- AWS Step Functions
This layer is especially useful when ETL includes:
- ordered task chains
- branching logic
- retries per step
- SLAs
- dependencies between jobs
A good baseline design
If you want a practical default:
- API/service submits jobs
- Postgres stores job metadata and state
- SQS/RabbitMQ queues work
- Kubernetes/ECS/VM workers run jobs
- Airflow/Temporal if workflows become complex
Key design principles
Idempotency
ETL jobs often get retried. Make sure rerunning a job does not corrupt data or create duplicates.
Checkpointing
For long-running ETL:
- store checkpoints after each stage
- process data in chunks
- resume from last successful chunk after failure
Separate compute from orchestration
Don’t embed all business logic in the API server. Keep:
- orchestration in scheduler/worker layer
- execution in workers
Observability
You’ll want:
- structured logs
- metrics on runtime, failures, queue depth
- traces if the pipeline is distributed
- dead-letter queue for poison messages
Backpressure and concurrency control
Limit:
- number of jobs per tenant
- number of concurrent jobs
- max memory/CPU per worker
- per-source rate limits
When to use what
Simple ETL jobs, low volume
Use:
- queue + workers + DB tracking
Scheduled or multi-step ETL
Use:
- Airflow/Prefect/Dagster
Highly reliable distributed workflows with stateful retries
Use:
- Temporal or Step Functions
Very high throughput event processing
Use:
- Kafka + stream processors + separate job state store
Common anti-patterns to avoid
- running ETL inside web requests
- using only cron with no job state tracking
- relying on in-memory job status
- not handling retries/idempotency
- mixing orchestration logic and data transformation code
- letting workers directly coordinate with each other without a central state model
A simple reference architecture
Client / Cron / API
|
v
Job Service
|
v
Job DB + Queue
|
v
Worker Pods
|
v
Data Sources / Transformations / Destinations
|
v
Job DB updates + Logs + Metrics
If you want, I can also sketch:
- a minimal production-ready architecture,
- a Kubernetes-based version, or
- a cloud-specific design for AWS/GCP/Azure.