# abc-arbitrage/disruptor-cpp architecture

> Architecture diagram of the GitHub repository abc-arbitrage/disruptor-cpp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abc-arbitrage/disruptor-cpp
- Repository: https://github.com/abc-arbitrage/disruptor-cpp

## Overview

#### Purpose and Build Surface
Disruptor-cpp is a C++ port of LMAX Disruptor: an in-process, low-latency concurrent event pipeline built around preallocated ring buffers and sequence coordination. The root build defines the library and optional test/performance targets: `CMakeLists.txt`, `Disruptor/CMakeLists.txt`, `Disruptor.cmake`. Primary consumable API is header-centric under `Disruptor/`; no network, database, or web-service boundary exists.

#### Application Entry Points
Library users construct `Disruptor::disruptor<T>`, register handlers, start a scheduler, publish into its ring buffer, then shut down. The fluent orchestration entry point is `Disruptor/Disruptor.h`; the storage/publishing surface is `Disruptor/RingBuffer.h`. Executable entry points are benchmark runner `Disruptor.PerfTests/main.cpp` and unit-test runner `Disruptor.Tests/main.cpp`.

#### Event Storage and Publication
`RingBuffer<T>` owns a fixed-size, precreated event array and exposes claiming/publishing APIs. A sequencer assigns monotonically increasing sequence numbers, gates producers on consumer progress, and publishes availability:
- `Disruptor/RingBuffer.h`
- `Disruptor/Sequencer.h`
- `Disruptor/SingleProducerSequencer.h`
- `Disruptor/MultiProducerSequencer.h`

Producer mode is selected through `Disruptor/ProducerType.h`. The key data boundary is sequence-indexed mutable event slots: producers populate an acquired slot before publishing it; consumers read only published sequences.

#### Consumer Graph Assembly
The high-level disruptor constructs a dependency graph of event handlers/processors. Handler groups model fan-out and downstream dependencies; the repository tracks consumer metadata and updates gating sequences so upstream producers do not overwrite unconsumed slots:
- `Disruptor/Disruptor.h`
- `Disruptor/EventHandlerGroup.h`
- `Disruptor/ConsumerRepository.h`
- `Disruptor/SequenceGroups.h`

This is the primary control-plane boundary: registration occurs before `start()`, which materializes processors and schedules their run loops.

#### Consumption, Barriers, and Work Sharing
A `ProcessingSequenceBarrier` makes a consumer wait for a dependent/published sequence and propagates alerts during shutdown. `BatchEventProcessor` invokes ordered `IEventHandler<T>` callbacks, while `WorkProcessor`/`WorkerPool` distribute each event to one worker rather than broadcasting it:
- `Disruptor/ProcessingSequenceBarrier.h`
- `Disruptor/BatchEventProcessor.h`
- `Disruptor/WorkProcessor.h`
- `Disruptor/WorkerPool.h`

`EventPoller.h` provides a caller-driven polling alternative to dedicated processor loops.

#### Synchronization and Execution Runtime
`Sequence` is the shared progress primitive; barriers delegate waiting/signaling to selectable wait strategies. Strategies trade CPU use for latency, from blocking/timeout to busy-spin, yielding, sleeping, and phased backoff:
- `Disruptor/Sequence.h`
- `Disruptor/IWaitStrategy.h`
- `Disruptor/BlockingWaitStrategy.h`
- `Disruptor/BusySpinWaitStrategy.h`

Processors execute through scheduler abstractions, with per-task threads or round-robin thread-affined scheduling:
- `Disruptor/ITaskScheduler.h`
- `Disruptor/ThreadPerTaskScheduler.h`
- `Disruptor/RoundRobinThreadAffinedTaskScheduler.h`

Platform-specific thread support is separated in `Disruptor/ThreadHelper_Linux.cpp`, `Disruptor/ThreadHelper_Windows.cpp`, and `Disruptor/ThreadHelper_macOS.cpp`.

#### Failure, Validation, and Measurement
Consumer callback failures are routed through configurable exception handlers, including fatal and ignore policies: `Disruptor/IExceptionHandler.h`, `Disruptor/FatalExceptionHandler.h`, `Disruptor/ExceptionHandlerWrapper.h`. Unit tests validate concurrency primitives and graph behavior in `Disruptor.Tests/`; performance scenarios exercise producer/consumer topologies through `Disruptor.PerfTests/TestRepository.cpp` and session result types. Build dependencies are CMake, Boost, optional Conan, and vendored GoogleTest/GoogleMock (`googletest-release-1.8.0/`); CI targets Travis and AppVeyor.

Main entry points: [`Disruptor/Disruptor.h`](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/Disruptor.h) (disruptor<T>), [`Disruptor/ProcessingSequenceBarrier.h`](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/ProcessingSequenceBarrier.h) (ProcessingSequenceBarrier), [`Disruptor/Sequencer.h`](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/Sequencer.h) (Sequencer), [`CMakeLists.txt`](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/CMakeLists.txt) (CMake build surface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build &amp; validation"]
  node_cmake["CMake build surface<br/>[CMakeLists.txt]"]
  node_tests["Unit-test runner<br/>test executable<br/>[main.cpp]"]
  node_perf["Benchmark runner<br/>benchmark executable<br/>[main.cpp]"]
end

subgraph group_api["Public orchestration"]
  node_disruptor["disruptor&lt;T&gt;<br/>fluent API<br/>[Disruptor.h]"]
  node_handler_group["EventHandlerGroup<br/>dependency API"]
  node_consumer_repo["ConsumerRepository<br/>consumer registry"]
  node_sequence_groups["SequenceGroups<br/>gating manager<br/>[SequenceGroups.h]"]
end

subgraph group_pipeline["Event pipeline"]
  node_ring_buffer[("RingBuffer&lt;T&gt;<br/>event storage<br/>[RingBuffer.h]")]
  node_sequencer["Sequencer<br/>publication coordinator<br/>[Sequencer.h]"]
  node_producer_modes["Producer sequencers<br/>producer mode<br/>[ProducerType.h]"]
  node_barrier["ProcessingSequenceBarrier<br/>consumer barrier"]
  node_batch_processor["BatchEventProcessor<br/>broadcast consumer"]
  node_worker_pool["WorkerPool<br/>work-sharing consumer<br/>[WorkerPool.h]"]
  node_poller["EventPoller<br/>caller-driven consumer<br/>[EventPoller.h]"]
end

subgraph group_runtime["Runtime &amp; synchronization"]
  node_sequence["Sequence<br/>progress primitive<br/>[Sequence.h]"]
  node_wait_strategy["Wait strategies<br/>synchronization policy<br/>[IWaitStrategy.h]"]
  node_scheduler["Task schedulers<br/>execution runtime<br/>[ITaskScheduler.h]"]
  node_exceptions["Exception handlers<br/>failure policy"]
end

node_cmake -->|"builds library"| node_disruptor
node_cmake -->|"optional target"| node_tests
node_cmake -->|"optional target"| node_perf
node_tests -.->|"validates"| node_disruptor
node_perf -.->|"exercises topologies"| node_disruptor
node_disruptor -->|"defines dependencies"| node_handler_group
node_disruptor -->|"registers consumers"| node_consumer_repo
node_handler_group -->|"derives gating"| node_sequence_groups
node_consumer_repo -->|"schedules at start"| node_scheduler
node_disruptor -->|"creates pipeline storage"| node_ring_buffer
node_ring_buffer -->|"claims and publishes"| node_sequencer
node_producer_modes -->|"selects implementation"| node_sequencer
node_sequence_groups -->|"gates overwrite"| node_sequencer
node_sequencer -->|"publishes availability"| node_barrier
node_barrier -->|"releases ordered events"| node_batch_processor
node_barrier -->|"releases work"| node_worker_pool
node_ring_buffer -->|"polls events"| node_poller
node_sequence -->|"tracks producer and consumer progress"| node_sequencer
node_sequence -->|"checks dependencies"| node_barrier
node_wait_strategy -->|"waits and signals"| node_barrier
node_scheduler -->|"runs loop"| node_batch_processor
node_scheduler -->|"runs workers"| node_worker_pool
node_batch_processor -->|"routes callback failures"| node_exceptions
node_worker_pool -->|"routes callback failures"| node_exceptions

click node_cmake "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/CMakeLists.txt"
click node_tests "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor.Tests/main.cpp"
click node_perf "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor.PerfTests/main.cpp"
click node_disruptor "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/Disruptor.h"
click node_handler_group "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/EventHandlerGroup.h"
click node_consumer_repo "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/ConsumerRepository.h"
click node_sequence_groups "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/SequenceGroups.h"
click node_ring_buffer "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/RingBuffer.h"
click node_sequencer "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/Sequencer.h"
click node_producer_modes "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/ProducerType.h"
click node_barrier "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/ProcessingSequenceBarrier.h"
click node_batch_processor "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/BatchEventProcessor.h"
click node_worker_pool "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/WorkerPool.h"
click node_poller "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/EventPoller.h"
click node_sequence "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/Sequence.h"
click node_wait_strategy "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/IWaitStrategy.h"
click node_scheduler "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/ITaskScheduler.h"
click node_exceptions "https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/IExceptionHandler.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cmake,node_tests,node_perf toneBlue
class node_disruptor,node_handler_group,node_consumer_repo,node_sequence_groups toneAmber
class node_ring_buffer,node_sequencer,node_producer_modes,node_barrier,node_batch_processor,node_worker_pool,node_poller toneMint
class node_sequence,node_wait_strategy,node_scheduler,node_exceptions toneRose
```

## Components

### Build & validation

- [CMake build surface](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/CMakeLists.txt): build · Builds the library plus optional tests and performance targets. · `CMakeLists.txt`
- [Unit-test runner](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor.Tests/main.cpp): test executable · `Disruptor.Tests/main.cpp`
- [Benchmark runner](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor.PerfTests/main.cpp): benchmark executable · `Disruptor.PerfTests/main.cpp`

### Public orchestration

- [disruptor<T>](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/Disruptor.h): fluent API · Registers consumers, builds dependencies, starts and shuts down the pipeline. · `Disruptor/Disruptor.h`
- [EventHandlerGroup](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/EventHandlerGroup.h): dependency API · Expresses fan-out and downstream handler dependencies. · `Disruptor/EventHandlerGroup.h`
- [ConsumerRepository](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/ConsumerRepository.h): consumer registry · Tracks consumer metadata while assembling the graph. · `Disruptor/ConsumerRepository.h`
- [SequenceGroups](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/SequenceGroups.h): gating manager · Updates producer gating sequences from consumer progress. · `Disruptor/SequenceGroups.h`

### Event pipeline

- [RingBuffer<T>](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/RingBuffer.h): event storage · Preallocates mutable sequence-indexed event slots for publication and consumption. · `Disruptor/RingBuffer.h`
- [Sequencer](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/Sequencer.h): publication coordinator · Claims sequences, gates producers, and publishes availability. · `Disruptor/Sequencer.h`
- [Producer sequencers](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/ProducerType.h): producer mode · Single- and multi-producer implementations select claim coordination. · `Disruptor/ProducerType.h`
- [ProcessingSequenceBarrier](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/ProcessingSequenceBarrier.h): consumer barrier · Waits for published and dependent sequences and propagates shutdown alerts. · `Disruptor/ProcessingSequenceBarrier.h`
- [BatchEventProcessor](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/BatchEventProcessor.h): broadcast consumer · Invokes ordered IEventHandler<T> callbacks. · `Disruptor/BatchEventProcessor.h`
- [WorkerPool](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/WorkerPool.h): work-sharing consumer · Uses WorkProcessor instances so one worker handles each event. · `Disruptor/WorkerPool.h`
- [EventPoller](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/EventPoller.h): caller-driven consumer · Alternative to dedicated processor run loops. · `Disruptor/EventPoller.h`

### Runtime & synchronization

- [Sequence](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/Sequence.h): progress primitive · Shared atomic progress state for producers and consumers. · `Disruptor/Sequence.h`
- [Wait strategies](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/IWaitStrategy.h): synchronization policy · Blocking, busy-spin, and other policies trade CPU use for latency. · `Disruptor/IWaitStrategy.h`
- [Task schedulers](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/ITaskScheduler.h): execution runtime · Runs processor loops on per-task or thread-affined scheduling. · `Disruptor/ITaskScheduler.h`
- [Exception handlers](https://github.com/abc-arbitrage/disruptor-cpp/blob/master/Disruptor/IExceptionHandler.h): failure policy · Routes consumer callback failures to fatal or configurable handlers. · `Disruptor/IExceptionHandler.h`

## Connections

- CMake build surface → disruptor<T>: builds library
- CMake build surface → Unit-test runner: optional target
- CMake build surface → Benchmark runner: optional target
- Unit-test runner → disruptor<T>: validates
- Benchmark runner → disruptor<T>: exercises topologies
- disruptor<T> → EventHandlerGroup: defines dependencies
- disruptor<T> → ConsumerRepository: registers consumers
- EventHandlerGroup → SequenceGroups: derives gating
- ConsumerRepository → Task schedulers: schedules at start
- disruptor<T> → RingBuffer<T>: creates pipeline storage
- RingBuffer<T> → Sequencer: claims and publishes
- Producer sequencers → Sequencer: selects implementation
- SequenceGroups → Sequencer: gates overwrite
- Sequencer → ProcessingSequenceBarrier: publishes availability
- ProcessingSequenceBarrier → BatchEventProcessor: releases ordered events
- ProcessingSequenceBarrier → WorkerPool: releases work
- RingBuffer<T> → EventPoller: polls events
- Sequence → Sequencer: tracks producer and consumer progress
- Sequence → ProcessingSequenceBarrier: checks dependencies
- Wait strategies → ProcessingSequenceBarrier: waits and signals
- Task schedulers → BatchEventProcessor: runs loop
- Task schedulers → WorkerPool: runs workers
- BatchEventProcessor → Exception handlers: routes callback failures
- WorkerPool → Exception handlers: routes callback failures
