Execution Patterns

IndexBus provides four standard execution patterns. Each maps to a specific region layout and set of primitives.

Router Loop (Fanout)

A single-writer router step that moves events from a producer ring into one or more consumer rings.

                      ┌──────────┐
                  ┌──▶│Consumer 0│
┌────────┐       │   └──────────┘
│Producer│─SPSC─▶│Router│
│        │ queue │(Broadcast│   ┌──────────┐
└────────┘       │ or Work) ├──▶│Consumer 1│
                 │  Queue)  │   └──────────┘
                 └──────────┘

Modes

ModeBehaviorDelivery
BroadcastAttempt delivery to each consumer (partial OK)Best-effort
WorkQueueDeliver to at most one consumer (round-robin)Exactly-one

Tuning Knobs

KnobEffect
batch_maxMaximum events per router iteration
batch_time_usTime budget per batch before yielding
yield_everyYield to OS scheduler after N iterations
idle_spin_limitSpin iterations before switching to backoff or wake

Larger batches increase throughput at the cost of latency. Smaller batches reduce latency but add per-event overhead. Choose a wait strategy to match the deployment: busy spin for best latency with high CPU, backoff for lower CPU, or wake-based for low idle CPU.

Use Cases

  • Market-data fanout
  • Edge gateway distribution
  • CPU isolation with dedicated router cores

Sequencer + Gating

Disruptor-style monotonic sequence with per-consumer gating for strict ordering and stage coordination.

┌──────────┐    cursor    ┌───────────┐   gating[0]   ┌──────────┐
│ Producer │───────────▶│ Sequencer  │◀──────────────│Consumer 0│
│          │             │  Region    │               └──────────┘
└──────────┘             │            │   gating[1]   ┌──────────┐
                         │ (barrier)  │◀──────────────│Consumer 1│
                         └───────────┘               └──────────┘
  • Producer claims sequence numbers, publishes, and advances the cursor.
  • Consumers wait on barriers and advance their gating sequences.
  • Wrap prevention: the producer cannot advance more than capacity ahead of the slowest consumer.

Use Cases

  • Low-latency staged flows
  • Deterministic coordination
  • Multi-stage fanout with ordering guarantees

Router-Enforced Credits

Credit accounting layered on top of fanout routing. Each consumer has a credit budget (maximum allowed backlog). The router checks credits before delivery. On exhaustion, the configured policy determines behavior.

PolicyBehaviorTrade-off
DropSkip delivery, increment drops_no_creditStable latency, data loss
ParkBlock router until credit availableData preserved, router stalls
DetachRemove consumer after sustained exhaustionPrevents slow-consumer domination

Use Cases

  • Protect consumers from overwhelm
  • Prevent unbounded lag
  • Make overload behavior observable and testable

Journal (Append + Tail/Replay)

Append-only segmented log for fast appends, tailing, and replay-style reads.

┌───────────┐  append   ┌─────────────────────────────────┐
│ Publisher  │─────────▶│ Journal Region                   │
└───────────┘           │ ┌─────────┬─────────┬─────────┐ │
                        │ │Segment 0│Segment 1│Segment 2│ │
                        │ └─────────┴─────────┴─────────┘ │
                        └─────────────────────────────────┘
                                   ▲ tail
                        ┌──────────┴──────────┐
                        │  Subscriber (poll)   │
                        └─────────────────────┘

Record Format

Each record consists of an 8-byte header (payload_len + flags) followed by an 8-byte-aligned payload. Publication uses two-phase commit with FLAG_COMMITTED. Storage is bounded via fixed-size segments, with overrun detection for slow subscribers.

Use Cases

  • Capture-and-replay debugging
  • Late-joiner subscribers
  • Inspectable streams

Quick Chooser

NeedPattern
High-throughput 1→N distributionRouter loop (fanout)
Strict ordering + stage coordinationSequencer + gating
Bounded consumer lag with explicit overload policyRouter-enforced credits
Replayable stream, tailing, debug captureJournal
Lowest overhead, no fanout neededDirect SPSC/MPSC events
Provenance
Need the canonical source?
Use the public hub to orient yourself, then jump to repo-owned docs or rustdoc when you need contract-level detail.