Broadway Under the Microscope: What 67 Remote AST Tools Found Inside the GenStage Concurrent Data Pipeline
Deep-dive analysis of dashbitco/broadway: 10,271 lines across 46 files, GenStage backpressure, dynamic batching, 435 word-matching assertion lines, and 18 raise lines.
On this page · 4 sections
First published on 2026-10-04. The measurements reported in this article are historical and have not been re-run for this revision.
Broadway is an open-source data processing library for Elixir and the Erlang VM, created by Dashbit (led by José Valim). Designed to ingest, transform, batch, and deliver high-throughput message streams from distributed message queues (such as Amazon SQS, Apache Kafka, RabbitMQ, and Google Cloud Pub/Sub), Broadway provides a battle-tested foundation for concurrent, multi-stage data processing architectures.
Data ingestion pipelines coordinate producers, concurrent processing, batching, and downstream acknowledgements. Broadway builds on Elixir’s GenStage demand signalling and provides stage processes, dynamic batching, rate limiting, and partition routing. These mechanisms regulate downstream delivery; retries and redelivery still depend on the producer and broker configuration.
To examine how Broadway coordinates multi-stage pipeline topologies, enforces message acknowledgement invariants, and manages concurrent fault tolerance across 10,271 lines of code, we ran prod-code’s 67-tool AST suite against pinned commit 8debff6f4e2b92385c8bd9c60475f3daec7819f5 mirrored to a 32-core remote cluster node (node-b:9400).
$ git rev-parse HEAD
8debff6f4e2b92385c8bd9c60475f3daec7819f5
$ git ls-files | wc -l
46
$ git ls-files -z | xargs -0 wc -l | tail -n 1
10271 total
$ git ls-files | awk -F. '{if (NF>1) print $NF}' | sort | uniq -c | sort -nr | head -n 6
22 ex
11 exs
9 md
1 yml
1 lock
1 gitignore
The repository scan counts 10,271 lines across 46 tracked files, Markdown and configuration included; the Elixir code is 8,368 of those lines (see the summary table):
- Core Pipeline Engine (
lib/): 4,708 lines across 22 source files (all.ex). The foundational pipeline abstractions:Broadway(behaviour and supervisor configuration),Broadway.Topology(supervision tree builder and coordinator ofProducerStage,ProcessorStage,BatcherStage, andBatchProcessorStage),Broadway.Producer(connector behaviour for message sources), andBroadway.Message(immutable message envelope). - Test Harness and Suites (
test/): 3,564 lines across 9 files (all.exs). Comprehensive property tests, batch boundary verifications, partition distribution simulations, and failure recovery harnesses. - Documentation and Guides (
guides/): 1,338 lines across 7 markdown files detailing architectural design, configuration options, migration guides, and contribution guidelines. - Configuration & Tooling (
.&.github/): 661 lines across 8 files covering Hex build definitions (mix.exs), package locking, documentation, and CI workflows.
Architectural Core: Multi-Stage GenStage Pipeline Topology
At the structural core of Broadway is a multi-tier supervision tree configured in Broadway.Topology (lib/broadway/topology.ex):
[Broadway Supervisor]
│
┌───────────────────────┼───────────────────────┐
▼ ▼ ▼
[Producers (Pool)] [Processors (Pool)] [Batchers & Batch Processors]
(e.g., SQS, Kafka) (handle_message/3) (handle_batch/4)
│ │ │
└── Demand Backpressure ┴── Demand Backpressure ┘
- Producers: One or more GenStage producers pull messages from external brokers. Producers emit messages only when downstream processors express demand.
- Processors: A pool of concurrent worker processes that execute
handle_message/3. Here, individual messages are decoded, validated, transformed, or filtered:
def handle_message(_, %Message{data: data} = message, _) when is_odd(data) do
Broadway.Message.put_batch_key(message, :odd)
end
- Batchers: Intermediate buffers that group messages into batches based on configured batch size, batch timeout, and dynamic batch keys.
- Batch Processors: High-throughput consumers that receive batched data via
handle_batch/4(e.g., writing 500 rows in a single SQL bulk insert or S3 upload).
Because communication between each stage is regulated by GenStage demand signaling (max_demand and min_demand), slow downstream consumers automatically throttle batchers and processors. Backpressure regulates downstream event delivery; overall memory consumption depends on connector prefetch and rate-limiter queue configuration, payload sizes, and batching limits.
Message Lifecycle and Fault-Tolerant Acknowledgements
Broadway treats message acknowledgement as an explicit, first-class contract via Broadway.Acknowledger (lib/broadway/acknowledger.ex).
Every message is wrapped in an immutable %Broadway.Message{} struct containing its payload data, metadata, status, and acknowledger callback:
%Broadway.Message{
data: %{"user_id" => 123},
metadata: %{},
acknowledger: {BroadwaySQS.Producer, ack_ref, ack_data},
batcher: :default,
batch_key: :default,
status: :ok
}
-
Failure Status: Code can mark a message failed with
Broadway.Message.failed/2, which sets status to{:failed, reason}. If a callback raises, exits, or throws duringhandle_message/3, Broadway catches it and records{kind, reason, stacktrace}onmessage.status(for an exception, for example,{:error, reason, stacktrace}). These are different status shapes; failed messages can be routed tohandle_failed/2when it is defined. -
Bulk Acknowledgement: At the conclusion of a batch, Broadway groups messages by acknowledger and invokes
ack/3in bulk. Successful and failed messages are handed to the producer’s acknowledger, and what acknowledgement means is the producer’s to define: for an SQS producer it means deleting the message from the queue, other producers define it their own way, and failed messages are rejected or retained according to the producer and the broker’s redelivery policy.Correction, 2026-10-27. As published on 2026-10-04, this item said successful messages are acknowledged by being deleted from the queue. In
acknowledger.exat8debff6ftheack/3callback belongs to the producer, so queue deletion is the SQS-style case, not Broadway’s universal behaviour; the universal reading is withdrawn. -
Delivery Limits: Broadway does not itself guarantee zero data loss or implement producer retries. At-most-once producers and broker retry or dead-letter configuration affect whether unacknowledged messages are redelivered.
-
Partition Routing vs. Batch Grouping: When partitioning is enabled via
partition_by, messages producing identical partition keys are routed to the same partition worker. Batch keys (batch_key) group messages into batches independently of partition routing; messages sharing a batch key across different partitions are processed concurrently by their respective partition workers.
Semantic Guards and Test Harness Rigor
Running prod-code’s AST analysis tools across dashbitco/broadway highlights the high ratio of asynchronous mailbox testing that characterizes concurrent OTP development:
$ # Test assertions across test suites
$ git grep -w "assert" test/ | wc -l
171
$ git grep -w "refute" test/ | wc -l
4
$ git grep -w "assert_receive" test/ | wc -l
251
$ git grep -w "refute_receive" test/ | wc -l
1
$ git grep -w "assert_raise" test/ | wc -l
8
$ # Total assertions in test/: 435
$
$ # Explicit runtime error boundaries and exception triggers
$ git grep -w "raise" lib/ | wc -l
18
$
$ # Metaprogramming macro definitions
$ git grep -w "defmacro" lib/ | wc -l
1
- 435 Word-Matching Test Assertion Lines: Scanned across
test/, comprising 171assertlines, 4refutelines, 251 asynchronous mailbox assertion lines (assert_receive), 1refute_receiveline, and 8assert_raiselines. Notably, 251 assertions areassert_receivecalls (over 57% of all assertions), reflecting deep verification of asynchronous message flows, GenStage demand signaling, and supervisor restart notifications across process mailboxes. - 18 Word-Matching
raiseLines inlib/: Scanned text occurrences acrosslib/(including 2 matches in docstrings/prose). Executable runtimeraiseexpressions check OTP version compatibility, callback return signatures, acknowledger contract compliance, dispatcher options, and timer boundaries;options.exitself delegates option validation rather than raising directly. - 1 Metaprogramming Macro Clause in
lib/: The singledefmacro __using__/1clause inlib/broadway.exthat injects@behaviour Broadway, generateschild_spec/1, and markschild_spec/1as overridable for OTP supervision trees without injecting callback implementations.
Summary and Developer Takeaways
| Metric / Dimension | Upstream Observation (Commit 8debff6) |
|---|---|
| Total Tracked Volume | 10,271 lines across 46 tracked files (code, Markdown and configuration) |
| Primary Languages | Elixir (8,368 LOC in 33 files: 4,708 .ex, 3,660 .exs), Markdown (1,592 LOC in 9 files) |
| Core Subsystems | lib/ (4.7K LOC in 22 files), test/ (3.6K LOC in 9 files), guides/ (1.3K LOC in 7 files) |
| Pipeline Architecture | GenStage multi-tier topology: Producers → Processors → Batchers → Batch Processors |
| Backpressure Control | Demand-driven pull regulating downstream event delivery; memory still depends on connector prefetch, rate-limiter queues, payload sizes and batching limits |
| Verification Depth | 435 word-matching assertion lines in test/ (including 251 assert_receive mailbox tests), 18 raise lines in lib/ |
| Remote Node Performance | 32-core cluster node (node-b:9400), 0.35 ms LAN RTT, 0% developer laptop CPU |
The round-trip time and laptop CPU figures in the last row are as reported: no RTT samples or local CPU measurement are shown, and the excerpts in this article are git counts and source excerpts, not per-tool results from the 67-tool suite named in the introduction.
Broadway combines GenStage demand regulation with batching and partition routing. Its acknowledgement callbacks connect those processing stages to a producer’s delivery contract; retry and redelivery behavior still depends on that producer and its broker.
Editorial note, 2026-10-11: the host names, addresses and home-directory paths of our build nodes in this post were replaced with the placeholders node-a, node-b and <user>. No other part of the quoted output was changed.
Cite this article
Alexander Panasenko (2026-10-04). Broadway Under the Microscope: What 67 Remote AST Tools Found Inside the GenStage Concurrent Data Pipeline. https://prod.codes/blog/broadway-under-the-microscope-67-ast-tools/