Plan

Milestones, in order. Milestone 0 removes the main risks before anything is built on them. Each later milestone is a vertical slice, from the wire up to the public API, and is done when its checks pass in CI. The design is in DESIGN.md.

M0: Foundations and risks

Settle what everything else depends on.

  • Repository: a Cargo workspace with apache-pulsar, apache-pulsar-protocol and apache-pulsar-testkit; ASF license headers, LICENSE, NOTICE; CI on Linux and macOS; cargo-deny.
  • Protobuf: generate with buffa, with an open enum for BaseCommand.type, add the proto2-default accessors and the test that checks them against every [default] in the proto (3). Vendor PulsarApi.proto from a pinned apache/pulsar commit, commit the generated code, and add a script that refreshes it and checks it in CI.
  • compio: small programs that check, on Linux with io_uring, Linux with the polling driver, and macOS (2 §5):
    • TLS through compio-tls and rustls;
    • waking a loop from another thread;
    • timers;
    • dropping a future while its operation is in flight;
    • DNS resolution.
  • First contact: the codec and the CONNECT handshake against the apachepulsar/pulsar:5.0.1 image, the first release with scalable topics, reading the broker‘s feature flags. A released image keeps CI from building one from master; the proto is still vendored from a pinned master commit, which only adds fields to 5.0.1’s.
  • Vectors from Java: a small Java program, run against the Pulsar 5.0.1 artifacts from Maven Central, generates (MessageIdV5, CheckpointV5, SegmentRouter and Murmur3_32Hash are the same on master):
    • routing vectors for keys (raw hash, segment hash, bucket hash, and the v4 partition for N partitions);
    • golden bytes for MessageIdV5 and CheckpointV5.

Checks: the handshake passes against the container in CI. Rust‘s Murmur3 matches every vector. The compio checks pass on all three setups, or the design is adjusted where they don’t.

M1: Connections and the two client models

  • The connection state machine: requests and responses, keepalive, feature-flag gating, token and mTLS authentication, auth refresh (3).
  • The per-loop pool keyed by logical and physical address; lookup with redirects and proxies; reconnection with backoff and coalescing (4).
  • The simulated broker's skeleton in apache-pulsar-testkit.
  • The local client, and the thread-safe client over N loops: the hop, close and drop (2 §4). Placement and the admission counters need producers, so they moved to M2.

Checks: lookups against the container, directly and through a Pulsar proxy. Disconnect and timeout scenarios pass on the simulated broker.

M2: Producer, one message per batch

  • Every entry in the batch format, one message per batch, with its bucket stamp (5 §2). Java sends a lone message as a plain entry; the batch format was kept anyway, for one encoding path.
  • The layout watch, routing, and the scalable producer: lazy per-segment producers, access modes, dedup, send timeout, the memory limit, flush and close (6 §2–§3). As in Java V5, the memory limit is the only bound on what producers hold: there is no pending-message limit.
  • Per-key order across splits and merges: Java's retire, park and hold (6 §3.3).
  • Routing over a synthetic legacy layout, for persistent:// topics.
  • MessageId encoding, errors, and the producer in the default, local and blocking APIs (7).
  • Placement of producers on loops, and the memory admission counter (2 §4.1), moved here from M1.

Checks: C1–C6 and the producer side of C12–C15. Ported scenarios from ScalableTopicProducerTest, ScalableTopicProducerOrderingTest, V5ProducerSegmentGoneTest, V5ProducerLayoutChangeOrderingTest, V5ProducerAccessModeTest, V5ProducerBackpressureTest, V5ProducerClosingCompletionTest and V5ScalableTopicAutoCreateTest. Golden MessageId bytes round-trip with Java. A test confirms that the pipelining patterns in the rustdoc (buffered, FuturesOrdered, join_all) keep send order (7 §3.1).

Ported so far: the ordering, segment-gone, access-mode and close scenarios on the simulated cluster (crates/apache-pulsar-testkit/tests/producer.rs), backpressure and pipelining over loopback, and on the real broker a split during traffic, auto-create and not-found, an exclusive conflict, a partitioned topic, and a Java consumer reading what Rust produced. The Java tests of Java-only internals (executors, hooks) have no Rust counterpart.

M3: Queue consumer

  • The segment consumer: Shared subscriptions, flow control, parsing of batched and compressed entries (other clients produce them), grouped acks, negative acks and redelivery (5 §3).
  • The Queue consumer: attach to every segment, keep that set in step with the layout, one receive queue, ack routing by segment (6 §4).

It lands in two pull requests: the segment consumer first, which M4 and M5 build on, then the Queue consumer.

Checks: C8. Ported scenarios from ScalableQueueConsumerReconcileTest, ScalableQueueConsumerReceiveLoopTest, V5QueueConsumerBasicTest, V5QueueConsumerMultiSegmentAckTest, V5SubscriptionInitialPositionTest and V5DAGFollowingTest, and the Queue consumer cases of the split, merge and layout-watch tests. Java producer ⇄ Rust consumer, with each codec. V5MultiTopicQueueConsumerTest is the namespace consumer's, which comes after the first release.

M4: Stream consumer

  • The assignment session: register, apply updates, reconnect within grace, unsubscribe on close.
  • Exclusive per-segment subscriptions, position vectors, and cumulative ack fanned out across segments.
  • The consumer side of entry-bucketing: Key_Shared attach, individual acks on shared segments, drain before a mode flip or a release (6 §5).

Checks: C7. Ported scenarios from ScalableStreamConsumerReconcileTest, V5StreamConsumerAckWatermarkTest and V5StreamConsumerDagReplayTest, plus more consumers than segments, so that segments are shared.

It lands in three pull requests: the segment consumer‘s cumulative acks, Key_Shared attach and draining, with the simulated broker’s Exclusive and Key_Shared subscriptions; then the assignment session, the Stream consumer and the simulated controller; then the driver and the API.

Ported: the reconcile scenarios against hand-made assignments (crates/apache-pulsar-protocol/tests/stream_consumer.rs); on the simulated cluster, V5StreamConsumerBasicTest, V5StreamConsumerDagReplayTest, V5StreamConsumerOrderingTest, V5StreamConsumerAutoReconnectTest and V5StreamConsumerAckWatermarkTest, members that share a segment by bucket, a crashed member‘s messages handed to another, and members beyond the buckets (crates/apache-pulsar-testkit/tests/stream_consumer.rs); against a 5.0.1 broker, the basic, DAG replay and ordering, sharing, ack watermark and clean leave cases, with a Java producer. The broker’s controller orders a key's segments itself: it hands out a segment once its ancestors are drained.

M5: Checkpoint consumer

  • Readers on every segment, parents first, checkpoint capture and restore, the grouped mode (6 §6).
  • Checkpoint encoding.

Checks: C9 and C10. Ported scenarios from ScalableCheckpointConsumerTest, ScalableCheckpointConsumerReconcileTest and the V5CheckpointConsumer*Test classes. Checkpoints round-trip with Java across a layout change.

It lands in three pull requests: checkpoint encoding with the ungrouped consumer‘s state machine and its scenarios on the simulated cluster, then the driver and the API, then the grouped mode, on the Stream consumer’s assignment session from M4.

Done. Checkpoints match Java‘s golden bytes. The scenarios of the Java tests above pass on the simulated cluster: those of a consumer on its own in crates/apache-pulsar-testkit/tests/checkpoint_consumer.rs, and those of a group’s members in checkpoint_group.rs. On the real broker: a resume across a split, a latest start across a split, a deleted segment, a checkpoint round trip with the Java client across a split and a merge, two members of a group sharing a topic‘s segments and handing them over as one leaves, and a member created after a split reading the sealed backlog. The controller orders nothing for a Checkpoint group, so its members keep a key’s order within a segment only, as Java's do.

M6: Batching and compression

  • Multi-message batches: one open batch per entry bucket, with the stamp (5 §2).
  • LZ4, ZSTD, ZLIB and Snappy on the producer side.
  • A first round of benchmarks (8 §6).

Checks: ported scenarios from V5ProducerCompressionTest. Key affinity holds with batched producers and shared segments. A performance baseline is recorded.

It lands in three pull requests: batching, then compression, then the benchmarks.

Done. Batching, with Java V5‘s BatchingPolicy and its defaults, and EntryBucketBatchContainer‘s rules, on the simulated cluster (crates/apache-pulsar-testkit/tests/producer_batching.rs): the three triggers, one bucket per entry and its stamp, entries in sequence order, the messages that go alone, and open batches on a flush, a close, a reconnect, a split and a timeout. Key affinity holds on the simulated cluster and against a 5.0.1 broker: two Stream members sharing a one-segment topic by bucket each get whole keys, in order, from entries of several messages. Java’s V5EntryBucketDispatchTest sends one message at a time, so its entries hold one; these pipeline the sends. A Java consumer reads Rust’s batches, and with deduplication on, a 5.0.1 broker takes the entries of every bucket.

Compression, with Java V5‘s CompressionPolicy: the scenarios of V5ProducerCompressionTest (a payload with each codec, none, and no policy set) on the simulated cluster (producer_compression.rs) and against a 5.0.1 broker, a batch compressed whole, and the broker’s limit on the compressed entry. A Java consumer reads Rust's batches compressed with each codec, the ZLIB ones finished streams.

A first round of benchmarks, and a baseline against Java‘s V5 client on a 5.0.1 broker (8 §6): micro-benchmarks of the producer’s state machine and of the codecs, and tools/perf, which measures the producer‘s and the Queue consumer’s throughput and latency against a broker as Java‘s pulsar-perf does. The client side, the producer and perf driving it, is bound by its CPU, most of a send’s spent outside the state machine, and the thread-safe consumer‘s receives and acks each cross threads: the next rounds look for where a send’s time goes, and measure loops.

M7: Conformance and a first release

  • The rest of the schemas, generic records included (C11, 7 §8).
  • End-to-end tests of the migration bridge: partitioned and non-partitioned persistent:// topics, with v4 clients running alongside.
  • An audit of the error model, rustdoc and examples (send pipelining among them), and the conformance suite (8 §2.2).
  • A first ASF release.

Checks: the conformance checklist C1–C15 is complete, and tests/PORTING.md shows the Java scenarios in scope covered.

The schemas land in six pull requests: the primitive types and C11‘s typed error; key/value; generic records, with each message decoded by the schema of its version; JSON and Avro; Protobuf’s native type; Java V5's Protobuf type.

The schemas are done: bytes, string, the primitive types, key/value, generic records, JSON, Avro, and Java‘s two Protobuf schemas, named and encoded as Java’s, with a public SchemaInfo and SchemaType. JSON, Avro and Protobuf are features, on by default, through serde, apache-avro, buffa‘s descriptors and prost. The simulated cluster keeps a schema history per topic, as the broker does, and serves a schema by version. C11 holds there and against a 5.0.1 broker: a schema of another type than the topic’s fails with IncompatibleSchema for a Shared producer‘s sends, an exclusive producer’s create, and each kind of consumer‘s subscribe; the first consumer of a new topic registers its schema; and a topic with messages but no schema refuses a schema. Java reads the values of each schema that Rust sends, and Rust those Java sends, typed and as generic records. Generic and Avro consumers fetch the schema of each version they meet, and decode each message with its own: against 5.0.1, Java’s V5 evolution test holds across the two clients, a second Avro version registering after a split and both clients reading the first version‘s records with it. For Protobuf, Rust declares what Java declares for the same message: its descriptors for PROTOBUF_NATIVE, and for Java V5’s Schema.protobuf, type PROTOBUF, the same description in Avro, so that Rust‘s producers join the version Java’s registered. Neither client reads PROTOBUF as generic records, whose definition doesn‘t say how Protobuf encodes the message (J22). Key/value is Java’s inline encoding; its separated one, with the key in the message‘s key, comes later. Java V5’s autoProduceBytes() and generic(SchemaInfo), which the spec‘s standard set doesn’t name, aren't planned yet.

The migration bridge's end-to-end tests run against 5.0.1, on partitioned and non-partitioned topics, with Java v4 clients running alongside (tests/integration/bridge.rs):

  • Before a migration: v4 and Rust clients side by side, and on one Shared subscription. Every Rust producer and consumer is marked as managed by a V5 client, and a v4 client holds a migration off until it is forced.
  • During one: a producer keeps each key's order with sends in flight, and the Queue and Checkpoint consumers follow. v4 and Rust clients run through a forced migration.
  • After one: a Stream consumer reads the legacy segments first, every key in order, and a member of a Checkpoint consumer group reads them and the new ones.

The 5.0.1 broker gives a migrated topic‘s first layout the synthetic layout’s epoch, which the client allows for (spec gap 29). Left to the broker: a Stream consumer or a Checkpoint consumer group can't use a topic before it migrates (spec gap 28, J18). An ignored test keeps what a Stream consumer should get there.

The checks are done. tests/conformance/README.md holds the conformance suite, the spec‘s interoperability cases described for any SDK, each with what this client runs for it, and the checklist, which names for each of C1–C15 the tests that show the client meets it. tests/PORTING.md lists each Java test class that uses the V5 API, 150 classes and 694 tests at apache/pulsar a0e7f7de62, with the tests here that cover its scenarios: 303 covered and 2 partly; 104 Java-only, 80 the broker’s, 18 needing several brokers and 177 out of scope. The 10 in scope that aren‘t ported, and what the 2 partly covered miss, each have their reason there: what the client doesn’t have (a processing timeout, a TLS certificate apart from authentication, metrics, a proxy URL, Java V5‘s autoProduceBytes() and generic(SchemaInfo)), a failed CONNECT write, which nothing can cause over loopback, how the controller converges under churn, which is the broker’s, and a bug. Java‘s tests added since a0e7f7de62 aren’t mapped yet.

The bug is the checklist‘s known gap under C7: once the controller moves to another broker, a Stream consumer whose client holds the topic’s layout watch for something else too, a producer say, registers again with the old controller. From the code, a member of a Checkpoint consumer group, which registers the same way and holds the watch itself, would too. An ignored test pins it until it is fixed.

After the first release

In rough order: OAuth2 authentication, dead-letter policy, namespace subscription, transactions, end-to-end encryption, chunking, Windows as a tested platform. Then the later phase: a base for other language SDKs (1 §6).

After M2, the three consumer milestones (M3–M5) can proceed in parallel. They share the segment consumer from M3, so its subscription and ack parts land first.