ScyllaDB, from the CPU up
Recently at work, my team put an ~80TB ScyllaDB cluster into production. Being new to ScyllaDB, I was impressed enough by its latency and throughput that I went digging under the hood. What hooked me wasn’t just the database itself—it was Seastar, the C++ engine underneath it, and a radical architectural bet called thread-per-core.
Most high-performance backend systems accept the operating system as a given: the kernel schedules your threads, manages your file cache, and arbitrates access to disk. Seastar asks what happens if you stop letting the OS make those decisions—and build a server from the CPU up instead.
The catch is that you can’t make that choice halfway. Once you make one core bet—pinning a single, non-blocking thread to every CPU core—it sets off a domino effect. Each layer you remove forces you to replace the next one: locks, garbage collection, the kernel page cache, single-queue storage, and even how clients route network requests.
Even if you never run ScyllaDB, this mental model is worth having. The same architecture powers systems like Redpanda (also built on Seastar), Dragonfly, and TigerBeetle—and every chapter below exposes an invisible performance tax that ordinary servers pay every day.
Let’s start at the bottom: a single CPU core.
One core, and the one law of physics
A CPU core is a tiny worker that does one simple thing at a time: fetch an instruction, execute it, move to the next, a few billion times a second. It knows nothing about databases, requests, or users. All it has in front of it are three things:
- A program counter — which instruction it is on.
- Registers — a handful of scratch slots holding the numbers it is operating on right now.
- A private cache — a small, fast copy of the memory it touched recently.
That private cache is the single most important fact in this entire post. Reading from a core’s own cache takes about 1 nanosecond. Fetching the same byte from main memory takes about 100 nanoseconds. The exact same instruction can be a hundred times slower purely because the core hasn’t seen that data lately.
Here is one core answering lookups from a tiny key-value store.
Core 0 program loop
- ▶LOADr1 ← key of the next request1 ns
- ▶HASHr2 ← where that key lives in memory1 ns
- ▶LOADr3 ← memory[r2]1 ns from L1 cache, 100 ns from RAM
- ▶SENDr3 to the client, then back to the top1 ns
Registers
- r1
- –
- r2
- –
- r3
- –
Core 0 L1 Cache
Time per request, last 20
Nothing in the program changed when you emptied the cache. The core executed the exact same four instructions; it simply spent almost all of its time stalled, waiting on main memory to answer.
Now scale that picture up. A modern server isn’t “one really fast computer”—it’s 32, 64, or 128 of these workers, each with its own private cache. From the hardware’s point of view, a fast server is one that keeps every core busy on useful instructions with a warm cache.
Keep this one rule in mind, because every chapter from here on is a consequence of it: emptying a core’s cache—or making it wait—is the cheapest way to make a fast machine slow.
The core bet: taking over the scheduler
In most server software, the application doesn’t decide which core runs what—the operating system does.
You wrap work in threads (a sequence of instructions plus a saved snapshot of registers so a core can pause it and resume it later) and hand them to the OS kernel. A part of the kernel called the scheduler decides which thread runs on which core, and for how long. PostgreSQL gives each connection a process; MySQL, by default, gives each connection a thread; Cassandra uses thread pools. In all of them, the kernel is in charge.
Why not just spawn one thread per core and call it a day? Because in the classic model, threads block. When a thread asks the disk or network for data, it goes to sleep until the answer arrives. Unless another thread is ready to step in, that core sits completely idle.
Fig. 2 starts in that exact state: 4 cores, 4 threads. Every pale gap is a core doing nothing while its thread waits on disk.
Ready queue (waiting for a core)
Blocked on disk I/O
No OS ready queue. Thread 0 owns Core 0, Thread 1 owns Core 1, and so on. Async I/O means threads never sleep—and Seastar schedules tiny tasks inside each core with plain function calls.
Cores, newest tick on the right
- Useful work
- –
- Switches & cold cache
- –
- Idle
- –
- Longest wait for a core
- –
The hidden tax of “just add more threads”
The standard fix for idle cores is to run far more threads than cores so some thread is always ready. That closes the idle gaps, and introduces two silent taxes that show up in almost every production backend:
- Context switches and cold caches (the orange squares). With more ready threads than cores, the scheduler slices time between them. Pausing one thread and loading another costs a microsecond or so directly—but the real bill comes next. The incoming thread wants its data, which isn’t in this core’s cache. Every switch is a miniature Empty the cache from Chapter 1, especially if the thread last ran on a different core.
- Run-queue tail latency. When 32 threads fight over 4 cores, a thread that is ready to do 10 microseconds of work can sit in the ready queue for milliseconds waiting for a turn. Most mysterious p99 latency spikes in normal services come from here: the work was short, the wait for a core was long.
Seastar’s bet: one thread per core
Seastar—the C++ framework ScyllaDB is built on—solves this by giving the OS scheduler nothing to decide:
- One thread per core, pinned at startup. Thread 0 stays on core 0 forever. Its cache stays warm with its own working set.
- Threads never block. Every disk and network operation is asynchronous. A thread fires off an I/O request, immediately moves on to another task, and handles the result via a future/continuation when it comes back.
- User-space scheduling. Inside each core, Seastar runs its own event loop (a reactor) over a queue of small tasks. Switching from one task to the next is a plain function call—no kernel involvement, no register save/restore, no forced cache eviction.
The OS scheduler is still there, of course—it just sees one always-runnable pinned thread per core and stays out of the way.
The trade-off you inherit
The OS scheduler was doing a real job: preemption. If one thread gets stuck in a heavy loop, the kernel forcibly interrupts it so other requests keep moving.
Seastar’s scheduler is cooperative—it cannot interrupt a running task. It has to wait for the task to finish or explicitly yield control. One poorly behaved task (like scanning a huge partition or processing a giant batch without yielding) stalls every other request on that core. In production, ScyllaDB literally logs reactor_stalled warnings when this happens, and Seastar code has to be written carefully to yield inside long loops.
You got rid of the OS tax, and you inherited the OS’s job.
Domino 1: shared memory and locks
In most databases and web servers, all threads share one big pool of memory: one cache, one set of in-memory tables. Any thread can serve any request, which is super convenient.
It also creates a race: two threads modifying the same structure at once will corrupt it. The standard fix is a lock—one thread enters, everyone else waits.
Under a thread-per-core model, locks are a disaster for three reasons:
- Waiting violates rule #2. A thread blocked on a lock is a pinned core doing nothing.
- Cache-line bouncing (Chapter 1 strikes back). Even when a lock is held only briefly, modifying shared data invalidates every other core’s cached copy of it. The next core to touch that data—or even the lock variable itself—has to pull it across the CPU interconnect from the previous core’s cache. Hot shared state turns into a ping-pong ball between cores.
- Preemption while holding a lock (Chapter 2 strikes back). In a normal OS-scheduled server, if the kernel pauses a thread while it holds a lock, every other thread waiting on that lock freezes until the holder is scheduled again.
In Fig. 3, each request needs 8 ticks of work a core can do alone, followed by 1 tick inside a shared table.
Cores, newest tick on the right
Working aloneInside the table / shardWaiting on the lockCache-line bounce across coresIdle (no keys for this shard)
- Requests finished, last 100 ticks
- –
- Core time lost to lock & cache bounce
- –
Scaling ceiling: requests per 100 ticks by core count (even keys)
Shard per core (linear)Shared table + lock (Amdahl ceiling)
Show the chart as a table
With a shared table, throughput climbs at first and then hits a hard ceiling. Once the lock is saturated, extra cores don’t add capacity—they only lengthen the queue and bounce the cache line around faster. That ceiling is Amdahl’s law in action: the tiny serial sliver of your program caps how far the whole machine can scale.
Shared-nothing: a shard per core
If threads can’t share memory without locking, Seastar’s answer is blunt: don’t share memory at all.
Each core owns a completely independent slice of the data—a shard—with its own memory, its own cache, and its own in-memory tables. Every row belongs to exactly one shard, determined by hashing its partition key. Because only one core ever reads or writes that row, there is nothing to lock and the row never bounces out of that core’s cache.
What if core 2 receives a request for a row owned by core 5? It doesn’t reach into core 5’s memory. It drops a message into a lock-free queue for core 5 and immediately moves on to other work; when core 5 finishes, it sends the reply back the same way.
A 64-core server stops behaving like one 64-threaded program and starts behaving like 64 tiny, single-threaded databases talking to each other over in-memory messages.
What this means in practice
Shared-nothing gives you near-linear scaling as you add cores—as long as work spreads evenly across shards.
The trade-off is that shards cannot help each other. If one partition key is 100× hotter than the rest (a celebrity user, a popular tenant, a single “today” bucket), the single core owning that shard pegs at 100% CPU while the other 63 cores sit bored. Throwing a bigger machine at it won’t help at all. Choosing a partition key with high cardinality stops being a nice-to-have and becomes mandatory—and queries that span multiple shards pay message-passing overhead on every hop.
Domino 2: the garbage collector
Cassandra (the database ScyllaDB is API-compatible with) is written in Java, so the answer is the garbage collector. Code allocates freely and never frees anything; periodically the JVM scans for unreachable objects and reclaims their memory.
That convenience has a well-known cost: for parts of the cycle, the collector pauses application threads. When a pause hits, every request currently in flight freezes, and every request arriving during the pause piles up behind it.
Fig. 4 models one core with plenty of spare capacity and one request arriving per tick.
Shard memory in use
One core, newest tick on the right
Serving requestsAll threads frozen for GCServing + tiny LSA compaction step
Latency of last 80 requests (notice p50 vs p99 spikes)
- Median latency (p50)
- –
- Tail latency (p99)
- –
- Requests queued right now
- –
Notice how the typical (median) request barely changes, while the slowest request explodes. This is why averages hide GC damage completely: 98% of your requests look great while your p99 users sit behind a frozen thread and then wait for the backlog to drain.
To be fair, JVM collectors have come a long way. Cassandra 5.0 runs on Java 17, where modern collectors like ZGC and Shenandoah shrink stop-the-world pauses to a few milliseconds or less. They achieve that by doing most of their tracing concurrently alongside the application—which still spends CPU cores and memory headroom that the database could otherwise use for queries.
Per-shard memory without a collector
Seastar is written in C++, so there is no garbage collector. At startup, ScyllaDB claims almost all of the machine’s RAM and divides it equally among the shards. Each shard allocates from its own private pool—which also means even calling malloc requires zero locks across cores.
Manual memory management does bring its own headache: fragmentation. After hours of allocating and freeing variable-sized rows, free memory turns into Swiss cheese—plenty of total free bytes, but scattered in holes too small to fit new objects.
For its two biggest memory consumers—the row cache and in-memory write tables (memtables)—ScyllaDB uses a custom log-structured allocator that can compact and move objects to close those holes. Conceptually, that’s quite close to what a garbage collector does. The difference is who is in charge: instead of an external runtime freezing the world, each shard compacts a tiny slice of its own memory in small, bounded steps, between requests, under Seastar’s own scheduler.
What this means in practice
You get rock-solid tail latency and no JVM heap flags to babysit. In exchange, ScyllaDB’s engineers carry the full complexity and safety risk of manual C++ memory management—and because the process claims nearly all RAM on startup, it’s a terrible roommate. You run it on dedicated machines, not squeezed alongside other memory-hungry services.
Domino 3: bypassing the page cache
Normally, when a program reads a file, Linux silently caches what it read in spare RAM so the next read is fast. This is the kernel page cache. It is one of the best general-purpose features in Linux, and databases like PostgreSQL and Cassandra lean on it heavily.
For a thread-per-core engine, the page cache breaks down in two ways:
- It blocks your pinned thread. If the requested data isn’t in the page cache, a normal
read()puts the calling thread to sleep until the disk responds. We just spent Chapter 2 making sure a core’s single thread never sleeps—one blocking page fault stalls every other request queued on that core. - It caches at the wrong granularity. The kernel doesn’t know what a database row is; it only sees 4 KB file pages. To keep one 200-byte hot row in RAM, Linux has to pin the entire 4 KB page around it, dragging cold neighbouring rows along for the ride.
Fig. 5 shows a disk of 12 pages with 4 rows each, where one row per page is hot. Memory has room for 16 rows either way.
On disk (12 × 4 KB pages, 4 rows each)
In RAM (16 row slots total)
Hot rowCold rowCold neighbour wasting RAMCache hitDisk read (miss)
- Reads served from RAM
- –
- RAM slots holding hot rows
- –
- RAM wasted on cold rows
- –
Same RAM, same workload—wildly different efficiency. Because the page cache has to pull in whole pages, most of your precious memory gets burned on cold neighbours, and misses keep spilling to disk. A database-aware row cache keeps just the hot rows and answers far more reads from memory.
Direct I/O and a unified shard cache
Seastar opens data files with Direct I/O (O_DIRECT), telling the Linux kernel to get out of the way and skip the page cache completely. Every read and write is submitted asynchronously (via Linux AIO by default, with io_uring also supported in Seastar), so the core’s thread never waits.
In place of the kernel page cache, each shard manages its own row cache inside the memory pool from Chapter 4. Because the same pool holds both the row cache (for reads) and memtables (for recent writes), ScyllaDB can dynamically shift RAM between reads and writes as traffic changes—with zero double-buffering between OS memory and app memory.
What this means in practice
You get far more useful cache per gigabyte of RAM, and you don’t have to guess how to split memory between the database heap and the OS page cache.
The catch? First, ScyllaDB had to build and tune a caching layer that Linux gives every other program for free. Second, a restarted node starts completely cold. With PostgreSQL or Cassandra, if the database process crashes and restarts, the Linux page cache is still warm in kernel memory. Because ScyllaDB’s cache lives inside its own process, a restart wipes it clean until traffic warms it back up.
Domino 4: matching the hardware all the way down
For decades, the answer was no. Spinning hard disks had one physical arm, so they did one thing at a time. The SATA interface (and its AHCI protocol) was designed around that reality: a single command queue, 32 slots deep. Even if 64 CPU cores were ready to submit I/O in parallel, they all had to line up behind one shared queue—and take a lock to touch it.
Early SSDs kept the SATA interface for compatibility, which hid a huge mismatch: inside an SSD, there is no spinning arm. There are dozens of independent flash chips (dies) capable of working simultaneously—sitting mostly idle behind a single-file queue.
Cores and their command queues
16 parallel flash dies
Live user readBackground LSM compactionIdle die / empty slot
- Live reads finished, last 100 ticks
- –
- Flash dies busy
- –
- Live read wait time
- –
NVMe threw out the hard-disk assumption. Plugged directly into PCIe (the same high-speed bus GPUs use), NVMe replaces the single queue with many—up to 65,535 in the spec, and plenty on real drives to give every CPU core its own dedicated submission and completion queue. A core submits an I/O command by writing to memory only it touches: no lock, no cross-core traffic.
This is Chapter 3 again, etched into silicon. Seastar’s one-shard-per-core software architecture finally lines up 1-to-1 with NVMe’s one-queue-per-core hardware. From the CPU core all the way down to the flash die, nothing is shared.
One more scheduler in user space
Fast drives introduce a subtle trap: if you throw more commands at an NVMe drive than it can chew through, requests pile up inside the drive’s own controller, where the database can no longer see, prioritize, or cancel them.
That matters because a database isn’t only serving live user reads. ScyllaDB stores data in a log-structured merge (LSM) tree—appending writes to a commit log and memtable, flushing sorted immutable files to disk, and constantly merging (compacting) those files in the background. (Nanda Syahrasyad’s Build Your Own Database builds an LSM tree step by step if you want to see how it works.) Compaction rewrites huge amounts of data; left unchecked, it will saturate the SSD and tank live query latency.
So Seastar measures the exact throughput and concurrency limits of your drive at setup (iotune), and runs an I/O scheduler in user space. It dispatches only as much work as the drive can handle without internal queuing, holding the rest in its own queues so live user reads always cut ahead of background compaction.
What this means in practice
This is where the hardware requirements get real: thread-per-core shines on machines with many cores and local NVMe drives. Put it on a small VM backed by network-attached block storage (like EBS), and half of this machinery has nothing to work with. And because local cloud NVMe drives are ephemeral—stop the instance and the disk vanishes—you can only rely on them because the cluster replicates every row across multiple machines.
The final domino: reaching the right core
First, a quick step back to the cluster level. Many databases pick one machine as a leader that handles all writes and replicates them to followers. That’s simple to reason about, but it caps write throughput at one machine and forces a failover pause if the leader dies.
Like Cassandra and Dynamo before it, ScyllaDB is leaderless on the data path. Every row is replicated across several nodes (typically three), and any node can accept a request—with the client choosing how many replicas must reply (tuning latency vs. consistency).
That creates a routing problem at two levels: which machine owns this row, and which core on that machine owns its shard?
Extra hop (network or cross-core)Owning core (warm cache & shard)
- Avg stops per request
- –
- Avg routing overhead
- –
- Traffic hitting busiest node
- –
If a client sends a request to a random node, it usually lands on the wrong machine (network hop #1), gets forwarded to a node that owns the row, lands on the wrong core there (cross-core hop #2), and gets passed along to the owning shard. Network hops are measured in hundreds of microseconds—orders of magnitude more expensive than anything inside a single CPU.
A shard-aware ScyllaDB driver eliminates every single hop. It learns the cluster’s topology and shard layout, keeps a dedicated TCP connection open to every core of every node, and hashes the partition key client-side. The request leaves the application and lands directly on the exact CPU core that owns the row—where the thread is pinned, the cache is warm, and the NVMe queue is waiting.
Where a leader still makes sense
Even a leaderless database needs every node to agree on who owns what (cluster topology and schema changes). Modern ScyllaDB handles this control plane with Raft, a consensus protocol that does elect a leader—strictly for metadata changes like adding nodes or altering tables, never on the read/write path.
Raft also enabled tablets (default since ScyllaDB 2025.1): smaller, finer-grained slices of data that stream cleanly between nodes one at a time, so a newly added node starts serving traffic as soon as its first tablet arrives.
What this means in practice
Two things bite teams here:
- Don’t accidentally break shard-aware routing. If you connect with a generic Cassandra driver, or stick a naive L4 load balancer between your app and the cluster, you silently throw away direct-to-core routing and pay extra hops on every query.
- No leader means no single arbiter for conflicts. If two clients update the same row through different nodes at the same instant, ScyllaDB resolves it by timestamp (last write wins). Whether that’s safe depends entirely on your domain.
What it adds up to
Seen one piece at a time, ScyllaDB looks like a bag of low-level C++ tricks. Seen from the CPU up, it’s a single domino chain triggered by Seastar’s thread-per-core bet:
| Ch. | The OS / runtime tax removed | What Seastar / ScyllaDB builds instead | The trade-off inherited |
|---|---|---|---|
| 02 | OS scheduler context switches & queues | One pinned thread per core + cooperative reactor | Long tasks stall the whole core |
| 03 | Locks & cross-core cache-line bouncing | Shared-nothing shards + lock-free messages | Hot partition keys peg 1 core; shards can’t help each other |
| 04 | Stop-the-world GC tail latency | Per-shard C++ pools + incremental compaction | Manual memory management; claims nearly all machine RAM |
| 05 | Blocking reads & 4 KB page-cache waste | Direct I/O + async AIO/io_uring + row cache |
Restarted nodes start with an empty cache |
| 06 | Single locked SATA/AHCI disk queue | Per-core NVMe queues + user-space I/O scheduler | Needs local NVMe + many cores to shine |
| 07 | Leader bottlenecks & extra routing hops | Shard-aware drivers routing straight to the owning core | Needs shard-aware clients; last-write-wins conflicts |
What to take back to your own systems
Even if you never touch ScyllaDB, this architecture is a useful lens for debugging and designing ordinary software:
- Most tail latency isn’t slow code—it’s waiting. Waiting in an OS run queue, waiting on a lock, waiting behind a GC pause, or waiting on a congested disk queue. When p99 blows up while p50 looks fine, look for queues and pauses before micro-optimizing business logic.
- The OS abstractions exist for a reason. Replacing the scheduler, allocator, page cache, and I/O scheduler only pays off when your entire product is a single, hardware-bound engine (a database, a message broker like Redpanda, a high-throughput proxy). For 99% of business applications, letting Linux and a garbage collector do their job is the right call.
- Mechanical sympathy compounds—or breaks—at the seams. Thread-per-core only delivers its full payoff when the entire path aligns: hardware (multi-core + NVMe), engine (Seastar), data model (well-distributed partition keys), and client (shard-aware driver). Break one link—a hot key, a blocking call, a non-shard-aware client—and the bottlenecks come right back.
(One last caveat: the figures in this post are simplified models that exaggerate each cost so you can see the mechanism clearly, and many public ScyllaDB-vs-Cassandra benchmarks come from the vendor itself. As always, measure on your own workload.)
Some food for thought: can we make it even faster?
Once you strip away the OS scheduler, locks, garbage collection, the page cache, and single-queue storage, a natural question pops up: why stop at C++? Could we build a dedicated database ASIC—a “TPU for databases”—to make this 100× faster still?
Probably not in the way TPUs accelerated AI, and the reason goes right back to Chapter 1.
AI workloads are compute-bound: they perform thousands of math operations for every byte fetched from memory, so packing specialized matrix units onto custom silicon produces huge leaps. An OLTP database like ScyllaDB is data-movement bound. Even if you built a magical 0-nanosecond chip for every CPU instruction, a cache miss still waits ~100 ns for DRAM, a disk miss still waits ~50–100 µs for NAND flash, and a replicated write still waits ~100–300 µs for the network. Once Seastar gets the software out of the way, you’re already bumping into the speed of memory, flash, and light in fiber.
Where specialized hardware can push further isn’t replacing the CPU—it’s offloading data movement and housekeeping:
- Bypassing the network stack (DPDK, SmartNICs, and RDMA). Seastar already supports DPDK to bypass Linux’s TCP stack the same way it bypasses the page cache. Go a step further with SmartNICs/DPUs and RDMA, and a client can read remote shard memory directly without even waking up the remote CPU—shrinking network hops from hundreds of microseconds to single-digit microseconds.
- Computational storage. Remember Chapter 6’s LSM compaction? Merging files means hauling terabytes off flash, across PCIe, through the CPU, and writing them right back. Putting an FPGA or ASIC directly inside the SSD controller lets the drive run compaction, compression, and filtering in place without burning CPU or PCIe bandwidth.
- Fixed-function offload. Dedicated silicon for TLS encryption, CRC checksums, and LZ4/Zstd compression already frees up meaningful core time without needing a whole custom database chip.
Building a full custom OLTP chip rarely pencils out economically—taping out silicon costs tens of millions and takes years, while query engines and storage formats keep evolving. The real lesson of Seastar is that commodity hardware is already ridiculously fast; most of the time, the biggest wins come from stopping our software from getting in its way.
Sources
- Build Your Own Database, Nanda Syahrasyad. The inspiration for this post’s interactive format, and a great walkthrough of LSM trees.
- Seastar, the open-source C++ shared-nothing framework underlying ScyllaDB and Redpanda.
- Thread pool, Percona Server documentation. MySQL’s default of one thread per connection.
- Thread and task architecture guide, Microsoft. SQL Server’s cooperative scheduler.
- Memory management, ScyllaDB. Per-core memory and the split between cache and memtables.
- Java Virtual Machine, AxonOps Cassandra documentation. Supported Java versions and collector pause times.
- Inside ScyllaDB’s internal cache, ScyllaDB. Why it bypasses the page cache.
- reactor: add io_uring backend, seastar-dev mailing list. Linux AIO as the preferred backend.
- What makes NVMe architecture so efficient?, NVM Express. Queue limits.
- Overview of NVMe architecture, Oracle Linux blog. Queue counts on real drives.
- Connect faster to ScyllaDB with a shard-aware port, ScyllaDB. How drivers reach a specific core.
- Announcing ScyllaDB 2025.1, ScyllaDB. Tablets by default.
- Safe topology and schema changes on Raft, ScyllaDB. What Raft manages.