<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yegor Lukash on Medium]]></title>
        <description><![CDATA[Stories by Yegor Lukash on Medium]]></description>
        <link>https://medium.com/@lukashes?source=rss-5c0d43b798c7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*U8fYXQoiytU_AaC97F4oNQ.png</url>
            <title>Stories by Yegor Lukash on Medium</title>
            <link>https://medium.com/@lukashes?source=rss-5c0d43b798c7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 11:46:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lukashes/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Let’s Start Managing Dotfiles]]></title>
            <link>https://medium.com/@lukashes/lets-start-managing-dotfiles-3ec666381fc7?source=rss-5c0d43b798c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ec666381fc7</guid>
            <category><![CDATA[dotfiles]]></category>
            <category><![CDATA[chezmoi]]></category>
            <category><![CDATA[configuration]]></category>
            <dc:creator><![CDATA[Yegor Lukash]]></dc:creator>
            <pubDate>Tue, 24 Mar 2026 20:54:15 GMT</pubDate>
            <atom:updated>2026-03-24T20:54:15.465Z</atom:updated>
            <content:encoded><![CDATA[<p>I never really thought about managing my configs. Every time I get a new laptop, I install everything, use defaults, tweak things over time. The configs on different machines would slowly diverge, but it wasn’t a big deal. That’s just how it was.</p><p>I knew some people used Time Machine to restore their setups. Others kept their configs in a git repo. But I’d never heard the term “dotfiles management” as a concept — a deliberate approach to versioning and syncing your configs (obviously, <em>files</em> started from the <em>dot</em>), editor settings, and other stuff that lives in your home directory.</p><h4>What Changed</h4><p>I switched from Linux to Mac at work. The muscle memory was still Linux-shaped, so I had to reconfigure a lot of tooling — tmux, shell, key bindings. It took a while to get things right.</p><p>Then I also switched to Mac for personal laptop. And I realized I don’t want to go through all that again — figuring out the same settings, looking up the same flags. I wanted to set things up once and reuse them across machines.</p><p>So I started looking into how people actually solve this issue.</p><h4>The Tool</h4><p>The simplest approach — a bare git repo in <em>$HOME — </em>felt too manual and uncomfortable. I wanted something with a bit more structure.</p><p>I looked at <a href="https://yadm.io/">yadm</a> first. GitHub said 60% Python — and I instinctively moved on. Turns out that Python is just the test suite, yadm — is a shell script. But by the time I could have figured that out, I’d already found <a href="https://www.chezmoi.io/">chezmoi</a> — written in Go. I’ve written Go for a while, I already have the whole toolset on my machine: g<em>o install</em> or <em>brew install</em>, no runtime dependencies. That was enough to just go with it.</p><h4>How It Works</h4><p>Chezmoi keeps your dotfiles in a source directory (<em>~/.local/share/chezmoi</em>), separate from your home directory. The source is a <strong>regular git repo</strong>. When you run <em>chezmoi apply</em>, it syncs the source to the target.</p><pre>chezmoi add ~/.zshrc<br>chezmoi edit ~/.zshrc<br>chezmoi apply</pre><p>It also proxies git commands — <em>chezmoi git push</em>, <em>chezmoi git status</em>. Nothing exotic. It’s git underneath, so the mental model is familiar.</p><h4>Templating</h4><p>This is the part that sold me. My work laptop needs corporate tooling — internal CLIs, private Go module proxies, cluster management aliases. I don’t want any of that on my personal machine. It’s unnecessary, and some of it shouldn’t be there at all.</p><p>Chezmoi uses Go templates. During <em>chezmoi init</em>, it asks one question:</p><pre># .chezmoi.yaml.tmpl<br>data:<br> env: {{ promptStringOnce . &quot;env&quot; &quot;Environment (work/personal)&quot; }}</pre><p>One variable. Then in <em>.zshrc.tmpl</em>:</p><pre>autoload -U compinit; compinit<br>eval &quot;$(mise activate zsh)&quot;<br><br>{{ if eq .env &quot;work&quot; -}}<br>export GOPRIVATE=&quot;company.dev/*&quot;<br># … work-specific aliases and functions<br>{{ end -}}</pre><p>On the personal laptop, the work block doesn’t appear in the generated file at all. One template, two clean environments. The alternative (maintaining two separate zshrc files) would lead to the same divergence problem I was trying to solve.</p><h4>Summary</h4><p>I expected some friction. Configuration files to write, concepts to learn, edge cases to debug. In practice: <em>chezmoi init</em>, add a few files, push to git. That’s the whole setup.</p><p>On another machine:</p><pre>chezmoi init --apply &lt;repo&gt;</pre><p>It asks for the environment, generates the configs, puts them where they belong. A few minutes, and the machine has my setup. Next time only <em>chezmoi apply</em>, this is it.</p><p>I would recommend starting managing Dotfiles using any tool you want. Sadly I did not start doing it earlier.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ec666381fc7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning Zig by Building a PostgreSQL CDC Tool]]></title>
            <link>https://medium.com/@lukashes/learning-zig-by-building-a-postgresql-cdc-tool-4ba4b239ceaf?source=rss-5c0d43b798c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ba4b239ceaf</guid>
            <category><![CDATA[debezium]]></category>
            <category><![CDATA[change-data-capture]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[ziglang]]></category>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[Yegor Lukash]]></dc:creator>
            <pubDate>Mon, 09 Feb 2026 21:32:42 GMT</pubDate>
            <atom:updated>2026-02-09T21:32:42.557Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Outboxx" src="https://cdn-images-1.medium.com/max/800/1*Z4KlXVb-fQJTul27sUBjXg.png" /></figure><p>When Mitchell Hashimoto started building <a href="https://github.com/ghostty-org/ghostty">Ghostty</a> in <a href="https://ziglang.org/">Zig</a>, I got curious enough to try systems programming. After 10+ years writing Go, I wanted to learn something lower-level. The question was: what to build?</p><p>At my previous companies, I spent a lot of time dealing with Change Data Capture. We had a Kafka cluster connecting thousands of microservices across multiple data centers — CDC was everywhere. <a href="https://en.wikipedia.org/wiki/Change_data_capture">CDC</a> captures row-level changes from databases and streams them to other systems. The standard tool was <a href="https://debezium.io/">Debezium</a>: solid, battle-tested, but also hundreds of megabytes of memory per instance with JVM overhead.</p><p>What would a minimal CDC tool look like? I wasn’t trying to build a Debezium replacement — it’s excellent at what it does. I was just curious about the problem from a different angle. CDC seemed perfect for learning: real-world complexity (PostgreSQL replication protocol, Kafka integration), clear success criteria (events flow or they don’t), small enough for evenings and weekends.</p><p>So I spent a couple months building <a href="https://github.com/lukashes/outboxx"><strong>Outboxx</strong></a> — a PostgreSQL CDC tool that streams database changes to Kafka. This is that story, built with Zig 0.15.1.</p><h3>Building Outboxx</h3><p>Every project starts with choices. For Outboxx, the first was about dependencies.</p><h4>Choosing Libraries: The C Path</h4><p>The first decision came quickly. Zig’s ecosystem is young — the stdlib is solid, but third-party libraries for PostgreSQL replication and Kafka are scarce. But Zig has mature C libraries available: <strong>libpq</strong> for PostgreSQL (the official client) and <strong>librdkafka</strong> for Kafka (high-performance, battle-tested).</p><p>For a learning project, this seemed perfect — I’d learn C interop while building on proven foundations rather than reinventing protocols.</p><p>Then came the question: how do you manage C dependencies? System packages (apt install libpq-dev) pollute your system and create &quot;works on my machine&quot; problems. Manual compilation is time-consuming and not reproducible. Different versions on different machines lead to subtle bugs.</p><p>While exploring Zig projects, I kept seeing <a href="https://nixos.org/">Nix</a> mentioned. Ghosty uses it. Zig’s own infrastructure uses it. I was curious.</p><h4>Nix: Reproducible Dependencies</h4><p>Nix is a package manager that solves the reproducibility problem through declarative configuration:</p><pre># flake.nix<br>{<br>  description = &quot;Outboxx - PostgreSQL CDC in Zig&quot;;<br>  <br>  inputs = {<br>    nixpkgs.url = &quot;github:NixOS/nixpkgs/nixos-unstable&quot;;<br>  };<br><br>  outputs = { self, nixpkgs }: {<br>    devShell = pkgs.mkShell {<br>      buildInputs = [<br>        libpq        # PostgreSQL client - specific version<br>        rdkafka      # Kafka client - specific version<br>        zig          # Pinned to 0.15.1<br>      ];<br>    };<br>  };<br>}</pre><p>Run nix develop and you get a shell with exact dependency versions, isolated from your system. Clone the repo on any machine (Linux, macOS) and get an identical environment. No conflicts with other projects.</p><p>This actually saved me later. I started development on Linux, then switched to Mac midway through the project. Ran nix develop on the new machine - everything just worked. Same library versions, same Zig toolchain, zero configuration. Both Nix and Zig share a philosophy: explicit, reproducible, no hidden surprises.</p><h4>C Interop: Simple but Explicit</h4><p>With dependencies managed, integrating them into Zig was surprisingly straightforward. Coming from Go’s cgo — which nobody really enjoys — I expected pain.</p><p>The <a href="https://en.wikipedia.org/wiki/Foreign_function_interface">FFI</a> part uses @cImport:</p><pre>const c = @cImport({<br>    @cInclude(&quot;libpq-fe.h&quot;);<br>    @cInclude(&quot;librdkafka/rdkafka.h&quot;);<br>});<br><br>// Use directly with type safety<br>const conn = c.PQconnectdb(connection_string);<br>if (c.PQstatus(conn) != c.CONNECTION_OK) {<br>    return error.ConnectionFailed;<br>}<br>const producer = c.rd_kafka_new(c.RD_KAFKA_PRODUCER, conf, errstr, errstr.len);</pre><p>The @cImport mechanism translates C types automatically while keeping type safety. Unlike Go where cgo converts and copies strings at the boundary, Zig has no string type at all - just []u8 byte slices, exactly how C thinks about text. Direct interop, no runtime conversions. Error handling flows naturally through Zig&#39;s try/catch.</p><p>The linking part is declarative in build.zig:</p><pre>const exe = b.addExecutable(.{<br>    .name = &quot;outboxx&quot;,<br>    .root_source_file = b.path(&quot;src/main.zig&quot;),<br>    .target = target,<br>    .optimize = optimize,<br>});<br><br>// Link C libraries - simple and explicit<br>exe.linkSystemLibrary(&quot;pq&quot;);<br>exe.linkSystemLibrary(&quot;rdkafka&quot;);<br>exe.linkLibC();</pre><p>No build tags scattered across code. No magic comments. No linker archaeology. Just declare your dependencies in one place. This felt right.</p><h4>Memory Management: Arena Allocator</h4><p>With infrastructure sorted, the real work began. Each CDC event needs temporary memory: JSON parsing, routing key construction, stream matching.</p><p>In Go, you’d let the GC handle it. Zig has no garbage collector — you manage memory explicitly. Every allocation needs a corresponding free:</p><pre>const buffer = try allocator.alloc(u8, 1024);<br>defer allocator.free(buffer);  // Must remember to free!</pre><p>The defer statement (familiar from Go) executes when the scope exits. I messed this up once - forgot the defer on a branch and watched memory climb during a benchmark. The fix was obvious once I saw it: no defer, no cleanup. The explicitness that seemed verbose at first became helpful for debugging.</p><p>But tracking dozens of allocations per event gets tedious. For batch processing like CDC, there’s a better pattern: <strong>ArenaAllocator</strong>. Allocate freely during processing, free everything at once when done.</p><pre>while (!stop_signal.load(.monotonic)) {<br>    // Create arena for this batch<br>    var batch_arena = std.heap.ArenaAllocator.init(self.allocator);<br>    defer batch_arena.deinit(); // All batch memory freed here<br>    <br>    // Process batch - allocate freely inside<br>    try self.processChangesToKafka(batch_arena.allocator(), BATCH_SIZE);<br>    <br>    // Exit scope -&gt; defer triggers -&gt; entire arena freed at once<br>}</pre><p>Parse JSON, build routing keys, match streams — arena allocates. Exit function — one deinit() call frees everything. O(1) cleanup, cache-friendly memory layout, no tracking overhead.</p><p>This pattern proved both simple and fast — throughput jumped to 85K from 60K events/sec. But I could see the next bottleneck: waiting for Kafka to acknowledge each batch before continuing.</p><h4>Performance: Background Flush with Atomics</h4><p>The solution wasn’t more memory optimizations — it was separating I/O from processing. For at-least-once delivery semantics, events must reach Kafka before acknowledging them to PostgreSQL. My initial approach: synchronous flush after each batch. Simple, correct, but slow — network latency blocked the entire pipeline.</p><p>Background flush worker with atomic coordination solved this:</p><pre>// Shared state: atomic LSN (Log Sequence Number)<br>pending_lsn: std.atomic.Value(u64)<br><br>// Main thread: Process events, update LSN<br>self.pending_lsn.store(batch.last_lsn, .release);<br><br>// Background worker: Flush periodically<br>fn flushWorker(self: *Processor) void {<br>    while (!self.stop_signal.load(.monotonic)) {<br>        std.time.sleep(10 * std.time.ns_per_s);<br>        <br>        const lsn = self.pending_lsn.load(.acquire);<br>        <br>        // Flush to Kafka<br>        self.producer.flush(TIMEOUT) catch return; // Fail-fast<br>        <br>        // Acknowledge to PostgreSQL ONLY after successful flush<br>        self.source.sendFeedback(lsn) catch return;<br>    }<br>}</pre><p>And spawning the thread:</p><pre>const flush_thread = try std.Thread.spawn(.{}, flushWorker, .{<br>    processor,<br>});<br>// ...<br>flush_thread.join();</pre><p>How this guarantees at-least-once:</p><ul><li>LSN stored atomically after processing</li><li>Background worker flushes to Kafka every 10 seconds</li><li>PostgreSQL acknowledgment sent ONLY after successful Kafka flush</li><li>If flush fails → process exits → supervisor restarts → PostgreSQL re-sends data</li></ul><p>Simple fail-fast architecture. No retry logic, no exponential backoffs — the process either works or exits cleanly. The supervisor handles recovery.</p><p>Zig’s std.atomic.Value provides low-level control over concurrency. Memory ordering semantics (.acquire, .release) look unfamiliar coming from Go, but are straightforward to understand.</p><p>This gave the final jump from 85K to 105K events/sec — the main thread processing events while background worker handled I/O asynchronously.</p><h3>The Result</h3><h4>From 1K to 100K Events/sec</h4><p>After the first week, I had 1K events/sec and thought “this is fine for a learning project.” Then I benchmarked Debezium. 150K/sec. That hurt a bit.</p><p>The evolution was gradual:</p><pre>Version | Key Change              | Result<br>--------|-------------------------|------------------<br>v1      | Polling                 | 1K/sec<br>        | (test_decoding)         | Protocol basics,<br>        |                         | Zig syntax<br>        |                         |<br>v2      | Streaming binary        | 32K/sec<br>        | (pgoutput)              | Binary parsing,<br>        |                         | C interop<br>        |                         |<br>v3      | Event-driven I/O        | 60K/sec<br>        | (poll syscall)          | Syscalls,<br>        |                         | non-blocking I/O<br>        |                         |<br>v4      | Arena allocator         | 85K/sec<br>        |                         | Memory patterns<br>        |                         |<br>v5      | Async Kafka flush       | 105K/sec<br>        |                         | Atomics,<br>        |                         | coordination</pre><p>Each step taught something about either Zig or systems programming. Zig’s explicit memory control and simple C interop made iterating through these changes straightforward.</p><p>After those couple months of evening work, here’s what emerged:</p><p><strong>Outboxx</strong> — a lightweight PostgreSQL CDC tool in ~3000 lines of Zig.</p><pre>PostgreSQL WAL    →      Outboxx    →    Kafka Topics<br>(logical replication)       ↓            (partitioned)<br>                       Parse &amp; Route</pre><p>Single binary: <strong>~500 KB</strong>. Memory: <strong>&lt;10 MiB</strong> at runtime. Throughput: &gt;<strong>100K events/sec</strong>.</p><h4>Comparison with Debezium</h4><p>I benchmarked against Debezium (1M events, MacBook M4 Pro):</p><pre>Metric          | Outboxx    | Debezium<br>----------------|------------|-------------<br>Binary size     | ~500 KB    | ~250 MB<br>                |            |<br>Memory (peak)   | &lt;10 MiB    | ~500 MiB<br>                |            |<br>Throughput      | ~100K/sec  | ~150K/sec</pre><p>Outboxx is a ReleaseSafe build dynamically linked with libpq and librdkafka. Debezium was tested with 512 MiB memory limit.</p><p>Debezium is faster and has more features — it’s the mature, battle-tested choice. But for moderate-load outbox pattern implementations, Outboxx delivers serious throughput with minimal resources.</p><p><strong>Benchmark context</strong>: These numbers represent local testing with default configurations. Production performance varies based on hardware, Kafka cluster setup, and network conditions.</p><h3>Final Thoughts</h3><p>Writing Zig wasn’t dramatically harder than Go — manual memory management needs understanding, but the explicitness felt deliberate, not burdensome. For Outboxx’s requirements (minimal footprint, predictable performance), Zig was the right choice.</p><h4>Try Outboxx</h4><p>The project is open source: <a href="https://github.com/lukashes/outboxx">github.com/lukashes/outboxx</a></p><p><strong>Quick start:</strong></p><pre># Using Nix (recommended)<br>nix develop<br>zig build<br><br># Configure and run<br>./outboxx --config config.toml</pre><p><strong>Current status:</strong> Functional and tested in my experiments. Not yet battle-tested at large scale, but actively maintained. I’m continuing to develop this and would love feedback.</p><p><strong>If you try it:</strong> Let me know how it works for your use case. Found a bug? Have suggestions? Open an issue or discussion on GitHub.</p><p><strong>Roadmap includes:</strong> Production observability (OpenTelemetry), Kubernetes deployment manifests, and additional sources/sinks based on community needs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ba4b239ceaf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>