Q&A-1Design and defend a workflow mechanism for workflow graph.
Answer
Assumptions I'd state first: a batch pipeline, 10³–10⁵ tasks, artifacts are files on shared storage, tasks are idempotent, one cluster. If any of those is false the design changes: I flag where at the end.
Core answer. Build the workflow as an explicit DAG in which every task declares its inputs and outputs as content-addressed artifacts. The engine topologically sorts the DAG, runs every task whose inputs exist and whose cache key is absent, and records the key on completion. The dependency edge, not submission order, is the source of truth, so a change recomputes exactly the affected subgraph and nothing else. Snakemake, Nextflow and Argo all implement this shape; for file-based scientific pipelines I'd pick Snakemake because caching and restart come free.
Mechanism.
- Parse rules; instantiate wildcards into concrete jobs.
- Build the DAG: nodes are jobs, an edge runs producer→consumer when one job's output path equals another's input path. Kahn's algorithm gives the order in O(V+E); nodes left with in-degree > 0 are a cycle, and the error names the path.
- Schedule: ready set = in-degree 0, bounded by cores and memory. Each job runs in a container with only its declared inputs mounted read-only.
- Cache: key = SHA-256(input hashes ‖ command ‖ tool version ‖ params). Match → skip.
rule align: # Snakemake 8.x
input: "trimmed/{sample}.fastq"
output: "aln/{sample}.bam"
threads: 8
shell: "bwa mem -t {threads} ref.fa {input} | samtools sort -o {output}"Trace. Jobs: A trim (raw.fastq 2.1 GB → trimmed.fastq), B align, C call, D qc. Edges A→B, A→D, B→C. In-degrees A0 B1 C1 D1 → run A (4 min). Then B and D are ready and run in parallel. Then C. Change a param in C: only C's key changes, only C reruns. Change raw.fastq: A's hash changes, all four rerun. Hashing 2.1 GB at ~1.5 GB/s costs ~1.4 s: cheap next to a 4-minute trim.
Failure modes and how I'd catch them.
| failure | symptom | detection |
|---|---|---|
| hidden dependency | passes on the dev box, fails on a clean node; stale cache | container mounts only declared inputs; strace -f -e trace=openat |
| wildcard ambiguity | job count ≠ expected | --dry-run prints the job DAG; assert the count |
| fan-out identity loss | two samples write one path | engine errors on two producers for one artifact |
| cycle | DAG build errors | Kahn leftover nodes; report the cycle path |
| order relied on without an edge | results change when submission order is shuffled | shuffle order in a test run |
Trade-offs. Make-style timestamp dependencies are cheaper but lie across NFS and clock skew, and miss command changes; content hashing costs a hash of every input but is correct. Airflow's central scheduler DB suits long-running, time-triggered, heterogeneous workflows; at 10⁵ short tasks that DB is the bottleneck, which is why Snakemake and Nextflow keep the DAG in the driver process. Nextflow's dataflow channels pass values in memory: good for streaming, but you lose free caching and restartability that file-based rules give you.
When not to use this. Long-lived services with human-in-the-loop steps, or tasks that are not idempotent. A DAG engine will happily re-run a task that charged a credit card. Use a durable-execution engine such as Temporal with explicit compensation instead.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.