Engineering Notes

Short engineering notes on the systems ideas I am actively learning and building with. Concise by design.

Envoy's xDS control plane: how config reaches the data plane networking

xDS (discovery services) is the API by which a control plane pushes configuration to data-plane Envoy instances. The key insight: Envoy doesn't pull config on a schedule — it opens a long-lived gRPC stream to the management server and receives incremental updates. This is the Aggregated Discovery Service (ADS) pattern.

Resource types: LDS (listeners), RDS (routes), CDS (clusters), EDS (endpoints). The dependency order matters: LDS references RDS, RDS references CDS, CDS references EDS. ADS serializes updates so Envoy doesn't get a route pointing to a cluster it hasn't heard about yet.

Relevant for: service mesh control planes (Istio Pilot, Linkerd), Databricks Traffic Platform, any large-scale proxy fleet management.

Why taint tracking applies to LLM tool calls security

Taint analysis, a classical program analysis technique, tracks whether untrusted data can flow to sensitive sinks without being sanitized. The same model applies cleanly to tool-using LLM agents.

In classic taint analysis: source (user input) → propagation (through program logic) → sink (SQL query, shell exec). The question is whether untrusted source data reaches a dangerous sink unsanitized.

In LLM tool-use: source (untrusted document retrieved by a tool) → propagation (LLM processes and reasons over it) → sink (another tool call, e.g., writing a file, running code, exfiltrating memory). The attack is prompt injection — malicious instructions embedded in retrieved documents hijack the agent's next action.

LLMFirewall implements taint tracking by assigning a trust level to each document the agent reads, then checking whether high-capability tool calls (file writes, shell execution) are being triggered with arguments that seem to contain injected instructions rather than agent-generated content.

SPSC queues: why the lock-free ring buffer works systems

A single-producer single-consumer (SPSC) ring buffer is the canonical lock-free queue for high-throughput pipelines. The core insight: if only one thread writes the head pointer and only one thread reads the tail pointer, you never need a lock — you only need to ensure the writes are visible in the right order.

Implementation: circular array of capacity N. Producer writes to buf[head % N], then increments head with a release store. Consumer reads buf[tail % N], checks that head != tail with an acquire load, then increments tail with a release store. The acquire/release pairing ensures the data write is visible before the index update, and the index update is visible before the consumer reads.

Why it works for LOB: market data events flow from the network receive thread to the matching engine thread. SPSC eliminates all lock contention on the critical path. Cache line alignment of head and tail prevents false sharing — the two threads never fight over the same cache line.

ARIES recovery in one page databases

ARIES (Algorithm for Recovery and Isolation Exploiting Semantics) is the standard WAL-based recovery algorithm used by most commercial databases. Three phases on restart:

Analysis: Scan log forward from the last checkpoint. Reconstruct the dirty page table (pages modified but not yet written to disk) and the transaction table (active transactions at crash time). This tells you what needs to be redone and what transactions were in-flight.

Redo: Replay history forward from the earliest LSN in the dirty page table. Every logged action is redone, even from transactions that will later be aborted. This restores the database to its exact pre-crash state.

Undo: Roll back all transactions that were active at crash time (loser transactions). Undo is logged (CLRs — compensation log records) so undo itself is idempotent on a second crash.

Key invariant: write-ahead logging — the log record for a page modification must hit disk before the modified page does. This is what makes redo correct after a crash mid-write.

Why short-circuit codegen is easy to get wrong compilers

Short-circuit evaluation for && and || is simple to implement naively but breaks down in the presence of nested conditionals and control flow merges.

The naive approach: emit a conditional branch at each && / || operand, jumping to a "false" or "true" label. The problem is that multiple branches need to merge to a single result before the outer expression can continue, and that merge point gets confused when the same variable appears in multiple sub-expressions with different liveness states.

The clean solution is to compile boolean expressions with an explicit "destination" parameter — either a "true branch" label or a "false branch" label — and thread this through the recursion. Each subexpression knows where to jump on success and where to jump on failure, avoiding the need for a merge point entirely. This is the "backpatching" or "destination-passing" style used in most production compilers.

Covered in CS 164 (Compilers) at Berkeley. Easy to see why it matters when you hit your first spec test for nested && inside an if inside another &&.