Free preview

Consumer Manager: Offsets, Retention, and Delivery

Why this matters: offsets are the mechanism the entire chapter has been building toward. One log, many cursors is what makes independent consumption possible, and this is the component that holds the cursors.

Key takeaway

The consumer manager handles four things: verifying the consumer, retention time management, message delivery options (push or pull), and offset management in a key-value store.

ResponsibilityDetail
Verify the consumerChecks if a consumer is authorized to read from a specific topic
Retention time managementEnforces retention policies to prevent access to expired messages
Message delivery optionsSupports both push (system sends data) and pull (consumer requests data). This flexibility prevents consumer overload while supporting real-time needs. Preferences are stored in the database
Offset managementStores each consumer's offset in a key-value store, allowing consumers to resume reading from where they left off

Offset management

Partition 0 of Topic A  (immutable, append-only)

[ off 0 ][ off 1 ][ off 2 ][ off 3 ][ off 4 ][ off 5 ][ off 6 ][ off 7 ]
              ^                                  ^
        Consumer B: 2                      Consumer A: 6

Key-value store
  (consumer_B, topicA:p0) -> 2
  (consumer_A, topicA:p0) -> 6

One copy of the data. One small mutable value per consumer per partition.

Push or pull, per consumer

Supports both models, and the reason given is precise: this flexibility prevents consumer overload while supporting real-time needs. Preferences are stored in the database.

ModelFitsRisk
PullBatch consumers, analytics, anything with variable processing speedPoll latency — mitigated by long polling
PushReal-time needs — chat clients, live dashboardsConsumer overload, since the consumer no longer controls the rate

Retention enforcement

Enforces retention policies to prevent access to expired messages.

Key takeaway

Offsets in a key-value store — chosen over the relational store because they are high-volume, constantly overwritten, and fetched by exact key — give every consumer an independent cursor over one copy of the log. When you commit the offset decides at-least-once versus at-most-once. Push or pull is a per-consumer preference. And a consumer slower than retention loses data quietly.

Interview signal by level

LevelWhat a strong answer sounds like
L4"We store where each consumer has read so it can resume."
L5Justifies the store: "offsets go in a key-value store — one per consumer per partition, constantly overwritten, only ever fetched by key, so a relational database is the wrong shape."
Staff+Ties commit order to semantics: "committing the offset after processing gives at-least-once and needs idempotent handlers; committing before gives at-most-once and drops work. There's no ordering that gives exactly-once — you get it from idempotency or from making the commit and the side effect atomic. And I'd alert on lag against the retention window, because a consumer that falls behind retention loses messages with no error."

Next: the finished picture.

Enjoying the preview?

Create a free account to unlock the rest of this course, the in-browser judge, and live AI mock interviews.

Sign up free to continue