33

Chapter 33 — Full Example: Ingest, Match, Publish

A real three-stage, low-latency pipeline wired together from the patterns earlier chapters spent 32 chapters establishing one at a time.

Demo 33Source on GitHub ↗

The full source for this example lives in examples/concurrency/33-ingest-match-publish/ — clone the repo, cd in, and ./demo.sh.

Chapter reference: Doc 33 — Full Example: Ingest, Match, Publish

What it shows

Several ingest producer threads generate a stream of order messages and push survivors onto a bounded multi-producer ring; a single thread, pinned to its own core, is the sole writer of a real price-time-priority limit order book and busy-polls the ring rather than blocking; a small publish pool drains the match stage’s output ring. One BoundedRing<T> type, a generalized MPMC queue built on the single-writer-per-slot discipline earlier chapters established for simpler SPSC and disruptor rings, backs both hops. A sustained load phase keeps the ingest ring mostly empty while an unpaced overload burst reliably fills it; the verifier checks that no order is lost or duplicated through either ring, that order-book conservation holds exactly, that the match thread id never changes, and that back-pressure actually engaged under the burst — all hard assertions, with latency percentiles reported rather than pinned to a number.

Running it

cd examples/concurrency/33-ingest-match-publish
./demo.sh            # build + run pipeline + verify.lua
./demo.sh --clean    # remove the image