← Lessons

quiz vs the machine

Platinum1820

Concurrency

The Disruptor Ring Buffer

A lock free preallocated ring that hands off events at extreme speed.

6 min read · advanced · beat Platinum to climb

The Disruptor Ring Buffer

The Disruptor is a high performance inter thread messaging library built around a ring buffer, a fixed size circular array of preallocated slots. It was created at LMAX to process millions of trades per second on a single thread, and it avoids the costs that plague queue based handoffs.

Traditional concurrent queues suffer from lock contention, frequent allocation, and false sharing where unrelated variables share a cache line. The Disruptor sidesteps these:

  • Preallocation Slots are filled once at startup, so there is no garbage during steady state.
  • Sequence counters Producers and consumers track a monotonic sequence number. A producer claims the next slot; consumers follow behind, never passing the producer.
  • Lock free coordination Progress uses atomic sequence updates and busy waiting instead of locks, often with memory padding to defeat false sharing.

Multiple consumers can form a dependency graph. For example a journaling consumer and a replication consumer both read each event before a business logic consumer proceeds, all reading the same slot without copying. Because the buffer wraps, the producer must wait if it would overrun the slowest consumer, giving natural backpressure.

The result is mechanical sympathy: data stays in cache, branches are predictable, and throughput reaches tens of millions of events per second.

Key idea

The Disruptor uses a preallocated lock free ring buffer with sequence counters to hand off events at very high throughput with low latency.

Check yourself

Answer to earn rating on the learn ladder.

1. How does the Disruptor avoid garbage during steady state?

2. What provides natural backpressure in the Disruptor?