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.

  • Python 3.12
  • PySpark 4
  • PostgreSQL 16
  • Parquet
  • Docker Compose
  • pytest
  • GitHub Actions
rawbronzesilvergoldPostgreSQL✓quality gaterejected + reasoninput = duplicates + rejected + validrawbronzesilvergoldrejected rowsgate ✓PostgreSQLinput = dups + rejected + valid
Illustration of the pipeline stages. Row and segment sizes are not to scale.

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

  1. 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.

  2. RawKeep every response, unchanged

    Immutable raw JSON with SHA-256 checksums. Files are created exclusively, so a rerun does not overwrite earlier raw data.

  3. BronzeRead with explicit schemas

    Malformed records are captured instead of silently dropped.

  4. 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 rows

    Routed to a rejected-records dataset that keeps every rejection reason.

  5. 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 fails

    By default, that date is not published to PostgreSQL.

  6. PostgreSQLLoad in one transaction

    COPY into a staging table, then delete and insert by date, in a single transaction under an advisory lock.

From ingestion to PostgreSQL. Rejected rows and failed quality checks are kept and reported.

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.