All my work / Storage & data systems · by Ravindra Sawant

Flint

Spark-style batch engine: lazy lineage, stage planning, shuffles, broadcast and salted skew joins.

Python 3.11+ · multiprocessing (spawn) · JSONL shuffle files 540 lines of core code source on GitHub ↗ CI status

4/4 core requirements 9 tests passing 3/3 benchmark targets

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 to max_attempts with 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

ReqPriRequirement Proven byStatus
FR-01P0Partitioned datasets from iterables/JSONL; map/filter/flatMap build lazy immutable lineageT01, T05pass
FR-02P0collect/count/reduceByKey; stages at wide boundaries; fused narrow ops; bounded process poolT01, T02pass
FR-03P0Deterministic hash shuffle to per-reducer files; optional map-side combineT02, T04pass
FR-04P0Inner equijoin via shuffle and broadcast (multimap); reject oversized broadcastT03pass
FR-05P1Salted hot-key joins; retry failed tasks with attempt-specific outputsT03, T04pass
TestWhat it provesResult
T01Lazy trace (no tasks before action), fused narrow plan, map/filter/count parity, empty/uneven partitionspass
T02reduceByKey with/without combine matches reference; shuffle bytes shrink; reducer contract validationpass
T03Shuffle, broadcast and salted joins give identical multisets on duplicate, missing and hot keys; broadcast limitpass
T04Map task fails (exception or killed worker) after writing shuffle output; retry; no duplicates; bounded attemptspass
T05Collect guard, malformed JSONL reported as task error, temp shuffle files cleaned after jobspass

Benchmark

Target (hypothesis from the spec)GoalActual
salting cuts the largest task input >= 2x on the hot-key fixture>= 2x2.51x (25004 -> 9970)met
exact output parity across all strategiesall exactall exactmet
many-to-many key explosion is not fixed by repartitioningsame output{4: 90000, 16: 90000}met
  • salting_max_task_reduction_x = 2.51
  • retry_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   # bench

More 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

Distributed systems

  • Quorum Deterministic Raft consensus simulator with fault injection and an always-on invariant checker
  • Tandem Collaborative text editor on a sequence CRDT: offline edits, any delivery order, always converges
  • Burrow Minimal Linux container runtime in Go: namespaces, pivot_root, cgroup v2 limits

← See all my work: apps, ML/AI and systems