Billy McMonagle
03/02/2026, 2:35 PMMarvin
03/02/2026, 2:35 PMMarvin
03/02/2026, 2:42 PMfrom prefect import flow, task, get_run_logger
@task
def run_local_beam_job():
import apache_beam as beam
from apache_beam.options.pipeline_options import PipelineOptions
opts = PipelineOptions(["--runner=DirectRunner"])
with beam.Pipeline(options=opts) as p:
(
p
| "Create" >> beam.Create([1, 2, 3])
| "Square" >> beam.Map(lambda x: x * x)
)
return "done"
@flow
def orchestrate():
run_local_beam_job()
if __name__ == "__main__":
orchestrate()
2) Submit a managed Beam job (e.g., to Dataflow/Flink/Spark) and let Prefect handle orchestration around it
- Inline submission in Python (Dataflow example):
```
from prefect import flow, task
@task
def submit_dataflow_job(project, region, temp_location, staging_location, job_name):
import apache_beam as beam
from apache_beam.options.pipeline_options import PipelineOptions
options = PipelineOptions([
f"--project={project}",
f"--region={region}",
f"--temp_location={temp_location}",
f"--staging_location={staging_location}",
"--runner=DataflowRunner",
f"--job_name={job_name}",
# add "--streaming" for streaming pipelines
])
with beam.Pipeline(options=options) as p:
# define your pipeline graph here
pass # e.g., p | ...
@flow
def orchestrate_beam_job():
submit_dataflow_job(
project="my-gcp-project",
region="us-central1",
temp_location="gs://my-bucket/tmp",
staging_location="gs://my-bucket/staging",Marvin
03/02/2026, 2:42 PM- Or, call an external entrypoint (Python or Java) via subprocess so your Prefect flow just kicks off the job and then polls/alerts:
from prefect import flow, task
import subprocess
@task
def run_beam_entrypoint(entrypoint_py, args):
subprocess.run(["python", entrypoint_py, *args], check=True)
@flow
def orchestrate_external_beam():
run_beam_entrypoint(
"beam_job.py",
["--runner=DataflowRunner", "--project=my-gcp-project", "--region=us-central1"]
)
```
Reference docs
- Prefect concepts and getting started: https://docs.prefect.io/latest/getting-started/
- Prefect deployments and orchestration overview: https://docs.prefect.io/
- Apache Beam programming guide: https://beam.apache.org/documentation/programming-guide/
- Beam runners and capabilities matrix: https://beam.apache.org/documentation/runners/capability-matrix/
Rule of thumb
- If you need large-scale, low-latency, windowed data processing with exactly-once semantics, choose Beam (and a suitable runner) for the compute; use Prefect to orchestrate it end-to-end.
- If you’re coordinating multi-step workflows across systems, with control flow, scheduling, retries, and observability—and your transforms aren’t inherently “big distributed data”—Prefect alone is usually the right tool.
If you share a bit about your workload (batch vs streaming, data sizes, latency/SLA, runner preferences), I can suggest a concrete architecture and a Prefect pattern to launch and monitor the Beam jobs.