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

Tidelog

Kafka-style durable partitioned log broker: CRC'd records, offsets, generation-fenced consumer groups.

Python 3.11+ · socketserver · SQLite 641 lines of core code source on GitHub ↗ CI status

4/4 core requirements 5 tests passing 2/2 benchmark targets

Verified 2026-11-28; CI re-runs the acceptance tests on every push.

The problem

Partitioned, durable logs decouple producers from consumers and let each consumer group replay at its own pace. This single-broker Kafka-like system makes durability, ordering, offsets, lag and duplicate delivery concrete.

What I found

  • A fault point crashes the broker halfway through writing a record; on restart the torn tail is truncated and all 39 acknowledged records are intact.
  • Flipping one byte in the middle of the log makes the broker refuse to start instead of silently dropping data.
  • A consumer that crashes after processing but before committing gets duplicates - and an idempotent sink keyed by (topic, partition, offset) absorbs them.

Architecture

producer ─► TCP frame (u32 len + JSON, base64 payloads) ─► dispatch ─► Broker.produce_batch
            ─► SHA-256(key) % partitions | round-robin ─► PartitionLog lock ─► write frames ─► flush+fsync ─► ack
consumer ─► fetch(topic, partition, offset, max_records, max_bytes) ─► pread via in-memory offset index
         ─► commit(group, topic, partition, next_offset[, generation, member]) ─► SQLite transaction

Record format: u32 length | u64 offset | i32 key_len (-1 null) | key | u32 value_len | value | u32 crc32. Recovery: scan from byte 0; stop at an incomplete final frame and truncate it; any complete record with a bad CRC or an out-of-sequence offset raises CorruptLogError (quarantine, never silently drop). The high watermark is the durable end (exclusive) and only advances after a successful flush/fsync. An I/O error closes the partition until restart. Offsets: commits must be ≤ high watermark and cannot move backwards; rewinds use seek. Groups (P1): static membership with heartbeat leases; any join/expiry bumps the generation; commits from a managed group must carry the current generation and target a partition assigned to that member. Limits: loopback only, 4 MiB frames, 1 MiB records, 64 connections, 30 s socket timeout, topic names [A-Za-z0-9._-]{1,64}.

Requirements → tests

ReqPriRequirement Proven byStatus
FR-01P0Fixed-partition topics; produce returns partition + offset after durable append; SHA-256 key routing / round-robinT01, T03pass
FR-02P0Length-prefixed CRC records; rebuild index on restart; truncate torn tail; fail on mid-log corruptionT03pass
FR-03P0Fetch by partition/offset with max records/bytes; next offset + high watermarkT02, T05pass
FR-04P0Committed next offsets per (group, topic, partition) in SQLite; resume/seek/replay; lagT02, T04pass
FR-05P1Static group assignment, generation IDs, heartbeat leases, stale-commit rejection; dedup sinkT05, T04pass
TestWhat it provesResult
T01Stable key->partition across restarts; concurrent producers get contiguous unique offsetspass
T02Fetch in batches, commit, restart broker+consumer, resume at exact offset; seek replaypass
T03Broker crashes mid-append (failpoint) and is hard-killed after ack; torn tail truncated; mid-log CRC corruption rejectedpass
T04Consumer crashes after side effect, before commit: duplicate delivery + downstream deduppass
T05Expired membership/rebalance rejects old-generation commits; invalid/oversized frames, fetch past end, path-escaping namespass

Benchmark

Target (hypothesis from the spec)GoalActual
batch-durable mode >= 1,000 records/s on local SSD (provisional)>= 1000/smin 21594/smet
every produced record fetched back (no loss)fetched == producedokmet
  • fsync_records_per_s = 11509
  • batch_records_per_s = 118792
  • fsync_ack_p95_ms = 0.647

quick run · 2026-11-28T23:57:02+00:00 · fsync-per-record and batch-durable are different durability contracts - never equivalent.

Design questions

Why partitions?

Independent ordered logs allow parallel reads/writes and scale-out; a key keeps per-key order as long as its partition mapping is stable.

What is an offset?

A monotonically increasing position within one partition. A consumer group commits the next position it wants, independently of other groups.

Why are duplicates possible?

A consumer can process a record and crash before committing, or a producer can retry after an ambiguous ack. Use idempotent/dedup sinks or transactional coordination.

What changes with replication?

A leader coordinates replicas, durability depends on replica acks and leader election, and consumers must not read uncommitted or divergent data (high watermark across ISR).

What is rebalancing?

Membership changes move partition ownership. Generation/epoch fencing stops a revoked consumer from committing stale progress; real brokers add assignment protocols and cooperative transitions.

Limitations

  • Single broker, no replication/transactions/compaction/retention
  • Custom JSON framing, not the Kafka wire protocol
  • macOS fsync does not force the drive cache

Run it

git clone https://github.com/ravirs/tidelog.git && cd tidelog
pip install -r requirements.txt
PYTHONPATH=src python -m minikafka demo   # 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
  • Floe Iceberg-style table format: immutable Parquet, manifests, snapshots, time travel, compare-and-swap commits
  • Flint Spark-style batch engine: lazy lineage, stage planning, shuffles, broadcast and salted skew joins
  • 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