petabytedata.dev
← ALL ARTICLES

Data Platforms · By Divya Madhavan

Designing a Reusable PySpark Ingestion Framework for BigQuery

An architecture note inspired by Divya Madhavan’s work on multi-format ingestion with PySpark, Dataproc, BigQuery and Airflow. Explore how to onboard new feeds, track what landed and recover safely when a run fails.

Decide what every feed should share

Divya’s work included a reusable Python and PySpark framework that loaded multiple file formats into BigQuery through Dataproc, alongside Airflow automation and BigQuery audit processes. The design below uses an illustrative daily order feed to explore decisions that arise when expanding that pattern to more datasets.

Give each feed an explicit contract

The shared framework handles source reading, validation reporting, staging and run tracking. Feed owners define the expected schema, required fields, destination and publication mode. A customer CSV and an order JSON feed can use the same operational checks, while the order feed’s rules for cancellations and revenue stay in code the business owner can review. Give each contract a version so an operator can reconstruct how an older delivery was interpreted.

Record the input identity before processing

Assign each attempt a run ID and record the source object identity and version, the contract version and the destination. A rerun of the same input can then be distinguished from a corrected file delivered under the same name. When a feed spans several files, capture the expected input set and its versions in a manifest. The orchestrator’s run ID helps trace an attempt. The source manifest identifies the data being processed.

Stage and validate before publishing

Write transformed data to a staging destination tied to the delivery. Record rows read, accepted, rejected and published, along with the reason a run stopped. Check rules that match the feed, including expected date coverage and key uniqueness where applicable. If rejected rows contain sensitive data, restrict access to the quarantine store and record counts and error categories in ordinary logs.

Recover from a load that succeeded before the task timed out

Suppose the destination write succeeds but the orchestration task times out before it records success. On retry, reconcile the destination with the recorded delivery and operation identity before issuing another write. A complete daily extract might use a validated replacement of the intended partition. An event feed might need a stable business key, deduplicated staging records and an explicit merge rule. Define which version wins if an older delivery races with a correction. Where the publish and audit writes are separate, test the gap between them explicitly.

Test whether another team can operate it

Ask an engineer who did not build the framework to onboard a feed, diagnose a schema mismatch and recover a timed-out load. Measure time to first successful delivery, time to diagnose a failure and the share of feeds that need changes to the shared runtime. Those are suggested measurements. If onboarding repeatedly requires a runtime change, revisit which responsibilities belong in the shared layer and which belong with each feed.

Apply the contract to cloud and AI inputs

The same source identity, recovery and audit rules can guide a feed on AWS even when the storage and execution services differ. If a document becomes input to an AI retrieval pipeline, track the document version and processing configuration that produced each derived record. That makes it possible to rebuild an affected version or identify derived records for removal after access is revoked. These are extensions of the design for future workloads.

What to record

CheckRecordDecision
OnboardingTime from an agreed feed contract to the first validated deliveryIdentify where teams need help
RecoveryOutcome when publishing succeeds before the audit updateVerify replay preserves downstream totals
ReuseWhich new feeds require edits to the shared runtimeKeep feed-specific logic with the team that owns it
More from the blog

AUTHOR PROFILE

Divya Madhavan

Certifications

Honors