AlgoViz

Apache Pulsar

medium 28 min

Apache Pulsar separates serving from storing: brokers talk to clients and keep no data of their own, Apache BookKeeper stores each topic as many small replicated segments.

See it run

Publish to two bookies, lose a broker without copying data, and see which ledgers may be deleted.

Operations

One publish

The broker owns the topic, the bookies keep the message.

Step 1 of 4

Send

ProducerordersBroker 1owns ordersBroker 2other topicsMetadataowner: broker 1Bookie 1ledger 1Bookie 2ledger 1Bookie 3empty

The producer looked up the owner of the topic and sends to broker 1.

Step 1: Send

entry = next_entry()for bookie in write_quorum(entry):    bookie.append(ledger, entry, data)wait_for(ack_quorum)confirm(producer)
Delay
Two hops and a disk write
Protects
Two copies
Broker with its own disk
one hop less, data is tied to it

With three copies and an ack quorum of two, one slow bookie does not delay you.

In the real world

The same apache pulsar doing real jobs. Pick one and step through it.

A test consumer ran once and never came back.

Step 1 of 3

One test

ProducerordersBroker 1owns ordersBroker 2other topicsMetadataowner: broker 1Bookie 1ledger 1Bookie 2ledger 1Bookie 3empty
Backlog of mail
4%
Backlog of test
10%
Bookie disk
30%

Somebody subscribed with the name test and stopped the program.

Step 1: One test

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • No subscription before the first message

    critical

    Without a subscription and without retention, nothing is kept.

    Wrong
    producer.send(msg)   # consumers come later
    Right
    create the subscription firstor set-retention on the namespace
  • Key_Shared with default batching

    critical

    A batch is routed by its first key, so other keys reach the wrong consumer.

    Wrong
    create_producer(topic)
    Right
    create_producer(topic,    batching_type=BatchingType.KeyBased)
  • Trusting negative acks for dead letters

    major

    The counter is in memory and resets when the topic moves.

    Wrong
    consumer.negativeAcknowledge(msg)
    Right
    enableRetry(true)consumer.reconsumeLater(msg, 30, SECONDS)
  • Leaving test subscriptions behind

    major

    A durable subscription holds every ledger until it is deleted.

    Wrong
    subscribe(topic, "test")  # and forget it
    Right
    pulsar-admin topics unsubscribe --subscription test TOPIC

Interview tips

  • How to explain it

    • Brokers serve, bookies store.
    • A topic is a chain of ledgers.
    • A new owner opens a new ledger.
  • Memory trick

    • The desk speaks.
    • The vault remembers.
    • Sealed tapes never move.
  • Reach for it when

    • Many tenants share a platform.
    • The same events feed queues and streams.
    • Regions must replicate.
  • Be careful when

    • Nobody can operate three layers.
    • You rely on the Kafka ecosystem.
    • Subscriptions are not cleaned up.