Personal project · Data engineering
Book Pricing Analytics Pipeline
An end-to-end PySpark batch pipeline that turns real Open Library book metadata and seeded pricing data into daily pricing recommendations, with every input row accounted for.
The problem
Pricing analytics built on dirty data are wrong in ways that are hard to see: a malformed ISBN, a duplicate listing, or a row that disappears without a trace.
What I built
- Resilient ingestion from the Open Library REST API, with retries, backoff and payload validation.
- A bronze, silver and gold (medallion) pipeline in PySpark with explicit schemas, validation and deduplication.
- A rejected-records dataset that keeps every rejection reason, and a quality gate before publishing.
- Daily pricing recommendations and a category summary as date-partitioned Parquet, loaded into PostgreSQL.
- A seeded data generator that injects known defects, and a one-command run with Docker Compose.
How it works
- IngestFetch book metadata from Open Library
Request timeouts, exponential backoff on 429 and 5xx responses, Retry-After handling and payload validation. Other 4xx errors are not retried. Pricing and inventory records come from a seeded generator.
- RawKeep every response, unchanged
Immutable raw JSON with SHA-256 checksums. Files are created exclusively, so a rerun does not overwrite earlier raw data.
- BronzeRead with explicit schemas
Malformed records are captured instead of silently dropped.
- SilverValidate, normalize, deduplicate
ISBN-10 and ISBN-13 checksums as native Spark expressions, ISBN-10 to ISBN-13 conversion, normalized fields, then exact and business duplicates removed with a window function.
Invalid rowsRouted to a rejected-records dataset that keeps every rejection reason.
- GoldBuild outputs and a quality report
Daily pricing recommendations (inventory-aware, with a price floor), a category summary and a data-quality report, written as Parquet partitioned by date.
Quality gate failsBy default, that date is not published to PostgreSQL.
- PostgreSQLLoad in one transaction
COPY into a staging table, then delete and insert by date, in a single transaction under an advisory lock.
input = exact duplicates + rejected + business duplicates + valid
Key engineering decisions
- Validate in Spark, not in Python UDFs. ISBN checksums and conversion are native Spark expressions, safe under Spark 4's ANSI mode.
- Deduplicate after validation. Business duplicates are removed with a window function once invalid rows have been separated out.
- Safe reruns. Raw data is never overwritten, and re-running a date replaces only that date's output.
- Transactional loads. All tables for a date load in one transaction under an advisory lock, with parameterized SQL.
Results & verification
- CI82automated tests in CI
- Unit, Spark transformation, HTTP-level ingestion, end-to-end and PostgreSQL integration tests, plus lint and a Docker image build, in GitHub Actions.
- Test resultEveryinjected defect caught
- Each quality count is checked against the generator’s record of the defects it injected; the counts reconcile exactly.
- Test result1,200+ISBN inputs cross-checked
- The Spark ISBN logic is tested against a separate Python reference implementation.