~/mansi-aher

Project

DataGuard

CompleteBackend · Data quality pipelines

Overview

Recorded locally from the repository's code with its synthetic demo file: upload, 32 accepted and 8 rejected, correct a record, replay it, and check the audit trail.

Validate incoming data against versioned rules, quarantine what fails, and recover interrupted runs without duplicate writes.

DataGuard ingests CSV uploads and paginated HTTP sources, validates every row against a versioned rule set, and splits the results into accepted records and a quarantine that keeps each row's original values and the reason it failed. Users correct quarantined rows and replay them, and every step lands in an audit trail. Celery workers process runs in bounded batches; PostgreSQL holds the inputs, rule versions, checkpoints, results and evidence.

Runs locally with Docker Compose; not deployed publicly. The Celery worker-kill integration script and the GitHub Actions workflow haven't been run yet.

Problem

Batch jobs fail halfway. When a worker dies mid-run, naive retries either lose rows or write them twice, and rejected rows are often dropped with no record of why. DataGuard is built so an interrupted run resumes safely and every rejected row can be traced, corrected and replayed.

Role

Sole engineer

Stack

API
Python 3.11FastAPIPydantic
Data
PostgreSQL 16SQLAlchemyAlembic
Jobs
Celery workersCelery beat recovery scannerRedis (task delivery)
Frontend
Next.jsTypeScriptTailwind
Quality & ops
pytestPlaywrightDocker Compose

Architecture

A modular monolith: the API and the workers run separately, and PostgreSQL is the source of truth for everything, so Redis can restart without losing work.

  1. Next.js interface

    Upload and preview, rule editing, run results, quarantine, correction, replay and audit views.

  2. FastAPI

    Bearer-token auth and per-user ownership checks on every dataset, run and record.

  3. PostgreSQL

    Original bytes and content hashes, immutable rule versions, checkpoints and leases, accepted business keys, quarantine evidence, audit events.

  4. Celery worker

    Processes a run in batches of 250 rows using the same transactional core as the tests.

  5. Celery beat scanner

    Finds runs whose lease expired and queues them again, so a crashed worker's run resumes from its last checkpoint.

Engineering

Engineering decisions

  • One transaction per batch

    Records, failures, counters, the checkpoint and the lease renewal commit together, so a crash leaves a whole batch or none of it.

  • Leases with fencing tokens

    A worker that lost its lease can't commit after another worker has taken over the run.

  • Uniqueness enforced by the database

    Unique business keys per dataset block duplicate accepted writes even under concurrent or repeated delivery.

  • Immutable, versioned rule sets

    Each run records the exact configuration it used, so results are reproducible and corrections replay against the same rules.

  • At-least-once, stated plainly

    No exactly-once claim: safety comes from constraints and checkpoints, not from the queue.

Challenges & solutions

  • Proving recovery instead of asserting it

    A script hard-kills a real processing process after its first committed batch, waits for the lease to expire, and resumes the run. Result: 2,000 accepted rows, 0 duplicate writes, 2 attempts.

  • SQLite and PostgreSQL behave differently

    A partial-batch rollback test failed on SQLite's legacy transaction handling; explicit BEGIN and foreign keys fixed it. Concurrency tests run only on PostgreSQL, which has real row locks.

  • Fetching from external sources safely

    HTTP connector destinations come from an administrator-owned allowlist. Arbitrary user URLs, redirect targets and server-provided next-page URLs are not followed.

Results & roadmap

Results & outcomes

Local measurements on a shared laptop, not production capacity figures.

  • Crash-recovery test: 2,000-row run hard-killed after 250 committed rows, resumed after lease expiry

    0 duplicate records

    Source: docs/recovery-results.json: 2,000 accepted, 2 attempts. One test of the processing core on PostgreSQL; Redis/Celery transport excluded.

  • 100,000-row benchmark: accepted / quarantined

    99,996 / 4

    Source: Exactly the 4 seeded failures; 0 extra writes after two repeated deliveries (docs/VERIFICATION.md).

  • Backend tests on PostgreSQL 16

    23 passed

    Source: Concurrent delivery, partial-batch rollback, lease fencing, duplicate prevention, replay, ownership.

  • Browser end-to-end tests

    2 passed

    Source: Playwright against the full Docker Compose stack: correction and replay, and the paginated HTTP import.

Roadmap

  1. Ingestion · CSV upload with preview, paginated HTTP connectorDone
  2. Validation · Versioned rules, failure-rate threshold, unexpected-column policyDone
  3. Quarantine · Original evidence, correction, replay, audit trailDone
  4. Recovery · Checkpoints, leases, fencing tokens, scheduler re-queueDone
  5. Celery worker-kill test · Script written, not yet runPlanned
  6. Hosted deploymentPlanned

Links