Recently while studying 3fs, I learned that it uses CRAQ (Chain Replication with Apportioned Queries) as its replication algorithm. Coincidentally, I had similar requirements at work, so I’m documenting my understanding of CRAQ here. CRAQ is already a quite popular engineering solution for replication in object storage or KV systems. CRAQ can be viewed as a simple enhancement to traditional…
Recently, I’ve been delving into the architecture of production-grade inference engines. While projects like vLLM and SGLang are crazy sophisticated, their complexity can make detailed code tracing difficult. Over the holidays, I came across nano-vllm—a tightly scoped codebase that still delivers end-to-end support for Page Attention and scheduling. I took a deep dive into its internals and…
Recently I followed this tutorial to implement a basic Q-Learning reinforcement learning algorithm for Flappy Bird, which surprisingly worked quite well, reaching over 10,000 points. Q-Learning essentially estimates a value $Q(s, a)$ for each state-action pair $(s, a)$, and then selects actions based on these $Q$ values. Deep Q-Network (DQN) builds on basic Q-Learning by adding a neural network to…
Diffusion Model is undoubtedly the SOTA in image generation right now. When looking for resources to learn about Diffusion Model, most articles I found were packed with heavy math, like ELBO derivations, which were too tough for me. This article tries to avoid those concepts and focuses solely on the intuition behind it. Idea In VAE, image generation is seen as sampling from a Gaussian…
In the last blog, I went over the intuition behind VAE, which was pretty straightforward. However, when reading articles about the math behind VAE, I always felt something was missing. So, I spent two weeks (except for eating and sleeping) working through the math until I finally got the formulas down. The whole process was quite challenging for someone with my math background, so I’m…
Recently, I wanted to learn about Stable Diffusion, but it seemed like I needed to first understand what VAE (Variational Autoencoder) is all about. Here, I’ll jot down my naive understanding of VAE. I haven’t fully grasped the math behind ELBO yet, so I’ll note that separately later. The article “Intuitively Understanding Variational Autoencoders” does a great job…
I didn’t pay much attention to Spilling before because an article about Presto mentioned that Facebook didn’t enable it in production. Given Facebook’s massive cluster size, memory can be considered infinite. The maintenance cost of adding extra disks to compute nodes might outweighs the benefits of Spilling. However, recently I encountered some OOM cases. Without…
Recently, I wanted to learn about the postgres ecosystem. I didn’t quite get its MVCC mechanism before, so I’m trying to understand it again. For now, I’ll ignore the concurrency control and cleanup parts of MVCC and just focus on the Snapshot part. Tuple Postgres doesn’t have MySQL’s UNDO log. Multi-version data (Tuples) are stored directly in the tablespace with…
We learned earlier that data in ClickHouse doesn’t support updates, only insertions. If the same primary key has updates, it results in two rows in the table. That’s where ReplacingMergeTree from the MergeTree family comes in. It can do some merging during compaction to clean up duplicate data, leaving only the latest data for the primary key. Sounds good, right? But during contiguous…
First off, I thought MergeTree was just like leveldb’s LSM, but after digging into ClickHouse’s MergeTree, I couldn’t find any of the familiar stuff, and I was confused for a while. First, leveldb’s LSM has WAL + MemTable + SSTable. When reading data, each level has an iterator that forms a MergeIterator, reflecting the latest updates. Running compaction mainly cleans up…
My impression about Percolator was that it could enable transactional capabilities on a regular distributed KV store, but the overhead of the 2PC + Raft process was significant. A few days ago, I heard that CockroachDB (CRDB) has made some engineering optimizations compared to Percolator. I decided to learn about these implementation ideas. Similar to Percolator, CRDB also implements decentralized…
RocksDB supports two concurrency control modes: PessimisticTransactionDB and OptimisticTransactionDB. Both seem to be external wrappers around the DB object, implementing concurrency control outside of storage. This allows applications to perform transactional KV read and write operations through BEGIN, COMMIT, and ROLLBACK APIs. RocksDB inherently supports atomic write capabilities with…
Badger is an open-source LSM Tree KV engine developed by dgraph. Compared to leveldb, it introduced various improvements such as KV separation, transactions, and concurrent compactions, making it a more production-ready storage engine in the Go ecosystem. Let’s take a look at its transaction implementation. Badger implements optimistic concurrency control (OCC) transactions with Serializable…
All write operations in LevelDB, including Put and Delete are unified and recorded in the WriteBatch structure, then passed through the Write function as the only entry point for write operations: Status DB::Put(const WriteOptions& opt, const Slice& key, const Slice& value) { WriteBatch batch; batch.Put(key, value); return Write(opt, &batch); } Status DB::Delete(const WriteOptions& opt, const…
ZGC is a new garbage collector introduced in jdk11, promising pause times of no more than 10ms, and these pauses are independent of heap size, supporting heaps up to terabytes. As a fan of Go, you might think Go’s GC is already pretty good, right? It only has a little STW during Initial Mark, and regular GC pauses are usually under a millisecond? In reality, Go’s GC is still far from…
Prometheus is the most popular monitoring solution today. It can scrape metrics from various targets and store them in a time series database, providing flexible aggregation and query capabilities. This article attempts to organize the storage and indexing structure of Prometheus, understanding how it supports complex aggregation queries. Storage of Time Series Data In Prometheus’s…
Kafka’s data reliability totally depends on replication instead of a single-machine fsync. To put it simply, Kafka Replication is designed like this: Partition is the basic unit of replication. Each Partition has multiple Replicas, one of which is the Leader. The Leader handles all read and write interactions with Consumers, while Followers pull data from the Leader via Fetch RPC. The…
Graceful Shutdown is supposed to be a solved problem, especially for HTTP transports, where the details had already been handled properly by the application servers. However, I never thought carefully about how to implement graceful shutdown in the context of long-lived TCP connections. Let me have a study about the details on it. Graceful Shutdown in gunicorn First, let’s review the process…
The term “version” in LevelDB is a bit weird. Actually, it refers to the metadata of LevelDB: which sstable files are in each Level, and which WAL files are there. Whenever a new sstable is generated due to compaction, this metadata changes accordingly. Changes to this metadata must be logged (in the MANIFEST file) for crash recovery. LevelDB allows others to access the database using…
Container networking has changed a bit compared to the past virtualization of virtual machine networks. In the past, virtual machine network virtualization had to simulate NIC devices and the hardware details of virtual network cards. In the container era, network virtualization will reuse more of Linux’s existed network devices, which can be routed at the third layer of the protocol stack…
Recently, I went through the mruby GC and basically figured out the logic. Besides patching up some comments, I’ll jot down a quick note here. Tri-color GC If you’ve worked with Rails, you might remember that the main issue with traditional Mark-Sweep is the uncontrollable collection time [1]. If you’re unlucky enough to catch a GC, page latency can be pretty high. mruby, like…
Hi, I’m Yazhou Li. I’m a software engineer who loves building distributed architectures and exploring AI/LLM systems. This blog is where I record experiments, practical notes, and the lessons I pick up. Thanks for reading—feel free to reach out if something resonates. You can also find me on: 🐙 GitHub 🐦 X 🌐 Bluesky 📷 Instagram 💼 LinkedIn
Feel free to DM me on X if you’d like to exchange links! KC的废墟堆 CodeColorist Lieo 猫·仁波切 熊叔 Davelv Xuanwo’s Blog 邹扒皮实验室 银色子弹 风空之岛 xiaohanyu 飞林沙 Reus Reflector hotteran huangz chain