Kafka isn't this — reads delete here
A queue's read is destructive — once a consumer takes a message the bytes are gone, the inverse of a Kafka log where a read just advances a per-consumer bookmark and the bytes stay in place.
We have a buffer between the request and the worker. Same picture as Kafka from a distance, but opposite rules up close: in Kafka the consumer is a bookmark and the bytes stay; here the read removes the cell.
Scene 02
Kafka isn't this — reads delete here
- Watch
- Try it
- Predict
- Capture
Same five colored messages, two strips. On the log, both cursors crawl forward and every cell stays lit. On the queue, the first cell vanishes the instant C1 takes it — that's a destructive read.
Highlighted lines are the ones running in the diagram right now.
def read(consumer_id):offset = cursors[consumer_id] # per-consumer bookmarkif offset >= len(log):return None # caught up, bytes stayrecord = log[offset] # cell is NOT removedcursors[consumer_id] = offset + 1return recorddef seek(consumer_id, new_offset):cursors[consumer_id] = new_offset # replay from anywhere
def dequeue():if head == tail:return None # queue emptyrecord = cells[head]del cells[head] # bytes are GONEhead += 1 # broker owns this, not consumerreturn record# No seek(). No replay. A second consumer can only ever# receive cells that have not yet been dequeued.
def log_fanout(record):log.append(record) # one physical cell# each consumer group reads via its own cursordef queue_fanout(record, queues):for q in queues: # one queue per consumer groupq.enqueue(copy(record)) # N physical copies# each group dequeues from its own queue
Where this sits in Build a Message Queue (RabbitMQ / SQS)
Scene 02 of 14. Same picture as Kafka from a distance, opposite rules up close: the queue's read removes the cell; no other consumer will ever see it.
Up next. So reads are destructive and the broker tracks state. Time to draw the queue properly — head, tail, and the two operations that move messages across it.
All 14 scenes in Build a Message Queue (RabbitMQ / SQS) · Every curriculum