Skip to main content
← PROBLEMS / ARCHITECTURE
An end-to-end domain learning journey

Design an In-Memory Multi-Core OLTP Index Engine
with Adaptive Radix Trees & Epoch Reclamation.

Pair ART (Node4/16/48/256) with Optimistic Lock Coupling (OLC) for zero-write read paths and Epoch-Based Reclamation (EBR) with bounded limbo-list reclamation.
Start the journey5 stages· Last modified Nov 26, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When designing a multi-core OLTP index, pair ART + OLC with 3-epoch EBR and shrink hysteresis to prevent cache-line bouncing and allocator thrashing.

TL;DR30-second simplified summary
▾

Embedding a 64-bit OLC version word in ART's 20-byte header keeps reads write-free, while 3-epoch EBR safely frees obsolete nodes after grow/shrink without per-hop memory fences.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Adaptive Radix Trees (ART)
Know Node4/16/48/256 layouts, path compression, and why OLC uses version counters instead of reader locks.
Memory Reclamation (EBR / Hazard Pointers)
Understand why lock-free/optimistic readers cannot allow writers to free() a replaced node immediately.
Full walkthrough · 5 stages
01
L4 · FUNDAMENTALS

R & E · Requirements, Memory Budget & Latency Math.

With 500M keys and a 500 ns p99 lookup budget, you can afford at most 4–5 DRAM cache misses (~70–90 ns each) per lookup—leaving zero room for lock contention.

Illustrative Memory Sizing: At ~48–60 bytes per key including inner nodes + 8-byte leaf pointers, 500M keys occupy ~24–30 GB of DRAM for inner structure plus leaf payloads—easily fitting inside a single 256 GB–512 GB dual-socket server, compared to ~100+ GB for a naive 256-way trie.

Multi-Core Scaling

Shared RWLock Contention vs. Optimistic Lock Coupling (OLC)

Before · Per-Node RWLock
  • Readers dirty shared cache line
  • 64 cores serialize at root
  • <2M ops/sec ceiling
After · ART + OLC + EBR
  • Zero memory writes on reads
  • Linear scaling across 64 cores
  • <500 ns p99 lookup
02
L4 · FUNDAMENTALS

S · Storage & Cache-Aligned Node Headers.

Every ART inner node starts with a compact 16-byte header so the CPU fetches the version word, node type, and compressed prefix in the exact same 64-byte cache line.

Header layout: uint64_t version_lock_obsolete (8B: bit 0 = lock, bit 1 = obsolete, bits 2..63 = monotonic version), uint8_t type (Node4/16/48/256), uint8_t count, uint16_t prefix_len, and uint8_t prefix[8] (8B inline compressed prefix). Total header = 20 bytes.

64-Byte Cache-Line Header

20B OLC Header + Adaptive Child Payload

03
L5 · APPLIED DESIGN

H & A · High-Level Engine & OLC Traversal Contract.

Every lookup or range scan begins by registering the worker thread's current epoch (EbrGuard) and reading the root node's version.

During traversal, before dereferencing child = parent.find_child(byte), the reader checks parent.read_unlock_or_restart(v_parent). Only after confirming parent was untouched does it load v_child and descend—this is 'lock coupling' without holding any read locks!

OLC Read Coupling

Epoch-Guarded Optimistic Descent & Version Validation

Worker ThreadEBR EpochParent NodeChild Node1. Enter active epoch e2. Load v_p, find child ptr3. Validate v_p unchanged4. Load v_c & descend
04
L5 · APPLIED DESIGN

D · Detailed Design: Node Grow/Shrink & Epoch Reclamation.

A writer cannot call delete old_node immediately after swapping a Node4 for a Node16, because an optimistic reader might still be inspecting old_node before its validation check.

With 3-epoch EBR (e, e-1, e-2), each worker keeps a local limbo list of retired nodes tagged with the epoch e when they were retired. Periodically, a thread scans all active threads' announced epochs; once min_active_epoch >= e + 2, every node retired in epoch e is guaranteed unreachable by any reader and is freed in batch.

EBR Limbo Lifecycle

Active -> Obsolete + Retired -> Epoch Advance -> Safe Free

grow / shrinkpush to limbo[e]all readers > e+1Live NodeObsolete (Swapped)EBR Limbo (Epoche)Freed (min_e >=e+2)
Engineering Decision Framework
Problem
How to safely reclaim retired ART nodes without slowing down optimistic readers.
Naive Solution
Immediately free() replaced nodes or use per-pointer Hazard Pointers on every hop.
Why It Fails
Immediate free() causes segfaults on concurrent OLC readers; Hazard Pointers require an expensive atomic store + memory fence (MFENCE) at every single tree level.
Alternatives
Reference counting vs. Hazard Pointers vs. 3-Epoch Based Reclamation (EBR).
Engineering Decision
Use 3-Epoch Based Reclamation (EBR) with hysteresis on node shrink and a bounded-epoch stall check.
Trade-Offs
Amortizes reclamation overhead to once per operation batch (zero fences inside tree traversal), assuming workers do not block inside an epoch guard.
Decision Exercise · Make the Call

During a bulk delete workload, a worker thread enters an EBR epoch guard, then makes a slow synchronous HTTP call to an external service before exiting the guard. What happens to the 64-core OLTP index?

05
L6 · SCALE & TRADE-OFFS

E & D · Evaluation, Assumptions, Limitations & Glossary.

This design assumes all index data fits in DRAM on a cache-coherent NUMA server and that threads exit EBR guards within microseconds.

Assumptions & Limitations: Memory estimates (~24–30 GB for 500M keys) assume moderate key prefix sharing and exclude WAL/MVCC tuple payloads. Under extreme skew where 64 writers continuously resize the exact same Node4/Node16, OLC read restarts can spike; falling back to a brief shared read lock after K=8 restarts guarantees bounded tail latency.

End-to-End OLTP Index

OLC Workers -> ART Adaptive Nodes -> EBR Limbo -> Slab Allocator

64 Core WorkersingressOLC Version EnginecomputeART (4/16/48/256)storage3-Epoch EBR + Slabcontrolepoch guard + readSIMD / lock coupleretire & batch free
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why does an OLC-based ART engine use a shrink hysteresis threshold (e.g., grow Node16->48 at 17 keys, shrink Node48->16 at 12 keys)?

Recommended Learning Flow