All my work / Storage & data systems · by Ravindra Sawant
Flint
Spark-style batch engine: lazy lineage, stage planning, shuffles, broadcast and salted skew joins.
Verified 2026-11-28; CI re-runs the acceptance tests on every push.
The problem
Distributed batch engines pipeline narrow transformations and pay for wide ones with shuffles, skew and stragglers. This Spark-inspired engine has lazy lineage, stage planning, a process pool, hash shuffles and three join strategies.
What I found
- On an 80%-hot-key join, salting cut the largest task's input 2.5x while returning exactly the same rows as shuffle and broadcast joins.
- Map-side combine shrank a word-count shuffle from 288 KB to 328 bytes.
- Killing a worker after it wrote shuffle files triggers a retry with a new attempt id; the driver only accepts one winning attempt, so orphaned files never produce duplicates.
Architecture
Dataset ops (lazy) ─► lineage DAG: source → narrow* → reduce | join → narrow* ...
action ─► planner: walk lineage; fuse narrow chains; cut a ShuffleMapStage at each wide dependency
─► stages in topological order on a spawn ProcessPoolExecutor
map task ─► read input → fused ops → hash(canonical key) % R → R JSONL blocks (map-side combine optional)
work_dir/job/shuffle/s<id>/st<stage>-p<part>-a<attempt>/r<reducer>.jsonl
driver ─► accepts ONE winning attempt per partition (manifest) → barrier → reducers read winners' blocks only
reduce/join task ─► merge by key | left multimap × right stream (Cartesian on duplicate keys)
- Join strategies:
shuffle(co-partition both sides),broadcast(collect right side, row limit, multimap, optional fallback to shuffle),salted(hot keys on the left get salt = stable row ordinal % S; matching right rows replicated to every salt; salt stripped from output). - Failures: exceptions and dead workers (
BrokenProcessPool→ new pool) are retried up tomax_attemptswith a new attempt id; earlier attempts' files are orphans the driver never references. - Safety limits: max input rows,
max_collect, broadcast row limit; malformed input fails the task with file:line. - Serialization: JSON with tuples preserved (
{"__t__": [...]}), so outputs match the Python reference exactly.
Requirements → tests
| Req | Pri | Requirement | Proven by | Status |
|---|---|---|---|---|
| FR-01 | P0 | Partitioned datasets from iterables/JSONL; map/filter/flatMap build lazy immutable lineage | T01, T05 | pass |
| FR-02 | P0 | collect/count/reduceByKey; stages at wide boundaries; fused narrow ops; bounded process pool | T01, T02 | pass |
| FR-03 | P0 | Deterministic hash shuffle to per-reducer files; optional map-side combine | T02, T04 | pass |
| FR-04 | P0 | Inner equijoin via shuffle and broadcast (multimap); reject oversized broadcast | T03 | pass |
| FR-05 | P1 | Salted hot-key joins; retry failed tasks with attempt-specific outputs | T03, T04 | pass |
| Test | What it proves | Result |
|---|---|---|
| T01 | Lazy trace (no tasks before action), fused narrow plan, map/filter/count parity, empty/uneven partitions | pass |
| T02 | reduceByKey with/without combine matches reference; shuffle bytes shrink; reducer contract validation | pass |
| T03 | Shuffle, broadcast and salted joins give identical multisets on duplicate, missing and hot keys; broadcast limit | pass |
| T04 | Map task fails (exception or killed worker) after writing shuffle output; retry; no duplicates; bounded attempts | pass |
| T05 | Collect guard, malformed JSONL reported as task error, temp shuffle files cleaned after jobs | pass |
Benchmark
| Target (hypothesis from the spec) | Goal | Actual | |
|---|---|---|---|
| salting cuts the largest task input >= 2x on the hot-key fixture | >= 2x | 2.51x (25004 -> 9970) | met |
| exact output parity across all strategies | all exact | all exact | met |
| many-to-many key explosion is not fixed by repartitioning | same output | {4: 90000, 16: 90000} | met |
salting_max_task_reduction_x= 2.51retry_overhead_s= -0.021
quick run · 2026-11-28T23:57:24+00:00
Design questions
Narrow vs wide dependencies?
Narrow transformations pipeline within a partition; wide dependencies redistribute data across partitions and introduce a shuffle/stage boundary.
How do you spot skew?
Compare max vs median task input size and duration (not the average); one huge task means a hot key or bad partitioning.
When is a broadcast join right?
When one side is small enough to ship to every task; it avoids shuffling the big side. Duplicate keys need a multimap and large fan-out still costs memory/output.
How does salting work?
Spread hot keys on the large side across N salts and replicate the matching small-side records to each salt: balanced work at replication cost, all matches preserved.
How does Spark recover from failures?
Recompute lost partitions from lineage and regenerate map outputs; deterministic functions and a correct output-commit protocol (one winning attempt) make this safe.
Limitations
- Local processes only; not PySpark API compatible
- Functions must be importable top-level and deterministic; reducers associative + commutative
- No spill/external sort, AQE or caching
Run it
git clone https://github.com/ravirs/flint.git && cd flint
pip install -r requirements.txt
PYTHONPATH=src python -m sparkmini demo --rows 50000 # demo
PYTHONPATH=src python -m pytest -q # test
PYTHONPATH=src python benchmarks/bench.py --quick # benchMore systems I've built from scratch
Storage & data systems
- Strata LSM-tree key-value storage engine: WAL, SSTables with Bloom filters, atomic manifest, compaction
- Tidelog Kafka-style durable partitioned log broker: CRC'd records, offsets, generation-fenced consumer groups
- Floe Iceberg-style table format: immutable Parquet, manifests, snapshots, time travel, compare-and-swap commits
- Watermark Event-time stream processor: windows, watermarks, lateness, exactly-once checkpoints
- Warden Data governance catalog: explainable grants, row filters, column masks, lineage impact
- SnapshotDB MVCC transaction engine: snapshot isolation, the write-skew anomaly, a serializable mode
AI infrastructure
- Nearline HNSW-style vector search index from scratch, measured against exact search
- KVPager Paged KV cache with copy-on-write forks and prefix reuse (PagedAttention-style)
- Batchwise LLM inference scheduler simulator: static vs continuous vs chunked-prefill batching
- Steadyhand Durable AI agent runtime: allowlisted tools, approvals, budgets, crash recovery, replay
- Toolgate Model Context Protocol gateway: curated tools, signed identity, tenant policy, approvals, audit