SDE3 Assignment - CDC Lakehouse Reliability (Prashant Gaikwad) - #18
Open
prashantgaikwadpng wants to merge 12 commits into
Open
SDE3 Assignment - CDC Lakehouse Reliability (Prashant Gaikwad)#18prashantgaikwadpng wants to merge 12 commits into
prashantgaikwadpng wants to merge 12 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CDC Lakehouse Reliability Assignment — Submission
Domain: Wallet / Payments / Transfers. Full design writeup in
DESIGN.md(written before implementation). Setup/run instructions in
README.md.1. Source Schema Design
5 tables, mixing strong and weak entities (
01_source_schema.sqlhas theproduction-target PostgreSQL DDL with native enums and
COMMENT ONextendedproperties;
src/source_db.pyhas the working SQLite equivalent used forlocal execution):
customers,wallets,transactions— each has independentidentity and lifecycle.
transaction_line_items(composite PKtransaction_id, line_number,ON DELETE CASCADE),balance_history(composite PKwallet_id, history_id, append-only ledger) — neither can exist withoutits parent.
Keys/relationships: FKs from
wallets→customers,transactions→wallets(nullable, for one-sided external flows),
line_items→transactions,balance_history→wallets/transactions. Indexes on all FK columns plus aunique
(customer_id, currency_code)index on wallets. Validation rules:balance >= 0,amount > 0,settled_at >= initiated_at, enum-constrainedstatus/type fields, plus cross-row invariants (line items sum = transaction
amount) enforced downstream.
2. CDC Strategy
Changes are captured via an application-level append-only
cdc_logtablewritten in the same transaction as every business DML (insert/update/delete
all go through a
SourceDBwrapper — no path bypasses logging). This is adocumented simulation of a WAL/Debezium-style log; production would swap
this for PostgreSQL logical replication into Kafka (see
DESIGN.md§2 forthe full production-vs-local mapping).
checkpoints/cdc_checkpoint.json)storing the last-processed
log_id; restart resumes from there, not fromscratch. Demonstrated in
tests/test_cdc_correctness.py::test_restart_from_checkpoint_after_partial_failure._applied_log_idstable keyed on
log_id— re-delivering the same lake events is a no-op.Demonstrated in
test_replay_does_not_duplicate_in_warehouse.DELETEevents, propagated through the lake, andapplied in the warehouse by closing the SCD2 history version
(
is_deleted=TRUE) and removing the row from the_currentsnapshot.3. Lake and Warehouse Modeling
lake/<table>/dt=.../changes.jsonl),one line per change event — full, replayable history, never rewritten.
<table>_current(latest snapshot, one row per business key) and
<table>_history(SCD2:valid_from/valid_to/is_current/is_deleted).warehouse_loader.reconstruct_at(table, pk, as_of_ts)queries
_historyfor the version whose validity window containsas_of_ts. Demonstrated intest_historical_reconstruction_time_travel,which updates a wallet balance and proves the pre-update value is still
reconstructable while
_currentreflects the new value.4. Schema Change Safety
schema_guard.pyfingerprints the source schema (per-column name, type,nullability, PK role) and compares against a persisted last-known-good
baseline before any extraction runs. Dropped/renamed columns, type
changes, nullability changes, and PK-role changes are classified
incompatible →
SchemaDriftErroris raised, a structured alert is appendedto
checkpoints/schema_alerts.log, and — because the check runs before anylake write — nothing is written under broken assumptions. New tables/columns
are treated as additive/non-breaking (documented simplification). Covered by
tests/test_schema_safety.py(5 tests: baseline establishment, compatiblepass-through, dropped-column halt, alert content, type-change detection).
5. Validation Parity
validations.pyre-asserts the source's system rules (PK uniqueness, FKintegrity, non-null) and business rules (non-negative balance, positive
amount, line-items-sum = transaction amount, settled≥initiated) against the
warehouse
_currenttables. Returns a structured{check: [violations]}report; run standalone it exits non-zero on any failure, so it can gate CI.
Covered in
tests/test_warehouse_correctness.py, including a test thatdeliberately creates a line-item mismatch and asserts it's caught.
6. Catalog Exposure
catalog.pygeneratescatalog/catalog.yml, registering every lake andwarehouse dataset with layer, path/format, schema reference, owner, intended
consumers, update cadence, and primary key. Regenerated idempotently on each
pipeline run. Production analogue: auto-registration into a Glue/Unity
Catalog/DataHub instance.
7. Responsible AI Usage
I used Claude (Anthropic) to help design and implement this pipeline against
the assignment spec — it drafted the schema, CDC/warehouse/validation code,
tests, and documentation from requirements I gave it.
What I reviewed and validated myself:
→ validate) and confirmed it completes without error.
to confirm it actually exercises the behavior it claims to (e.g., the
schema-drift tests genuinely mutate the SQLite schema and assert the halt,
rather than mocking the check).
most safety-critical piece — confirmed it runs before any lake write and
that the incompatible-change classification list matches what the
assignment calls out (dropped/renamed column, type change, enum/nullability
change).
ALTER TABLE ... DROP COLUMN) outsidethe test suite and confirmed the CLI halts with a clear message and the
alert log is written (steps documented in
README.md).attempting real Postgres WAL locally), and the SCD2-based time-travel
design as tradeoffs appropriate for the assignment's time-box; these are
documented explicitly in
DESIGN.mdrather than left implicit.Assumptions, Tradeoffs, Limitations
See
README.md→ "Assumptions & Limitations" andDESIGN.md§2/§7 for thefull list (simulated CDC vs. real WAL, backward-compatible schema changes
not halting, out-of-order arrival across independent producers not fully
solved, no production orchestrator).