When I started building systems, my primary motivation was to understand what happens underneath the abstractions we use every day.

How does a database actually persist data? Why do storage engines use different indexing structures? How does the operating system manage file-backed memory? Why does adding more threads sometimes make an application slower rather than faster?

Initially, these seemed like isolated engineering problems. But as I worked on storage engines, distributed search systems, and concurrent applications, I started noticing something interesting.

The principles governing low-level systems are often the same principles behind high-level system design.

Understanding them from the ground up made several architectural decisions that previously seemed arbitrary feel almost intuitive.

Here are some of the connections I discovered along the way.

1. mmap vs pread + LRU: Choosing How Data Enters Memory

One of the interesting decisions I encountered while building storage systems was choosing between memory-mapped files and explicit file reads.

Both approaches allow applications to access data stored on disk, but they offer fundamentally different models.

With mmap, a file is mapped into a process's virtual address space. Instead of explicitly reading blocks into application-managed buffers, the application accesses the mapped region as if it were memory. The operating system handles page loading through page faults and the page cache.

This is particularly useful when data is already stored in a representation that can be consumed directly.

I encountered this while building Turbo Query, a distributed hybrid search engine combining BM25 with semantic reranking using MiniLM embeddings.

Each document has an associated 384-dimensional embedding. These vectors are stored as contiguous floating-point arrays in a binary file.

During a search, BM25 first retrieves a relatively small set of candidate documents. Instead of loading the entire vector dataset into application memory, I use mmap to access the corresponding vectors directly and calculate cosine similarity for semantic reranking.

This makes memory-mapped access a natural fit for the workload.

The data is already in the representation required by the computation. There is no need to deserialize the entire vector store into another in-memory structure.

mmap has costs too, which the CIDR 2022 paper "Are You Sure You Want to Use MMAP in Your DBMS?" (Crotty, Leis, Pavlo) covers well. A read can silently stall while the operating system fetches data from disk, and my code can't see when that happens. The OS also decides what stays in memory, not me. If a read fails, the program can crash instead of getting an error it can handle. And since the file is just raw bytes, I have to be careful that they are interpreted as numbers correctly. I accepted these costs for Turbo Query because the vectors are read-only, fixed-size, and already in the layout the similarity computation needs.

On the other hand, pread provides explicit control over reading data into application-managed buffers at specified file offsets.

Combined with an LRU cache, this becomes useful when the application needs more control over what gets loaded, retained, evicted, and processed.

In BedrockDB, an LSM-tree-based storage engine, records are persisted in an encoded representation. Accessing a record involves reading the relevant data from disk, decoding it, and reconstructing its in-memory representation before it can be consumed.

An explicit pread + LRU approach provides greater control over block reads, buffer management, and caching. Frequently accessed blocks can remain in memory, avoiding repeated disk reads.

The distinction isn't that one approach is universally faster than the other.

It depends on the data representation, access pattern, memory constraints, and processing requirements.

If data can be consumed directly in its stored representation, mmap can be a natural choice. If access requires explicit loading, transformation, and buffer management, pread + LRU can offer greater control.

2. Why More Parallelism Can Sometimes Hurt Performance

One of the most interesting lessons from building Turbo Query came from optimizing concurrency.

The initial assumption was straightforward: more concurrent workers should translate into higher throughput.

But that isn't necessarily true.

Parallelism is particularly effective when workloads are compute-bound. If multiple independent tasks require substantial CPU computation, distributing them across available cores can improve throughput. Think of a GPU. Its architecture is designed to execute thousands of operations concurrently, making it particularly effective for highly parallel computational workloads such as matrix multiplication, image processing, and neural network inference.

However, memory-bound workloads behave differently.

Consider what happens when multiple workers continuously access large regions of memory.

Eventually, the bottleneck might not be CPU availability. It might be memory bandwidth, cache misses, or contention within the memory subsystem.

Adding more workers can increase competition for shared resources instead of improving useful work completed per second.

I encountered this while working on Turbo Query.

The search engine uses Bleve for BM25 retrieval and memory-mapped vector storage for semantic reranking.

During performance testing, I observed significant latency fluctuations under unrestricted concurrency. Bleve latency varied from approximately 4 ms to 400 ms.

Instead of continuing to increase concurrency, I introduced bounded parallelism using a semaphore initialized with four permits.

This limited the number of concurrent workers accessing the workload.

The observed latency subsequently stabilized around 3–5 ms.

The important realization was that unrestricted concurrency was introducing more contention than useful parallelism.

Several factors can contribute to this behaviour:

  • Increased context switching.
  • Cache and TLB pressure.
  • Memory-system contention.
  • Competition for shared resources.
  • Additional synchronization overhead.

The solution wasn't to maximize the number of concurrent operations. It was to find a concurrency level that allowed the system to operate efficiently.

This is particularly important for memory-bound workloads, where additional CPU workers cannot necessarily increase the rate at which data is supplied from memory.

There is another interesting connection here.

This is the same reasoning behind bounded worker pools, connection pools, and backpressure mechanisms in distributed systems.

We don't want an application to accept unlimited work simply because it can create more goroutines or threads.

We want to control how much work enters the system at a time.

Concurrency is a resource that needs to be managed, not a number that should always be maximized.

3. fsync Batching: Amortizing Expensive Operations

Another interesting lesson came from understanding durable writes.

Writing data to a file and ensuring that it has reached persistent storage are two different things.

An fsync operation requests synchronization of modified file data and relevant metadata with the underlying storage device.

However, synchronization operations can be expensive.

Consider a workload where every individual write is followed by an fsync.

If we perform 100 writes, we might end up paying the synchronization cost 100 times.

An alternative is to batch multiple writes and synchronize them together.

Instead of:

Write → fsync

Write → fsync

Write → fsync

We can do:

Write → Write → Write → fsync

This is closely related to group commit in database systems.

The underlying idea is simple: amortize the cost of an expensive operation across multiple units of useful work.

Of course, batching introduces a trade-off. Individual writes may have to wait longer before becoming durable, and the system must account for the consequences of a crash before synchronization completes.

But the throughput improvement can be substantial.

This principle extends far beyond storage systems.

We see similar ideas in:

  • Batch database inserts.
  • Bulk API operations.
  • Message batching.
  • Network packet aggregation.
  • Distributed data processing.

Sometimes, optimizing a system isn't about making an individual operation cheaper. It is about making each expensive operation accomplish more work.

4. LSM Trees vs B-Trees: Architecture Follows Workload

Building and understanding storage engines also changed how I think about database selection.

A common oversimplification is that B-trees belong to SQL databases and LSM trees belong to NoSQL databases.

The actual distinction is much more interesting.

B-trees and LSM trees represent different approaches to organizing persistent data.

B-trees support efficient lookups and updates through a page-oriented indexing structure. They are widely used in databases that need balanced read and write performance.

LSM trees optimize write paths by accumulating updates in memory and flushing them to disk as sorted structures. These structures are subsequently merged through compaction.

This makes LSM-based storage engines particularly attractive for write-intensive workloads.

However, they introduce trade-offs involving read amplification, write amplification, and compaction overhead.

The important distinction is the workload, not whether the database exposes SQL or NoSQL interfaces.

Modern NoSQL databases can also provide strong consistency guarantees. Consistency is a property of the database's architecture and configuration, not simply its query language.

Understanding B-trees and LSM trees taught me to evaluate databases based on their underlying storage characteristics rather than their labels.

5. Sequential Writes vs In-Place Writes

This connects directly to the previous section.

Traditional in-place update strategies modify existing data structures on disk. Depending on the storage engine, this can involve random I/O and additional coordination.

LSM-based systems take a different approach.

Instead of repeatedly modifying existing disk structures, they favor sequential writes to new storage files, followed by background compaction.

Why is this useful?

Sequential I/O generally provides more predictable and efficient storage access patterns than scattered random writes, particularly on traditional storage devices.

It also simplifies certain aspects of write-path design.

But this doesn't mean sequential writes are universally superior. Compaction introduces additional I/O, and the system must manage multiple versions of data until they are merged.

The broader lesson is that storage architecture is fundamentally about managing the cost of moving data between memory and persistent storage.

Once you understand that, many database design decisions become easier to reason about.

6. From WAL to Kafka: Recognizing the Same Abstraction

Perhaps the most interesting connection I made was between implementing a Write-Ahead Log in BedrockDB and understanding Kafka.

A Write-Ahead Log, or WAL, is a mechanism used by storage engines to ensure recoverability.

Before modifying the primary in-memory or on-disk representation of data, changes are recorded in a sequential log.

A simplified workflow looks like this:

  1. Receive a write request.
  2. Append the operation to the WAL.
  3. Ensure the required durability guarantees are met.
  4. Apply the change to the in-memory data structure.
  5. Recover the state by replaying the log after a failure, if necessary.

Having implemented the WAL in BedrockDB, I began recognizing the same underlying abstraction when I studied Kafka: the append-only log.

Kafka.

Kafka organizes messages into append-only, partitioned logs. Producers append records, consumers read them sequentially, and the system maintains offsets to track consumption.

Kafka is not simply a database WAL. Their responsibilities, retention models, and recovery semantics differ.

However, understanding the WAL made Kafka's underlying storage abstraction much easier to understand.

The common idea is the append-only log.

Instead of treating updates as isolated modifications, represent changes as an ordered sequence of records.

This is a powerful abstraction that appears in databases, event sourcing, distributed logs, and recovery systems.

One concept learned while building a storage engine suddenly became useful for understanding a completely different system.

7. Why Systems Knowledge Makes System Design More Intuitive

This is probably the biggest takeaway from building these systems.

We often approach system design as a collection of architectural patterns.

Caching, sharding, replication, message queues, load balancing, database selection, and horizontal scaling.

We learn when to use Redis, when to introduce Kafka, when to partition a database, and when to add more application instances.

But understanding the underlying systems changes the way we approach these decisions.

Consider a few examples:

Low-level systems concept High-level system design connection
mmap and page cache OS-managed caching & zero-copy reads
pread + LRU Explicit buffer management and caching
Bounded parallelism Worker pools and backpressure
Memory bandwidth contention Concurrency and resource bottlenecks
fsync batching Batch processing and group commit
LSM trees Write-optimized storage engines
B-trees Efficient indexing and read-heavy workloads
Sequential writes Append-only storage architectures
Write-Ahead Log Kafka's append-only log abstraction

These aren't merely superficial similarities.

They are manifestations of recurring engineering principles.

When you understand why sequential writes are useful, you have a better foundation for understanding append-only architectures.

When you understand why LRU caching works, Redis eviction policies become easier to reason about.

When you understand why fsync batching improves throughput, database group commit and bulk processing make more sense.

When you understand memory bandwidth limitations, you become more careful about introducing parallelism into a workload.

The abstractions change, but many of the underlying constraints remain.

There are, of course, additional complexities at higher levels. Distributed systems introduce network partitions, replication, consensus, failure recovery, and consistency challenges that cannot be reduced to operating-system concepts.

But having a foundation in systems programming makes reasoning about these architectures considerably easier.

Closing Thoughts

I initially started building systems to understand how things worked underneath the abstractions.

What I didn't expect was how much that experience would change the way I understood software architecture.

Building a storage engine taught me about WALs. Understanding WALs helped me understand Kafka. Working with memory-mapped files taught me about the operating system's memory management. Implementing LRU caching helped me reason about application-level caching. Optimizing Turbo Query taught me that unrestricted parallelism can sometimes hurt performance rather than improve it.

These connections gradually changed my approach to engineering.

I no longer see system design as memorizing a collection of architectural patterns and knowing when to apply them.

I see it as understanding constraints, identifying bottlenecks, evaluating trade-offs, and choosing an architecture that fits the workload.

The more I learned about how systems work underneath, the more naturally I began to understand how to design them at a higher level.

And perhaps that is one of the most valuable things about building systems from the ground up: you don't just learn how to implement them. You develop an intuition for why they are designed the way they are.