The Simplest Way to Make Airflow and Google Pub/Sub Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

You pair airflow and google pub/sub to trigger batch jobs from live events. Airflow runs the scheduled tasks while the message bus moves event data between apps. Many teams struggle when they connect a batch tool to a fast stream. Long polling jobs can drain compute nodes and rack up cloud costs. Good patterns keep both systems fast, safe, and easy to manage. How airflow and google pub/sub pass data and keys Airflow uses provider packages to talk to Google Cloud services. A workflow task can

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You pair airflow and google pub/sub to trigger batch jobs from live events. Airflow runs the scheduled tasks while the message bus moves event data between apps.

Many teams struggle when they connect a batch tool to a fast stream. Long polling jobs can drain compute nodes and rack up cloud costs. Good patterns keep both systems fast, safe, and easy to manage.

How airflow and google pub/sub pass data and keys

Airflow uses provider packages to talk to Google Cloud services. A workflow task can publish a new message to a topic. Another task can pull waiting messages from a subscription.

To do this, the scheduler and workers need a cloud identity. Most teams link an identity role to the worker nodes. When a task runs, it uses that role to call the message API.

Data flows between the two tools in two main ways. In the first way, an outside app sends a message to a topic. A sensor task in Airflow waits for that message and starts a job.

In the second way, a finished job sends a notice to a topic. Downstream apps read that notice and start their own work. This keeps your batch jobs and live apps separate.

For waiting tasks, teams should use async sensors on their worker nodes. Standard sensors hold a worker slot open while they wait for data. Async sensors free up the worker until the message arrives.

Common failure modes and how to scope roles

The biggest risk in this setup is a shared service account. Teams often give one broad cloud key to the whole Airflow cluster. Every task then gets full rights to all topics and subscriptions.

If one workflow has a bug, it can read from the wrong queue. It might pull messages meant for another team and drop them. Static keys stored in plain text also create a huge security risk.

End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Unlogged actions cause headaches during an audit. When twenty jobs share one identity, cloud logs show only that single name. You cannot tell which specific task or user read a sensitive message.

Sensitive data in message payloads makes this problem worse. Events often carry user emails, phone numbers, card numbers, or national IDs. Without field controls, worker logs might print those raw values in plain text.

To fix permissions, give each workflow its own narrow cloud role. Grant publish rights only to the exact topic a task needs. Grant pull rights only to the single subscription that job reads.

Network rules also need tight limits in production. Keep worker nodes on private subnets without public web addresses. Use private cloud routing so traffic stays inside the cloud network.

How to handle retries and dead letters

Message queues and batch tools handle failed tasks in different ways. The message bus expects a quick reply after a worker pulls data. If a batch task takes too long, the bus sends the message again.

This mismatch causes duplicate runs of the same workflow. To avoid this, pull the message and reply right away. Then pass the payload to the next task in your workflow.

Always set up a dead letter topic for broken messages. Sometimes a bad payload causes a parsing task to crash every time. A dead letter rule moves that bad message aside after a few tries. Your main queue stays clear and your team can inspect the broken data later.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

Should Airflow pull messages or should the queue push to it?

Pulling with async sensors works well for steady schedules and batch loads. If you need instant runs, use a cloud function to read the queue. That function can then call the workflow API to start a run.

How do we stop duplicate workflow runs from the same message?

Make your tasks safe to run more than once. Give each run a unique ID based on the message ID. If the queue sends the message twice, the second trigger will fail safely.

Where should we store cloud keys for local testing?

Avoid saving static JSON key files on laptops. Have developers log in with their own cloud user accounts instead. Grant those user accounts temporary rights to a test topic and subscription.

The query runs. The emails stay hidden.