<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Rahdar blog</title>
  <link href="https://rahdar.dev/blog/feed.xml" rel="self"/>
  <link href="https://rahdar.dev/blog/"/>
  <id>https://rahdar.dev/blog/</id>
  <updated>2026-12-05T00:00:00.000Z</updated>
  <entry>
    <title>Your Kafka consumer lag is an estimate. Ours says so.</title>
    <link href="https://rahdar.dev/blog/2026-12-kafka-consumer-lag-is-an-estimate"/>
    <id>https://rahdar.dev/blog/2026-12-kafka-consumer-lag-is-an-estimate</id>
    <updated>2026-12-05T00:00:00.000Z</updated>
    <published>2026-12-05T00:00:00.000Z</published>
    <author><name>Mahdi Amirabdollahi</name></author>
    <summary>Consumer lag is a subtraction between two numbers read at different times, over offsets that do not all hold records. Rahdar marks it as an estimate, says why, and never turns an unknown partition into zero.</summary>
    <content type="html">&lt;h1 id=&quot;your-kafka-consumer-lag-is-an-estimate-ours-says-so&quot; tabindex=&quot;-1&quot;&gt;Your Kafka consumer lag is an estimate. Ours says so. &lt;a class=&quot;header-anchor&quot; href=&quot;#your-kafka-consumer-lag-is-an-estimate-ours-says-so&quot; aria-label=&quot;Permalink to &amp;quot;Your Kafka consumer lag is an estimate. Ours says so.&amp;quot;&quot;&gt;&amp;ZeroWidthSpace;&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Every Kafka console shows consumer lag as a plain integer. Rahdar, an open-source operations console for Apache Kafka, RabbitMQ and Apache ActiveMQ Artemis, shows it as &lt;code&gt;≈ 13,200&lt;/code&gt; with a reason attached. This post explains why, down to the type that enforces it.&lt;/p&gt;
&lt;h2 id=&quot;lag-is-a-subtraction-and-neither-operand-holds-still&quot; tabindex=&quot;-1&quot;&gt;Lag is a subtraction, and neither operand holds still &lt;a class=&quot;header-anchor&quot; href=&quot;#lag-is-a-subtraction-and-neither-operand-holds-still&quot; aria-label=&quot;Permalink to &amp;quot;Lag is a subtraction, and neither operand holds still&amp;quot;&quot;&gt;&amp;ZeroWidthSpace;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;For one partition, lag is the end offset minus the group&apos;s committed offset. For a group on a topic, it is that difference summed over the partitions. Three things keep the result from being a record count.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The end offset moves while you read it.&lt;/strong&gt; The committed offsets and the end offsets come from separate requests. On a busy topic the two readings describe different moments.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Not every offset holds a record.&lt;/strong&gt; A transactional producer writes a commit or abort marker into the log, and the marker takes an offset. Compaction removes records and leaves their offsets behind. The distance between two offsets therefore counts positions, and it can overcount records.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The start of the log moves too.&lt;/strong&gt; If retention has deleted records past the group&apos;s committed offset, the group cannot be behind by records that no longer exist.&lt;/p&gt;
&lt;p&gt;Here is the whole per-partition computation in the Kafka driver of &lt;a href=&quot;https://github.com/sudoitir/openbroker&quot; target=&quot;_blank&quot; rel=&quot;noreferrer&quot;&gt;OpenBroker&lt;/a&gt;, the open SDK Rahdar reads every broker through:&lt;/p&gt;
&lt;div class=&quot;language-java vp-adaptive-theme&quot;&gt;&lt;button title=&quot;Copy Code&quot; class=&quot;copy&quot;&gt;&lt;/button&gt;&lt;span class=&quot;lang&quot;&gt;java&lt;/span&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark vp-code&quot; tabindex=&quot;0&quot; v-pre=&quot;&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;long&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; lag &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; at.&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt;lag&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;().&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt;orElse&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(Math.&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt;max&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, last &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; Math.&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt;max&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(at.&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt;offset&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(), first)));&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;&lt;code&gt;at.lag()&lt;/code&gt; is the lag the cluster itself reports for the partition, when it does. Otherwise it is the end offset &lt;code&gt;last&lt;/code&gt; minus the group&apos;s position, with the position clamped to the log start &lt;code&gt;first&lt;/code&gt;, and the result clamped at zero.&lt;/p&gt;
&lt;p&gt;The driver knows what that number is worth. It attaches this sentence to every group it returns:&lt;/p&gt;
&lt;div class=&quot;language-java vp-adaptive-theme&quot;&gt;&lt;button title=&quot;Copy Code&quot; class=&quot;copy&quot;&gt;&lt;/button&gt;&lt;span class=&quot;lang&quot;&gt;java&lt;/span&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark vp-code&quot; tabindex=&quot;0&quot; v-pre=&quot;&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#6A737D;--shiki-dark:#6A737D&quot;&gt;/** Why a lag is only an estimate. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; final&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; String ESTIMATE_REASON &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;        &quot;The end offset moves while it is read, and transaction markers and compaction leave offsets that&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;                +&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt; &quot; hold no record, so the lag can overcount.&quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;h2 id=&quot;a-partition-with-no-answer-is-not-a-partition-with-zero-lag&quot; tabindex=&quot;-1&quot;&gt;A partition with no answer is not a partition with zero lag &lt;a class=&quot;header-anchor&quot; href=&quot;#a-partition-with-no-answer-is-not-a-partition-with-zero-lag&quot; aria-label=&quot;Permalink to &amp;quot;A partition with no answer is not a partition with zero lag&amp;quot;&quot;&gt;&amp;ZeroWidthSpace;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The second problem is worse, because it produces a number that is wrong in the comforting direction.&lt;/p&gt;
&lt;p&gt;Summing over partitions assumes every partition has a lag. Some do not. A group may have no committed offset on a partition. An end offset may fail to come back. The easy code path is &lt;code&gt;getOrDefault(tp, 0L)&lt;/code&gt;, which reports those partitions as fully caught up.&lt;/p&gt;
&lt;p&gt;The driver refuses to do that. A partition without an answer goes into a separate map with its reason, and stays out of the sum:&lt;/p&gt;
&lt;div class=&quot;language-java vp-adaptive-theme&quot;&gt;&lt;button title=&quot;Copy Code&quot; class=&quot;copy&quot;&gt;&lt;/button&gt;&lt;span class=&quot;lang&quot;&gt;java&lt;/span&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark vp-code&quot; tabindex=&quot;0&quot; v-pre=&quot;&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (at &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; null&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    unavailable.&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt;put&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(tp.&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt;partition&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;&quot;The group has no &quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; offsetsName&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt; &quot; offset on this partition.&quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (last &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; null&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; first &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; null&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    unavailable.&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt;put&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(tp.&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt;partition&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;&quot;The partition&apos;s end offset could not be read.&quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#6A737D;--shiki-dark:#6A737D&quot;&gt;    // ... lag computed, added to the breakdown and the total&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;The total then says what it left out. The reason on the group gains a second sentence: &amp;quot;N partitions are left out of the total because their lag is unknown.&amp;quot;&lt;/p&gt;
&lt;p&gt;A total of 12,400 over five of six partitions is a different fact from 12,400 over six of six. The person on call needs to know which one they are reading.&lt;/p&gt;
&lt;h2 id=&quot;the-type-exact-estimate-or-unavailable-with-a-reason&quot; tabindex=&quot;-1&quot;&gt;The type: exact, estimate, or unavailable with a reason &lt;a class=&quot;header-anchor&quot; href=&quot;#the-type-exact-estimate-or-unavailable-with-a-reason&quot; aria-label=&quot;Permalink to &amp;quot;The type: exact, estimate, or unavailable with a reason&amp;quot;&quot;&gt;&amp;ZeroWidthSpace;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;OpenBroker carries this distinction in its API, so a consumer cannot lose it by accident. Counts that a caller acts on, such as the affected count of a preview or the total of a browse, use this type. It is &lt;a href=&quot;https://github.com/sudoitir/openbroker/blob/main/openbroker-api/src/main/java/io/github/sudoitir/openbroker/messaging/Count.java&quot; target=&quot;_blank&quot; rel=&quot;noreferrer&quot;&gt;quoted here in full&lt;/a&gt;, minus the three static factories:&lt;/p&gt;
&lt;div class=&quot;language-java vp-adaptive-theme&quot;&gt;&lt;button title=&quot;Copy Code&quot; class=&quot;copy&quot;&gt;&lt;/button&gt;&lt;span class=&quot;lang&quot;&gt;java&lt;/span&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark vp-code&quot; tabindex=&quot;0&quot; v-pre=&quot;&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#6A737D;--shiki-dark:#6A737D&quot;&gt;/** A number that says how much it can be trusted. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; sealed&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; interface&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; Count&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    record&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; Exact&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;long&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; value) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;implements&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; Count&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#6A737D;--shiki-dark:#6A737D&quot;&gt;    /** Derived, such as a backlog computed from offset distances. Never shown as exact. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    record&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; Estimate&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;long&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; value) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;implements&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; Count&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#6A737D;--shiki-dark:#6A737D&quot;&gt;    /** The system cannot say, and why. An unavailable count is never zero. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    record&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; Unavailable&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(String reason) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;implements&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; Count&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        public&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; Unavailable&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;            Objects.&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt;requireNonNull&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(reason, &lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;&quot;reason&quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Two details do the work:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Unavailable&lt;/code&gt; has no &lt;code&gt;value&lt;/code&gt; field.&lt;/strong&gt; There is nothing to read as zero. The reason is required, so &amp;quot;unknown&amp;quot; always arrives with an explanation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The interface is sealed.&lt;/strong&gt; A &lt;code&gt;switch&lt;/code&gt; over a &lt;code&gt;Count&lt;/code&gt; has to handle all three cases, or the compiler complains. Rahdar&apos;s own code is full of &lt;code&gt;case Count.Unavailable(var reason) -&amp;gt;&lt;/code&gt; branches for this reason.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The backlog metric follows the same rule with a different shape. It is a &lt;code&gt;MetricValue&lt;/code&gt; with a &lt;code&gt;Precision&lt;/code&gt; of &lt;code&gt;EXACT&lt;/code&gt; or &lt;code&gt;ESTIMATE&lt;/code&gt;, and a per-partition breakdown. The Kafka driver always builds a group&apos;s backlog with &lt;code&gt;Precision.ESTIMATE&lt;/code&gt;. There is no code path that reports Kafka lag as exact.&lt;/p&gt;
&lt;p&gt;The trade-off is real. Every consumer of the SDK pays for a three-way branch where a &lt;code&gt;long&lt;/code&gt; would have been one line. We think that is the correct price.&lt;/p&gt;
&lt;h2 id=&quot;what-the-operator-sees&quot; tabindex=&quot;-1&quot;&gt;What the operator sees &lt;a class=&quot;header-anchor&quot; href=&quot;#what-the-operator-sees&quot; aria-label=&quot;Permalink to &amp;quot;What the operator sees&amp;quot;&quot;&gt;&amp;ZeroWidthSpace;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The rule on the screen is one line of TypeScript:&lt;/p&gt;
&lt;div class=&quot;language-ts vp-adaptive-theme&quot;&gt;&lt;button title=&quot;Copy Code&quot; class=&quot;copy&quot;&gt;&lt;/button&gt;&lt;span class=&quot;lang&quot;&gt;ts&lt;/span&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark vp-code&quot; tabindex=&quot;0&quot; v-pre=&quot;&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; backlog.accuracy &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt; &apos;ESTIMATE&apos;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; ?&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt; `≈ ${&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;figure&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;}`&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; figure;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;An exact figure is plain. An estimate carries the approximately-equal mark and has &amp;quot;estimate&amp;quot; in its accessible name, so a screen reader hears it too. An unavailable figure reads &lt;strong&gt;Unavailable&lt;/strong&gt;, never 0.&lt;/p&gt;
&lt;p&gt;The figure is a button. It opens the reason the driver gave, and &lt;strong&gt;Show partitions&lt;/strong&gt; where the system has a breakdown.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://rahdar.dev/blog/2026-12-kafka-consumer-lag-is-an-estimate/subscriptions-light.webp&quot; alt=&quot;The backlog of one consumer group on one topic, by partition: lag, committed offset and end offset, slowest partition first, with the age of the sample&quot;&gt;&lt;/p&gt;
&lt;p&gt;The drawer lists partitions slowest first, and its first line states the age of the sample: &amp;quot;Sampled 0s ago. The slowest partitions come first.&amp;quot; In this capture the group &lt;code&gt;analytics&lt;/code&gt; on topic &lt;code&gt;orders&lt;/code&gt; has six partitions. Four of them have a committed offset of 0, and the six lags sum to 13,200.&lt;/p&gt;
&lt;p&gt;A partition whose lag could not be read shows &lt;strong&gt;Unavailable&lt;/strong&gt; in the Lag column with its reason underneath, and &lt;strong&gt;None&lt;/strong&gt; or &lt;strong&gt;Unknown&lt;/strong&gt; for a missing committed or end offset.&lt;/p&gt;
&lt;p&gt;One candid note: partitions with an unknown lag currently sort to the bottom of that list, below the caught-up ones. There is a fair argument they belong at the top.&lt;/p&gt;
&lt;p&gt;The group&apos;s own page shows the same table per topic:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://rahdar.dev/blog/2026-12-kafka-consumer-lag-is-an-estimate/kafka-group-light.webp&quot; alt=&quot;A Kafka consumer group&apos;s page: type, state, members, and every partition with its lag, committed offset and end offset&quot;&gt;&lt;/p&gt;
&lt;p&gt;The estate Dashboard applies the rule one level up. Its Backlog tile sums every cluster the user may read, across all three systems. In the current capture it reads &lt;code&gt;≈ 297.5K&lt;/code&gt;, and under it:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Estimate: events: 6 subscriptions report an estimated backlog; rabbit: 1 subscription reports no backlog, 5 subscriptions report an estimated backlog.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;A sum is only as exact as its least exact term, and the tile names which terms those are, per cluster.&lt;/p&gt;
&lt;h2 id=&quot;the-same-rule-on-previews&quot; tabindex=&quot;-1&quot;&gt;The same rule on previews &lt;a class=&quot;header-anchor&quot; href=&quot;#the-same-rule-on-previews&quot; aria-label=&quot;Permalink to &amp;quot;The same rule on previews&amp;quot;&quot;&gt;&amp;ZeroWidthSpace;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Every destructive operation in Rahdar has a dry run that returns an affected count without acting. That count has the same problem as lag: the queue or log keeps moving between the preview and the act.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/sudoitir/rahdar/blob/main/docs/adr/0022-dry-run-estimate-and-server-enforced-bulk-cap.md&quot; target=&quot;_blank&quot; rel=&quot;noreferrer&quot;&gt;ADR-0022&lt;/a&gt; settled this early, when Rahdar only spoke to Artemis. The dry-run count is a broker-side estimate and is labelled a point-in-time estimate in the API and the UI. The audit row of the executed operation records the count the broker actually affected. In the ADR&apos;s words, that second number &amp;quot;is the number of record&amp;quot;. When the two disagree, the audit trail holds both.&lt;/p&gt;
&lt;p&gt;Kafka added a twist, recorded in &lt;a href=&quot;https://github.com/sudoitir/rahdar/blob/main/docs/adr/0221-a-log-purge-preview-asks-the-driver.md&quot; target=&quot;_blank&quot; rel=&quot;noreferrer&quot;&gt;ADR-0221&lt;/a&gt;. Purging a group&apos;s backlog means moving the group to the last offset it can read. Rahdar&apos;s bulk preview used to estimate from the scraped lag, which also counts records an open transaction still holds. The confirmation therefore named a move the broker would not make.&lt;/p&gt;
&lt;p&gt;The preview now asks the driver once per selected group, and the number on the confirmation is that answer. The ADR&apos;s decision reads:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A count the driver does not report is unavailable, never zero, and the purge is not offered.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The cost is one driver call per group at preview time, bounded by the existing cap on bulk selections. The ADR lists a batched preview as the alternative, and rejects it for now because it would need a new SDK shape.&lt;/p&gt;
&lt;h2 id=&quot;an-absent-number-reads-as-zero&quot; tabindex=&quot;-1&quot;&gt;An absent number reads as zero &lt;a class=&quot;header-anchor&quot; href=&quot;#an-absent-number-reads-as-zero&quot; aria-label=&quot;Permalink to &amp;quot;An absent number reads as zero&amp;quot;&quot;&gt;&amp;ZeroWidthSpace;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Rahdar&apos;s frontend rules contain one sentence that all of the above follows from: an absent number reads as zero, which is the most dangerous possible misreading.&lt;/p&gt;
&lt;p&gt;Someone paged at 3 a.m. glances at a lag column. A blank cell, a dash and a &lt;code&gt;0&lt;/code&gt; all tell them the same thing: this consumer is fine, look elsewhere. If the truth is &amp;quot;we could not read this partition&amp;quot;, the console has just sent them away from the problem.&lt;/p&gt;
&lt;p&gt;So the number says what it is. Exact figures are plain, estimates are marked and explained, and unknowns say &lt;strong&gt;Unavailable&lt;/strong&gt; and why.&lt;/p&gt;
&lt;p&gt;To see it on your own cluster:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://rahdar.dev/guide/quickstart.html&quot;&gt;Quickstart&lt;/a&gt; to run Rahdar and register a cluster.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://rahdar.dev/guide/kafka.html&quot;&gt;Kafka guide&lt;/a&gt; for consumer groups, lag and offset resets.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://rahdar.dev/guide/dashboard.html&quot;&gt;Dashboard guide&lt;/a&gt; for the estate totals and how each states its accuracy.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Rahdar and OpenBroker are both Apache-2.0. The lag code quoted above is in &lt;a href=&quot;https://github.com/sudoitir/openbroker/blob/main/openbroker-kafka/src/main/java/io/github/sudoitir/openbroker/kafka/admin/Subscriptions.java&quot; target=&quot;_blank&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;Subscriptions.java&lt;/code&gt;&lt;/a&gt; of the Kafka driver.&lt;/p&gt;
&lt;p&gt;&lt;small&gt;Apache Kafka, Apache ActiveMQ Artemis and RabbitMQ are trademarks of their respective owners. Rahdar is not affiliated with or endorsed by them.&lt;/small&gt;&lt;/p&gt;
</content>
  </entry>
</feed>
