<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Paresh Yadav on Medium]]></title>
        <description><![CDATA[Stories by Paresh Yadav on Medium]]></description>
        <link>https://medium.com/@pareshyadav.ksp?source=rss-819484d48518------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NpE-IueF-4DhgNPzU-Ritw.jpeg</url>
            <title>Stories by Paresh Yadav on Medium</title>
            <link>https://medium.com/@pareshyadav.ksp?source=rss-819484d48518------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 18:23:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pareshyadav.ksp/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Kafka vs a Queue: A Log Is Not a Message Queue]]></title>
            <link>https://medium.com/@pareshyadav.ksp/kafka-vs-a-queue-a-log-is-not-a-message-queue-816df0a09fa4?source=rss-819484d48518------2</link>
            <guid isPermaLink="false">https://medium.com/p/816df0a09fa4</guid>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[event-driven-architecture]]></category>
            <category><![CDATA[solution-architect]]></category>
            <dc:creator><![CDATA[Paresh Yadav]]></dc:creator>
            <pubDate>Mon, 09 Nov 2026 06:37:13 GMT</pubDate>
            <atom:updated>2026-11-09T06:37:13.651Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A queue deletes a message once it is acknowledged. Kafka keeps it in a log, and that one difference changes replay, sharing and scaling.</em></p><p>Kafka and a message queue both move messages between services, so they are often treated as the same tool. They are built on different ideas.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dk_QnW7RTJXF1hZk0giHzw.png" /></figure><h3>The core difference</h3><p>A <strong>queue</strong> holds work. A consumer takes a message, processes it and acknowledges it. The broker can then discard it. RabbitMQ’s documentation describes it this way: a positive acknowledgement tells the broker the message was delivered and can be discarded.</p><p><strong>Kafka</strong> holds history. Events are appended to a log, and reading an event does not remove it. Kafka’s documentation states that events are not deleted after consumption. They are removed only when the retention period you set for the topic ends.</p><p>Everything else in the table follows from that.</p><h3>What changes in practice</h3><ul><li><strong>Replay.</strong> A Kafka consumer can move its offset back and read old events again, for example to recover after a bug in its code. This works only inside the retention period. A queue cannot do this, because the message is gone</li><li><strong>Several services.</strong> In Kafka, each consumer group gets every event. Ordering, shipping and payment services can each read the same “order placed” event at their own speed. In a queue, each message goes to one consumer</li><li><strong>Consumer position.</strong> A queue tracks every message with an acknowledgement. Kafka tracks one number per partition, the offset. Kafka’s design notes call this very cheap</li><li><strong>Scaling.</strong> A Kafka topic is split into partitions across brokers. Inside a consumer group, each partition is read by one consumer at a time, so you scale by adding consumers up to the number of partitions. A queue scales by adding consumers</li><li><strong>Ordering.</strong> Kafka guarantees order inside a partition, not across the topic. Events with the same key go to the same partition, so keying by order ID keeps one order’s events in sequence</li></ul><h3>Which one to use</h3><ul><li><strong>Use a queue</strong> for jobs that should run once: send an email, resize an image</li><li><strong>Use Kafka</strong> for facts that several systems react to, or that someone may need to read again</li></ul><p>Newer Kafka versions also describe share groups, which share records in a queue-like way. Check what your version supports.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=816df0a09fa4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Kafka Partition Count You Can’t Take Back]]></title>
            <link>https://medium.com/@pareshyadav.ksp/the-kafka-partition-count-you-cant-take-back-59372a47181e?source=rss-819484d48518------2</link>
            <guid isPermaLink="false">https://medium.com/p/59372a47181e</guid>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[mirrormaker2]]></category>
            <category><![CDATA[kafka-consumer]]></category>
            <category><![CDATA[kafka-partition]]></category>
            <category><![CDATA[kafka-replication]]></category>
            <dc:creator><![CDATA[Paresh Yadav]]></dc:creator>
            <pubDate>Mon, 09 Nov 2026 06:16:57 GMT</pubDate>
            <atom:updated>2026-11-09T06:16:57.323Z</atom:updated>
            <content:encoded><![CDATA[<p>One sizing question, and the replication detail that reversed my answer</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZN9EDuKvbWw6dzAp_QPirA.gif" /><figcaption>The topic creation form: replication factor and partition count, with the final column reading “Can be altered — No”</figcaption></figure><p>A platform team asked me for two numbers before they would create our production Kafka topics: replication factor and partition count. Their form listed the limits, and then, in the last column:</p><p><strong>Can be altered: No.</strong></p><p>Whatever I wrote down would be true for the life of those topics. I had a ready answer. It was wrong, and why it was wrong is the useful part.</p><h3>One sentence explains partitions</h3><blockquote><em>A partition is both the unit of parallelism and the unit of ordering.</em></blockquote><p>You cannot buy more of one without spending the other. That tension is the entire subject.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLeceDfWboCuuMxqU9pcTA.gif" /><figcaption>A dial sliding from one partition to eight: ordering holds only at one partition, while the number of working consumers rises with the count</figcaption></figure><h3>Keys decide where records land</h3><p>Kafka guarantees order only within a partition, and which partition a record lands in comes from its key:</p><pre>partition = hash(keyBytes) % numPartitions</pre><p>With a key, every event for customer-4471 goes to the same partition and is read in the order it was written. With a null key, Kafka has nothing to hash and spreads records across all partitions — so two events about the same customer, produced a second apart, can be processed in either order.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R9Hibomp8X2r4Sm7xtdgZQ.gif" /><figcaption>Keyed records all landing in one partition and read 1, 2, 3; null-key records scattering across three partitions and read 2, 1, 3</figcaption></figure><p>Our records had null keys. We checked rather than assumed: a console consumer with print.key=true takes thirty seconds and settles arguments that otherwise run for a week.</p><p>Which meant ordering was surviving on exactly one thing — the topic had a single partition. Not by design. The cluster had one broker, and one partition was the path of least resistance. An accident of infrastructure was holding up a correctness guarantee, which is the kind of thing that breaks silently.</p><h3>What more partitions gain, and what they cost</h3><p><strong>You gain</strong> consumer parallelism, which is the main one: each partition is assigned to exactly one consumer in a group, so the partition count is a hard ceiling on how many consumers can actively work. You also gain throughput across more brokers, and headroom to scale later.</p><p><strong>You pay</strong> in ordering. Above one partition there is no topic-wide order. Keyed records still get per-key ordering, which is usually what you actually need. Unkeyed records get nothing.</p><p>There are broker-side costs too — file handles, per-partition producer buffers, slower leader elections. Those matter at thousands of partitions. At three they are noise. Ordering is the cost that actually decides this question.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M8lxA9MoSVTsANBZM0xKmw.gif" /><figcaption>Raising a topic from three partitions to four: the hash result changes, so new records for the same key land in a different partition from their own history</figcaption></figure><p>One more, and it is underrated: <strong>increasing partitions later breaks keyed ordering.</strong> Kafka lets you increase a partition count and never decrease it, but numPartitions sits inside the hash. Existing records stay where they are while new records for the same key start landing elsewhere, splitting that key&#39;s history in two. &quot;Start small and grow later&quot; is a migration, not a tuning step.</p><h3>Do more partitions mean more consumers?</h3><p>No. A single consumer will happily read every partition of a topic. Adding partitions raises a ceiling that nobody is obliged to reach, and consumers beyond the partition count simply sit idle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uCl5IHDakcXaLtaXETZTXg.gif" /><figcaption>Consumers joining a group one at a time: the first holds all three partitions, the group rebalances as others join, and the fourth is left idle</figcaption></figure><p>The trap runs in the other direction:</p><p><strong>Ordering is lost with multiple partitions even if you have exactly one consumer.</strong> A consumer interleaves the partitions it polls and makes no attempt to reconstruct a global sequence, because the information required no longer exists. You cannot recover ordering by deploying fewer consumers or by being clever in the application.</p><p>Partition count is an ordering decision. It is not a consumer deployment decision.</p><h3>Is one partition just a queue?</h3><p>For ordering, yes — strict FIFO, and at most one active consumer per group. For everything else, no:</p><ul><li><strong>Records are not deleted when read.</strong> Anything inside the retention window can be replayed by rewinding offsets, which a queue cannot do.</li><li><strong>Every consumer group receives every record.</strong> It is still publish-subscribe; you have merely arranged for there to be one subscriber.</li><li><strong>Offsets are a cursor, not per-message acknowledgements.</strong> You cannot acknowledge record 5 while leaving record 4 outstanding, and redelivery means rewinding everything after that point.</li></ul><p>And head-of-line blocking is absolute. One slow record stalls the whole topic, and you cannot add workers to drain around it — because that is precisely the ability you gave up.</p><h3>The detail that reversed my answer</h3><p>Our topics were not produced to directly on the destination cluster. They were replicated into it by MirrorMaker 2.</p><p>Which raised a question I had never thought to ask: when MirrorMaker copies a record into a topic with a different partition count, how does it decide where the record goes?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RXNFtwDYbDYGtKOpJTg3NA.gif" /><figcaption>Side by side: the assumed behaviour scattering records across three destination partitions, against the actual behaviour placing every record on partition 0</figcaption></figure><p>I assumed it produces like any other client — the partitioner runs, null keys scatter. That assumption was sitting in our design documentation, written down as fact. It is wrong:</p><pre>return new SourceRecord(<br>        ...<br>        targetTopic, record.partition(),   // pinned to the source partition<br>        ...);</pre><p>The destination partition is set explicitly to the index the record already had upstream. The producer partitioner never runs. KIP-382, the design document behind MirrorMaker 2, states it outright: <em>remote partition i is a replica of source partition i</em>.</p><p>Three consequences fell out, each contradicting something I believed that morning:</p><ul><li><strong>A one-partition source feeds exactly one destination partition.</strong> The others never receive a record, and no destination-side setting can give them one.</li><li><strong>Ordering on the destination was already safe</strong> — not despite the null keys, but because the keys were never consulted.</li><li><strong>Adding keys would have achieved nothing on its own.</strong> Keys place records on the <em>source</em> topic, and hash(key) % 1 is zero for every key ever written.</li></ul><p>The number the platform team asked me for was inert. The real lever was the source topic’s partition count — in a system we controlled, which nobody had asked about because it was not on anyone’s form.</p><h3>What changed</h3><p>Once you know the mechanism, the recommendation inverts. A three-partition destination behaves identically to a one-partition one while the source has a single partition, so it carries no ordering risk. And because the setting is irreversible, three is free insurance for the day we key the records and widen the source. Asking for one would have bricked that door shut.</p><p>Same topic, same volumes, same evening. The only thing that changed was that I read the source code instead of trusting my model of it.</p><h3>Three things worth keeping</h3><ol><li><strong>A partition count is an ordering decision wearing a performance decision’s clothes.</strong> Decide it by asking what must stay in order and what the key is, not by counting consumer instances.</li><li><strong>Verify your keys instead of assuming them.</strong> Thirty seconds with a console consumer beats a week of architectural debate.</li><li><strong>When a setting cannot be undone, optimise for keeping options open, not for the smallest number.</strong> The conservative-sounding value is often the reckless one.</li></ol><p>And the one I keep coming back to: when a decision feels harder than it should, check whether you are reasoning about the right layer. Six of us debated a number that turned out not to matter, because nobody asked which component was actually choosing the partition.</p><p><em>If this helped, follow for more on agents, system design, and production AI.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59372a47181e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RL-4 — When the Rate Limiter’s Own Store Goes Down: Failure, Cost and Observability]]></title>
            <link>https://medium.com/@pareshyadav.ksp/rl-4-when-the-rate-limiters-own-store-goes-down-failure-cost-and-observability-7b56e8843df8?source=rss-819484d48518------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b56e8843df8</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[solution-architect]]></category>
            <category><![CDATA[rate-limiting]]></category>
            <category><![CDATA[api-gateway]]></category>
            <category><![CDATA[observability]]></category>
            <dc:creator><![CDATA[Paresh Yadav]]></dc:creator>
            <pubDate>Sun, 08 Nov 2026 02:06:35 GMT</pubDate>
            <atom:updated>2026-11-08T02:06:35.724Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A distributed rate limiter adds a dependency to every API call. The real design work is deciding what happens when that dependency is slow, wrong, or gone, and what it costs you when it works.</em></p><h3>Who this is for</h3><p>This is the fourth and last article in the <strong>RL series</strong>. It is for <strong>solution architects</strong>, <strong>API platform engineers</strong>, <strong>SRE and platform teams</strong> who own the gateway in production. The question to take away: <em>what does this limiter do at 3 a.m. when its store stops answering?</em></p><p>In <a href="https://medium.com/@pareshyadav.ksp/rl-2-the-shared-counter-identity-policy-and-document-design-ba0165106b55">RL-2</a> the counter moved out of the gateways into one shared store. In <a href="https://medium.com/@pareshyadav.ksp/rl-3-the-race-at-99-atomic-updates-and-counting-algorithms-eab38811b508">RL-3</a> the check and the increment became one atomic operation. The limiter now gives the right answer.</p><p>It also changed something else. Before, a request was checked in the gateway’s own memory, which cannot fail in an interesting way. Now every request makes a call to a separate system first. This article is about the three consequences: what to do when that call fails, what it costs at volume, and how to see what the limiter is doing. It is a design walkthrough with illustrative numbers, not a measurement from a live system.</p><h3>When the counter store is down</h3><p>Suppose the OpenSearch cluster is unreachable, or the update times out, or conflicts keep failing past the retry limit. A request arrives and the gateway cannot get an answer to “may this one proceed?”</p><p>There are only two honest choices:</p><ul><li><strong>Fail open</strong> — let the request through without a verdict</li><li><strong>Fail closed</strong> — reject the request without a verdict</li></ul><p>Neither is correct everywhere. Which one is right depends on what the API protects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J4ZNLRTFIJ4hrv1Tobuebw.png" /></figure><ul><li><strong>A public read API</strong> can usually fail open. Being unavailable is worse than letting a burst through for a few minutes. Pair it with a rough local cap so open does not mean unlimited</li><li><strong>A payment API</strong> leans to failing closed, or to a tightly bounded fallback. A wrong accept costs more than a refused call that the client can retry</li><li><strong>An expensive reporting API</strong> should fail closed. One client with no limit can exhaust a costly backend and hurt everyone</li><li><strong>A health or status API</strong> needs its own policy. It must keep working precisely when the shared store does not, so do not make it depend on the counter at all</li></ul><p>Because the policy is looked up per API, the failure strategy can live in the same record as the limit and the algorithm. Decide it per API, in advance, and write it down. The worst time to choose is during the outage.</p><h3>A local fallback has limits too</h3><p>A bounded local fallback usually means each gateway applies the limit divided by the number of gateways, the idea from <a href="https://medium.com/@pareshyadav.ksp/rl-2-the-shared-counter-identity-policy-and-document-design-ba0165106b55">RL-2</a>. It is not exact, because the load balancer does not split traffic evenly. As a short-term protection while the shared store is down, that is acceptable. As a permanent design it is not.</p><h3>A slow limiter is worse than a broken one</h3><p>A failed call is quick to handle. A slow call holds a thread and delays the API request that was waiting on it. If the limiter takes 2 seconds to time out, every API call pays 2 seconds, which is an outage of your own making.</p><p>So put a short timeout on the limiter call, much shorter than the API’s own timeout, and apply the failure policy when it expires. A circuit breaker around the call helps for the same reason: after enough failures, skip the store and apply the fallback immediately instead of waiting each time.</p><h3>What the client sees</h3><p>When you reject, answer with HTTP 429. RFC 6585 says the response may include a Retry-After header, and it is worth sending so a well-behaved client knows when to try again. The same RFC also notes that under a real attack, dropping the connection can be better than writing a 429 for every single request, because the answers themselves cost you work.</p><h3>The cost of checking every request</h3><p>The design so far checks the shared counter on every request. That is exact, and it is not free.</p><p>Say a busy platform serves 10,000 requests per second. Now the store takes 10,000 atomic updates per second, and each one adds a network round trip to the front of an API call. The limiter is protecting the backend while turning into a load of its own.</p><p>Two things get hot.</p><p><strong>The hot counter.</strong> The document ID is deterministic, so every update for one consumer and window goes to the same document, on the same shard. A large partner with high traffic concentrates its load on one counter, and concurrent updates start to collide. Many small partners spread out nicely. One big one does not. This is the price of the deterministic ID from <a href="https://medium.com/@pareshyadav.ksp/rl-2-the-shared-counter-identity-policy-and-document-design-ba0165106b55">RL-2</a>.</p><p><strong>The hot shard.</strong> If a few busy consumers happen to hash to the same shard, that shard takes the heat while others sit idle.</p><h3>Take tokens in batches</h3><p>A common way to cut the load is to stop asking for every request. A gateway takes a batch of tokens from the shared counter, say 10, and then serves the next 10 requests from its own memory before going back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O90wjuy9H3a_C0atBNVooA.png" /></figure><p>The store sees one update per batch instead of one per request, and most checks become local and fast. The global limit still holds, because tokens leave the shared counter when the batch is taken, not when they are used.</p><p>The cost is <strong>stranded tokens</strong>. Say a gateway takes 10 tokens and then receives no more traffic for that partner. Those 10 tokens are not coming back to anyone until the window ends. If the gateway crashes, they are gone for good. The partner can be rejected while unused tokens sit in another gateway’s memory.</p><p>The batch size matters more than it first appears. With a limit of 100 and three gateways taking 10 each, up to 30 tokens, almost a third of the limit, can sit idle in local hands. The batches of 30 in <a href="https://medium.com/@pareshyadav.ksp/rl-1-the-distributed-gatekeeper-designing-rate-limiting-for-an-enterprise-api-platform-0da73f324d7a">RL-1</a> are even coarser: 90 of the 100 tokens would be spread across three gateways at once. Batching suits large limits where a batch is a small fraction. For a limit of 100 per minute, checking every request is the better trade. This is a trade-off, not a free speedup: you give up some exactness to buy cheaper checks.</p><h3>Cleaning up</h3><p>Every minute, for every consumer and API, a new counter document appears. Nothing deletes the old ones.</p><p>Deleting documents one by one is the expensive way. OpenSearch’s index state management can delete whole indexes by age, which is much cheaper. So make the index time-based, for example one index per day, such as api-rate-limits-2026.11.06, and let a policy remove indexes older than you need. Build the index name from the same timestamp as the document ID, so every gateway still lands on the same document.</p><p>One detail to watch is the clock. Window boundaries come from each gateway’s own time. If two gateways disagree by a second, they briefly use different windows near the edge. Keep clocks synced and accept that edges are fuzzy by a second.</p><h3>What to watch</h3><p>A limiter that rejects the wrong requests, or silently stops limiting, is very hard to notice from the outside. A few metrics make it visible:</p><ul><li>http_requests_total — all requests, by API and status</li><li>http_requests_rejected_total — requests answered with 429. A sudden rise for one consumer is either abuse or a customer bug</li><li>rate_limit_remaining — how much of the limit is left. It shows who is close to the edge before they hit it</li><li>rate_limit_check_duration_seconds — how long the check takes. This is the first number to move when the store struggles</li><li>opensearch_errors_total — store failures, which is how you know the failure policy is running</li><li>rate_limit_update_conflicts_total — version conflicts. If this climbs, a hot counter needs attention</li></ul><p>Two notes. Prometheus convention is to use base units such as seconds in the name and _total for counters, which is why the duration metric ends in _seconds. And be careful with labels. A label per consumer is fine for a few dozen partners and risky for thousands, because each new label value creates a new time series.</p><p>I would also add one more counter, which is my own suggestion: a count of requests let through because the limiter failed open. If it is not zero and nobody is alerted, you are running without a limit and do not know it.</p><h3>The whole path, revisited</h3><p>This is the request path from <a href="https://medium.com/@pareshyadav.ksp/rl-1-the-distributed-gatekeeper-designing-rate-limiting-for-an-enterprise-api-platform-0da73f324d7a">RL-1</a>, now with the lessons of this article on it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BSl64dUsvP3UlGG3blkSeg.gif" /></figure><p>Three things from this article belong on that picture:</p><ul><li><strong>On the arrow from the limiter to OpenSearch</strong> — a short timeout and a circuit breaker, so a slow store cannot slow every API call</li><li><strong>Inside the policy engine</strong> — the failure strategy next to the limit, window and algorithm, so the limiter knows what to do when the arrow breaks</li><li><strong>On the way to Prometheus and Grafana</strong> — the counts of rejections, store errors, update conflicts and requests let through because the limiter failed open</li></ul><h3>Principles</h3><ul><li><strong>A shared limiter is a new dependency, so give it a failure policy.</strong> Choose fail open or fail closed per API, before an outage, and write it down</li><li><strong>A health endpoint should not need the limiter.</strong> It has to work when the shared store does not</li><li><strong>Time-box the check.</strong> A limiter that responds slowly hurts more than one that fails fast</li><li><strong>Exactness costs a call per request.</strong> Batching tokens is cheaper and leaves unused tokens stranded. Size the batch against the limit</li><li><strong>Measure the limiter.</strong> Rejections, remaining quota, check time, store errors and conflicts tell you whether it works, and a fail-open counter tells you when it does not</li></ul><p>A rate limiter is easy to explain and easy to demo. The hard part starts when the thing that holds the count stops answering, and your design has to already know what to do.</p><p><strong>Previous:</strong> <a href="https://medium.com/@pareshyadav.ksp/rl-3-the-race-at-99-atomic-updates-and-counting-algorithms-eab38811b508">RL-3 — Atomic Updates and Counting Algorithms</a></p><p>If this helped, follow for more on agents, system design, and production AI.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b56e8843df8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RL-3 — The Race at 99: Atomic Updates and Counting Algorithms]]></title>
            <link>https://medium.com/@pareshyadav.ksp/rl-3-the-race-at-99-atomic-updates-and-counting-algorithms-eab38811b508?source=rss-819484d48518------2</link>
            <guid isPermaLink="false">https://medium.com/p/eab38811b508</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[api-design]]></category>
            <category><![CDATA[rate-limiting]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[concurrency]]></category>
            <dc:creator><![CDATA[Paresh Yadav]]></dc:creator>
            <pubDate>Sun, 08 Nov 2026 01:41:22 GMT</pubDate>
            <atom:updated>2026-11-08T02:16:31.306Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A shared counter fixes the multiplication problem and opens a smaller one. Two gateways read 99 at the same moment, and both let a request through. The fix is one atomic step, and then a choice between four ways of counting.</em></p><h3>Who this is for</h3><p>This is the third article in the <strong>RL series</strong>. It is for <strong>solution architects</strong>, <strong>API platform engineers</strong> and <strong>senior developers</strong> who review concurrency in shared-state designs. You need no OpenSearch experience, only the habit of asking: <em>what happens when two requests arrive at the same instant?</em></p><p>In <a href="https://medium.com/@pareshyadav.ksp/rl-1-the-distributed-gatekeeper-designing-rate-limiting-for-an-enterprise-api-platform-0da73f324d7a">RL-1</a> and <a href="https://medium.com/@pareshyadav.ksp/rl-2-the-shared-counter-identity-policy-and-document-design-ba0165106b55">RL-2</a>, a rate limit of 100 requests per minute became 300 because each of three gateways kept its own counter. We fixed it by moving the counter into one shared store, with one document per consumer, API and minute.</p><p>A shared counter is necessary. It is not enough. This article is about the bug that survives it, how to close it, and how to pick the counting method behind the limit. As before, this is a design walkthrough with illustrative numbers. I have not run the request below against a live cluster, so check it against the docs for your OpenSearch version before you rely on it.</p><h3>The race at 99</h3><p>Here is the limiter, written the way most people write it first:</p><pre>count = store.read(counterId)<br>if count &gt;= 100:<br>    reject()<br>else:<br>    store.increment(counterId)<br>    accept()</pre><p>It reads well. Now put two gateways on it, with the counter at 99, one request short of the limit:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3BCDu2WvuWmSwl1cMqZIZw.png" /></figure><p>Gateway 1 reads 99. Before it can do anything, Gateway 2 also reads 99. Both check “99 is less than 100”, both say yes, and both add one. Two requests were accepted when only one slot was left. The counter ends at 101.</p><p>The shared counter did its job. The bug is that <strong>the check and the increment are two separate steps</strong>, and anything can happen between them. This kind of bug is called <strong>check-then-act</strong>. It is the same shape as two people booking the last seat on a flight because each saw the seat as free.</p><p>There is a second version of the same bug. If the code writes the new value instead of adding one, so store.write(counterId, count + 1), both gateways write 100. Now the counter says 100 and 101 requests were accepted. One increment was lost, and the counter now under-reports.</p><p>At 100 requests per minute, being off by one hardly matters. With heavy traffic and many gateways, the gap grows with the number of requests that overlap, and it grows exactly when the system is busiest, which is when a limit is supposed to protect you.</p><h3>The fix: one operation, not two</h3><p>The check and the increment must happen as <strong>one atomic operation</strong> inside the store. No other write may land between “look at the number” and “change the number”.</p><p>OpenSearch does this with a scripted update. The script runs inside the store, next to the data:</p><pre>POST /api-rate-limits/_update/customerA_accountAPI_202611061030?retry_on_conflict=5<br>{<br>  &quot;scripted_upsert&quot;: true,<br>  &quot;script&quot;: {<br>    &quot;lang&quot;: &quot;painless&quot;,<br>    &quot;source&quot;: &quot;if (ctx._source.requestCount &gt;= params.limit) { ctx.op = &#39;none&#39;; } else { ctx._source.requestCount += 1; }&quot;,<br>    &quot;params&quot;: { &quot;limit&quot;: 100 }<br>  },<br>  &quot;upsert&quot;: { &quot;requestCount&quot;: 0 }<br>}</pre><p>The field is requestCount, the same one in the counter document from <a href="https://medium.com/@pareshyadav.ksp/rl-1-the-distributed-gatekeeper-designing-rate-limiting-for-an-enterprise-api-platform-0da73f324d7a">RL-1</a>. Read the request in three parts:</p><ul><li>upsert<strong> with </strong>scripted_upsert — if the document for this minute does not exist yet, create it with requestCount: 0 and run the script on it. The first request of every minute creates its own counter. No separate setup step is needed</li><li><strong>The script</strong> — if the count has reached the limit, set ctx.op = &#39;none&#39;, which means &quot;change nothing&quot;. Otherwise add one. The limit comes in as a parameter, so one script serves every policy</li><li><strong>The result</strong> — the response tells you what happened. created or updated means the request was counted, so the gateway accepts it. noop means the limit was already reached, so the gateway answers 429</li></ul><p>The gateway never reads the number and decides on its own. It sends the rule to the store and gets back a verdict.</p><h3>What “atomic” means here</h3><p>It is worth knowing how this works underneath, because it explains a cost you will meet in <a href="https://medium.com/@pareshyadav.ksp/rl-4-when-the-rate-limiters-own-store-goes-down-failure-cost-and-observability-7b56e8843df8">RL-4</a>.</p><p>An update in OpenSearch fetches the document, runs the script, and writes the result back as a new version. If another update changed the document in between, the write is rejected with a <strong>409 version conflict</strong>. By default OpenSearch does not retry that. The retry_on_conflict setting tells it to fetch the fresh document and run the script again.</p><p>Replay the race with this design. Both gateways try at 99. One wins and makes it 100. The other gets a conflict, retries, reads 100, and the script returns noop. The second gateway answers 429. The limit holds.</p><p>So the safety is real, but it is optimistic. Under very heavy traffic on one counter, many updates collide and retry. We will count those collisions as a metric later.</p><h3>If you use Redis instead</h3><p>Redis gives you the same idea with less ceremony. INCR is atomic and returns the new value, so &quot;increment, then compare the result with the limit&quot; has no gap. A Lua script is also atomic when you need more than one step. The mistake to avoid is the same one: do not read, decide, and write as three separate calls. Even the Redis documentation shows one rate-limiter variant that admits a race.</p><h3>Four ways to count</h3><p>“Count requests per minute” hides a real choice. The counter in <a href="https://medium.com/@pareshyadav.ksp/rl-2-the-shared-counter-identity-policy-and-document-design-ba0165106b55">RL-2</a> was a fixed window. There are three other common methods:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hgY4phWjWZhB-A9ziwF5Hw.png" /></figure><p><strong>Fixed window.</strong> One counter per time window, which is what the document ID …_202611061030 already does. It is the cheapest and the easiest to explain. Its weakness is the edge. A partner sends 100 requests at 10:30:59 and 100 more at 10:31:00. Each window sees exactly 100, and the backend gets 200 requests in about two seconds.</p><p><strong>Sliding log.</strong> Store a timestamp for every request. To check, drop the timestamps older than one minute and count what is left. This is exact and has no edge problem. The price is memory and work that grow with the limit. It is fine at 100 per minute and heavy at 10,000.</p><p><strong>Sliding counter.</strong> Keep two fixed-window counters, the previous minute and the current one, and blend them. Say it is 10:31:15, so 25% of the current minute has passed. The previous minute had 80 requests and the current one has 30. The last 60 seconds still include 75% of the previous window, so the estimate is 30 + (80 × 0.75) = 90. It is an estimate, because it assumes the previous minute’s traffic was spread evenly. In return you get most of the accuracy of the log for the storage of two numbers.</p><p><strong>Token bucket.</strong> Think of a bucket that holds tokens. Each request takes one. If the bucket is empty, the request is rejected. Tokens are added back at a steady rate, and the bucket can never hold more than its capacity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XNNa1hHZTwCmoMHxJSuv_w.gif" /></figure><p>In the diagram the bucket holds 100 and refills 10 tokens per second. A quiet partner can send 100 requests at once, then settles at 10 per second. That is a different policy from “100 per minute”, and that is the point. <strong>The algorithm is part of the policy</strong>, not an implementation detail. You do not need a background job to refill the bucket. Store the token count and the time of the last refill, and work out the refill when the next request arrives. That calculation has to be inside the same atomic update, for the same race reason as above.</p><h3>Which one to use</h3><p>There is no best algorithm, only a best fit for each API. As a starting point:</p><ul><li><strong>Fixed window</strong> when simplicity matters and an edge burst is acceptable, such as a daily or monthly quota</li><li><strong>Sliding log</strong> when the limit is strict and low, and you want exact counts</li><li><strong>Sliding counter</strong> when you want smooth behaviour at a larger scale without paying for a log</li><li><strong>Token bucket</strong> when short bursts are normal and fine, as with a mobile app that opens and fires several calls at once</li></ul><p>Because the limit is already looked up per consumer and API, the algorithm can be one more field in that policy. The gateway reads “100, one minute, fixed window” for one API and “50 tokens, refill 5 per second” for another, and calls the same atomic operation either way.</p><h3>Principles</h3><ul><li><strong>A check and an increment that are separate steps are a race.</strong> Any “read, decide, write” over shared state needs to be one atomic operation inside the store</li><li><strong>Send the rule to the data, not the data to the rule.</strong> A script that runs in the store removes the gap that a read-then-write across the network leaves open</li><li><strong>Atomic does not mean free.</strong> Optimistic updates retry on conflict, so a hot counter pays for its safety in retries</li><li><strong>Pick the counting method per API.</strong> Fixed window, sliding log, sliding counter and token bucket each fail in a different way. Choose by the failure you can live with</li><li><strong>Treat the algorithm as policy.</strong> Store it next to the limit so it can change without a code change</li></ul><p>The last one I would put on the wall: the bug at 99 does not show up in a test with one client. It only exists when two requests arrive close together, which is the exact situation a rate limiter is built for.</p><p><strong>Previous:</strong> <a href="https://medium.com/@pareshyadav.ksp/rl-2-the-shared-counter-identity-policy-and-document-design-ba0165106b55">RL-2 — The Shared Counter </a>· <strong>Next:</strong> <a href="https://medium.com/@pareshyadav.ksp/rl-4-when-the-rate-limiters-own-store-goes-down-failure-cost-and-observability-7b56e8843df8">RL-4 — Failure, Cost and Observability</a></p><p>If this helped, follow for more on agents, system design, and production AI.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eab38811b508" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Coordination, CAP, and PACELC: How Distributed Systems Agree Under Failure]]></title>
            <link>https://medium.com/@pareshyadav.ksp/coordination-cap-and-pacelc-how-distributed-systems-agree-under-failure-5a3b27322c0c?source=rss-819484d48518------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a3b27322c0c</guid>
            <category><![CDATA[cap]]></category>
            <category><![CDATA[pacelc-theorem]]></category>
            <category><![CDATA[coordination]]></category>
            <category><![CDATA[eventual-consistency]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <dc:creator><![CDATA[Paresh Yadav]]></dc:creator>
            <pubDate>Fri, 06 Nov 2026 13:53:27 GMT</pubDate>
            <atom:updated>2026-11-06T13:53:27.629Z</atom:updated>
            <content:encoded><![CDATA[<p>On a single machine, coordination is free. One memory space, one source of truth, one process deciding what happens next. Then you scale out — and the simplicity vanishes.</p><p>Distributed systems spread work across machines that cannot see each other’s memory. Independent nodes must agree on shared state, but networks fail, clocks lie, and processes crash mid-thought. Without coordination, chaos follows:</p><ul><li>No node knows who should run a critical task</li><li>Two workers process the same queue job twice</li><li>Machines overwrite each other’s data</li><li>Dead nodes stay in routing tables</li></ul><p>This is the coordination problem. It combines “state replication” (same data on all nodes), “heartbeats” (alive signals), and “agreement protocols”. This story walks through the tools engineers built to make independent machines behave like one reliable system — and the trade-off theorems that explain why every distributed database makes different choices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*az62-6-TvFZy9zbY9Uow2g.gif" /><figcaption>Coordination Primitives</figcaption></figure><p>Think of coordination as a toolkit. Four primitives cover most real-world needs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c1NTFnpAnvZrzfcyjnAGyw.gif" /></figure><h3>Leader election</h3><p>Leader election — one node handles writes or coordinates work, such as a DB primary. Bully and Ring are classic algorithms. If the leader dies, followers re-elect.</p><p>Recall hook — ticket booking: without a leader, two DB replicas could both approve seat 7A → overselling. A leader serializes writes in one agreed order, so all replicas converge on the same decision.</p><h3>Distributed locks</h3><p>Distributed locks — mutual exclusion across machines. They are the distributed version of a lock in a single-process program: only one participant can use a shared resource at a time.</p><p>Recall hook — daily email report: three scheduler replicas run for high availability, but only one should send the report per day. The winner acquires a lock; the others skip → exactly-once execution. ActiveMQ HA is another example with shared message store.</p><p>Two flavors:</p><ul><li><strong>Pessimistic lock:</strong> acquire first, then act (most coordination tools).</li><li><strong>Optimistic lock:</strong> act first, verify no conflict later.</li></ul><h3>Consensus</h3><p>Consensus — nodes agree on one value; decision cannot be undone. Paxos (foundational); Raft (easier to implement; powers etcd and many modern systems).</p><p>When the decision itself must be irrevocable — a committed transaction, an elected leader’s term, a cluster metadata update — consensus is the mechanism behind the scenes.</p><h3>Service discovery</h3><p>Service discovery — dynamic registry + heartbeats; internal real-time DNS as pods scale up/down. When a service starts, it registers itself and sends heartbeats. Other services query the registry to find live peers. Without it, traffic can route to ghosts.</p><h3>ZooKeeper vs etcd</h3><p>These primitives rarely live inside your app code. They live in dedicated coordination services. ZooKeeper and etcd run as separate quorum clusters: a majority of nodes must be operational and agree before changes take effect. That majority rule is what lets them stay reliable under node failures and some network partitions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HCIRH1owrKYFb0lg8Le44w.png" /></figure><blockquote>ZooKeeper uses ZooKeeper Atomic Broadcast (ZAB) and stores data in a hierarchy of znodes, similar to a file system. It is common in HBase, Kafka, Hadoop, and legacy distributed systems.</blockquote><blockquote>etcd uses Raft and a flat key-value model; it is the coordination backend for Kubernetes cluster state and many cloud-native systems.</blockquote><p><strong>Different shapes, same patterns:</strong></p><ul><li><strong>Watchers</strong> — subscribe to key/znode changes (config reload on change)</li><li><strong>Ephemeral keys </strong>— vanish when session dies → leader election + distributed locks</li><li><strong>Configuration storage</strong> — shared config pushed to all services</li></ul><p>Keep coordination in its own failure domain — an app crash must not take down the cluster you need to recover.</p><p>The daily email report comes alive in the diagram below: three schedulers compete, one wins the lock, two skip. In practice this often means creating an ephemeral key or a key with a short TTL in etcd/ZooKeeper; if the winner dies, the lock disappears and another scheduler can try later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Jx32vLPAgWisZOGZY08XA.gif" /><figcaption>Distributed lock: daily report job</figcaption></figure><h3>CAP Theorem</h3><p>Coordination solves agreement under normal conditions. But what happens when the network itself breaks?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_JeGh_260KFImogbvEF-8g.gif" /></figure><p>During a network partition, pick consistency OR availability — not both. Partition tolerance (P) is mandatory in any distributed system — networks fail; pretending otherwise is not an option.</p><p>Define the terms through scenes:</p><ul><li><strong>Consistency ( C )</strong>— after a successful write, every read returns that write. Recall hook: bank transfer. Once confirmed, every device shows the new balance.</li><li><strong>Availability (A)</strong> — every request gets a non-error response, possibly stale. Recall hook: e-commerce. Users browse and add to cart even if inventory count is slightly outdated.</li><li><strong>Partition tolerance (P)</strong> — the system continues to operate despite a network split between nodes. In real distributed systems, P is not optional; partitions happen.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35QKPCFRE5J2U9YUN9oNsQ.png" /></figure><p>The proof fits on a napkin:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yKZ0_UTt_oRwfERmG553Ww.png" /></figure><p>Recall hook — proof: Node A and B both hold x=10. Partition splits them. Client writes 15 to A, reads from B.</p><ul><li>Return 10 → available but stale (violates C)</li><li>Return error → consistent but unavailable (violates A)</li></ul><p>Node B cannot learn about the write on Node A because the partition blocks communication. No third door exists during the partition.</p><p>That is why CAP becomes a CP vs AP decision under partition:</p><ul><li>CP: refuse unsafe reads/writes to preserve correctness; some requests fail or block.</li><li>AP: keep serving requests; some responses may be stale until reconciliation.</li></ul><p>Three myths trip up interviews:</p><ol><li>“Pick two of three” — wrong. P is always on. Real question: CP or AP during partition? When no partition, all three can coexist.</li><li>“One static choice forever” — wrong. The trade-off can be per operation. MongoDB-style write concern is the intuition: majority acknowledgement favors consistency; acknowledging from one replica is faster and more available.</li><li>“Binary only” — wrong. Spectrum from strong to eventual (social feed = eventually consistent).</li></ol><h3>PACELC</h3><p>CAP only covers the bad day — when the network partitions.</p><ul><li>If Partition → Availability vs Consistency (same as CAP).</li><li>Else (no partition) → Latency vs Consistency.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vy7bHw7juc5vT-gRhf8kQg.gif" /><figcaption>PACELC decision flow</figcaption></figure><p>Even with healthy networks, waiting for all replicas to ack slows writes. Async replication is fast but reads may lag. Partitions are rare; latency is daily.</p><p>Recall hook — group message: send a message to a group chat and show it instantly, or wait until every recipient’s replica confirms it. The first path is low latency but weaker consistency. The second path is stronger consistency but slower. That is PACELC’s “Else” trade-off.</p><p>Recall hook — system labels:</p><ul><li>DynamoDB — PA/EL (available in partition, low latency normally, async replication, eventual reads)</li><li>Google Spanner — PC/EC (consistent always; atomic clocks + two-phase commit; higher write latency)</li><li>Azure Cosmos DB — five tunable consistency levels</li></ul><p>These are more than labels. They describe architecture. DynamoDB chooses speed and availability for many workloads using asynchronous replication and eventual reads. Spanner chooses stronger consistency with atomic clocks and two-phase commit, paying higher write latency. Cosmos DB exposes five consistency levels so architects can choose their point on the spectrum.</p><p>Recall hook — real-time chat: PACELC fits better than CAP alone. Users feel latency daily; partitions are rare. Pattern: causal or eventual delivery, fast local ack, availability during partition — keep chatting, reconcile order later.</p><p>Recall hook — contrast: financial ledger (Spanner-style consistency) vs social like counter (eventual is fine). Same company, different objects, different guarantees.</p><h3>Tying It Together</h3><p>Strong consistency needs coordination → higher latency in the happy path, tougher availability in partition.</p><p>Eventual consistency skips global coordination → faster, more available, temporarily inconsistent.</p><p>Match guarantee to business object: ledger ≠ like counter ≠ chat message.</p><p>Coordination primitives give you the mechanisms. CAP and PACELC give you the vocabulary to explain why DynamoDB and Spanner feel so different — and why neither is “wrong.”</p><h3>Revision Snapshot</h3><ul><li>Coordination = replication + heartbeats + election/locks/consensus/discovery.</li><li>Ticket overselling = why leader election; daily email = distributed lock.</li><li>ZooKeeper (ZAB, tree, Kafka/HBase) vs etcd (Raft, K8s); quorum + watchers + ephemeral keys + config storage.</li><li>CAP: partition → C xor A; P always required; x=10 write 15 proof; CP blocks, AP serves stale.</li><li>PACELC: if partition → A vs C, else → latency vs consistency; DynamoDB PA/EL, Spanner PC/EC, Cosmos tunable.</li><li>Chat = PACELC; bank = strong/CAP-consistent; feed = eventual spectrum.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a3b27322c0c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RL-2 — The Shared Counter: Identity, Policy and Document Design]]></title>
            <link>https://medium.com/@pareshyadav.ksp/rl-2-the-shared-counter-identity-policy-and-document-design-ba0165106b55?source=rss-819484d48518------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba0165106b55</guid>
            <category><![CDATA[rate-limiting]]></category>
            <category><![CDATA[api-design]]></category>
            <category><![CDATA[api-gateway]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Paresh Yadav]]></dc:creator>
            <pubDate>Fri, 06 Nov 2026 13:29:54 GMT</pubDate>
            <atom:updated>2026-11-08T02:13:57.488Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A shared counter fixes the multiplication problem. It only works if the counter is keyed by the right identity and the right policy, and if every gateway can find the same document without asking anyone.</em></p><h3>Who this is for</h3><p>This is the second article in the <strong>RL series</strong>. It is for <strong>solution architects</strong>, <strong>API platform engineers</strong> and <strong>senior developers</strong> who need to decide what a rate limit is counted against, and how the counter is stored. <a href="https://medium.com/@pareshyadav.ksp/rl-1-the-distributed-gatekeeper-designing-rate-limiting-for-an-enterprise-api-platform-0da73f324d7a">RL-1</a> walked the full design once. This article slows down on one step: moving the counter out of the gateways.</p><p>Like the rest of the series, this is a design walkthrough, not a postmortem. The numbers are illustrations chosen to make the arithmetic easy.</p><h3>Recap: why the counter has to move</h3><p>In <a href="https://medium.com/@pareshyadav.ksp/rl-1-the-distributed-gatekeeper-designing-rate-limiting-for-an-enterprise-api-platform-0da73f324d7a">RL-1</a>, a telecom platform limited each partner to <strong>100 requests per minute</strong> on its Account API. With one gateway, a local counter did the job. With three gateways behind a load balancer, each kept its own counter, each said “100 of 100, within the limit”, and the backend received 300 requests in a minute.</p><p>Nothing was broken in any single gateway. The bug was in the design: <strong>the limit belongs to the partner, but the counter belongs to the gateway.</strong> It also scales the wrong way. Add a fourth gateway during a busy week and the real limit becomes 400. A rule that changes when you add servers is not a rule.</p><h3>The tempting fix: split the limit</h3><p>The next idea is common: give each gateway a share. With 3 gateways, each allows 100 ÷ 3, so about 33 requests per minute.</p><p>This is better, and it is still wrong, for two reasons:</p><ul><li><strong>A load balancer does not split traffic perfectly.</strong> If one gateway receives 60 of the partner’s requests, it rejects 27 of them while the other two sit half empty. The partner is told “too many requests” while using less than 100 in total</li><li><strong>The share depends on the number of gateways.</strong> Autoscaling changes N. Every gateway has to learn the new N at the same moment, or the limit drifts</li></ul><p>Splitting works only if traffic is perfectly even and the cluster size never changes. Neither is true in production. It does earn a place later, as a short-term fallback when the shared store is down. That is covered in <a href="https://medium.com/@pareshyadav.ksp/rl-4-when-the-rate-limiters-own-store-goes-down-failure-cost-and-observability-7b56e8843df8">RL-4</a>.</p><h3>Who is the “consumer”?</h3><p>Before fixing where the counter lives, fix what it counts. A limit is always “per something”, and the something has to be chosen carefully.</p><p>The first instinct is the client IP address. It is easy to read and it is wrong for partner APIs. A large partner often sends all its traffic through one corporate gateway, so thousands of users share one IP. Limit by IP and you punish the whole company for one noisy user. It works the other way too: one partner can rotate IP addresses and dodge the limit.</p><p>For authenticated partner APIs, use an identity that the platform issued:</p><ul><li>The <strong>OAuth client ID</strong> from the access token</li><li>Or the <strong>subscription ID</strong> if a partner can hold more than one plan</li></ul><p>The limit is then not a single number. It is a small policy, looked up per consumer and per API:</p><ul><li><strong>Consumer</strong> — which partner is calling (customerA)</li><li><strong>API</strong> — which API is being called (accountAPI)</li><li><strong>Limit</strong> — how many requests (100)</li><li><strong>Window</strong> — over how much time (one minute)</li></ul><p>The same partner may be allowed 100 per minute on the Account API and 20 per minute on the Payment API. If the key contains only the consumer, those two limits collapse into one.</p><p>Policy also answers a question that comes up later: how should this API count, and what should it do when the store is down? Both can be fields in the same record. <a href="https://medium.com/@pareshyadav.ksp/rl-3-the-race-at-99-atomic-updates-and-counting-algorithms-eab38811b508">RL-3</a> and <a href="https://medium.com/@pareshyadav.ksp/rl-4-when-the-rate-limiters-own-store-goes-down-failure-cost-and-observability-7b56e8843df8">RL-4</a> use that.</p><h3>Make the counter shared</h3><p>Now the real fix. Move the counter out of the gateways and into one place that all of them can reach:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l-asvHWXvGP8Nrh_9pooQA.gif" /></figure><p>Gateway 1 accepted 40 requests, Gateway 2 accepted 20, and Gateway 3 accepted 15. None of them knows what the others did, and none of them needs to. The shared counter says 75 of 100 used, and that is the only number that matters.</p><p>In this design the shared store is <strong>OpenSearch</strong>, because the platform already runs it for search and logs. Many teams use Redis for this job, and if you already run Redis, it is usually the more natural choice. The design idea does not depend on the product. What matters is that the store can change one counter safely when several gateways write to it at once. That is the topic of <a href="https://medium.com/@pareshyadav.ksp/rl-3-the-race-at-99-atomic-updates-and-counting-algorithms-eab38811b508">RL-3</a>.</p><h3>One document per consumer, API and window</h3><p>The counter is one small document in an index called api-rate-limits. It carries the consumer, the API, the window start, the window length, the current count and the limit. The trick that makes it work across gateways is the document ID. It is built from the data in the request, with no lookup and no coordination:</p><pre>customerA_accountAPI_202611061030</pre><p>Read it left to right: the consumer, the API, then the window, here 6 November 2026 at 10:30. Every gateway that handles a request from Customer A for the Account API during that minute builds exactly the same ID. That means they all update the same document, even though they never talk to each other.</p><p>When the clock reaches 10:31, the ID becomes customerA_accountAPI_202611061031. That is a brand new document that starts at zero. The old one is not reset. It is simply never used again. This is the <strong>fixed window</strong> approach, and <a href="https://medium.com/@pareshyadav.ksp/rl-3-the-race-at-99-atomic-updates-and-counting-algorithms-eab38811b508">RL-3</a> covers its weak spot and the other options.</p><p>A deterministic ID has a second benefit. By default, OpenSearch picks the shard for a document from a hash of its ID, so all updates to one counter land on one shard. The same ID always goes to the same place. That is good for correctness, and it will matter again when we talk about cost in <a href="https://medium.com/@pareshyadav.ksp/rl-4-when-the-rate-limiters-own-store-goes-down-failure-cost-and-observability-7b56e8843df8">RL-4</a>.</p><h3>Two traps with this design</h3><p>Two details catch people who have used a database more than a search engine:</p><ul><li><strong>Do not read the counter with a search query.</strong> OpenSearch searches see new data only after a refresh, and a refresh is not part of every update. A counter read through search can be seconds behind. Read and change the counter by its ID, inside the update itself</li><li><strong>The old documents pile up.</strong> Every consumer, API and minute makes a new document. Left alone, the index grows forever. Cleanup is a real part of the design and is covered in <a href="https://medium.com/@pareshyadav.ksp/rl-4-when-the-rate-limiters-own-store-goes-down-failure-cost-and-observability-7b56e8843df8">RL-4</a></li></ul><h3>What a shared counter still does not solve</h3><p>Moving the counter fixed the multiplication problem. It created two new ones:</p><ul><li><strong>Two gateways can update the same counter at the same moment.</strong> With a naive “read, check, then add one” flow, a limit of 100 can let 101 requests through. Fixing that needs one <strong>atomic </strong>operation. That is <a href="https://medium.com/@pareshyadav.ksp/rl-3-the-race-at-99-atomic-updates-and-counting-algorithms-eab38811b508">RL-3</a>.</li><li><strong>The counter store is now on the path of every request.</strong> If it is slow or down, the question becomes whether you let traffic through or stop it. That is <a href="https://medium.com/@pareshyadav.ksp/rl-4-when-the-rate-limiters-own-store-goes-down-failure-cost-and-observability-7b56e8843df8">RL-4</a>.</li></ul><h3>Principles</h3><ul><li><strong>A limit belongs to the consumer, not to a server.</strong> If the counter lives in the gateway, the real limit is the limit multiplied by the number of gateways, and it changes every time you scale</li><li><strong>Splitting the limit by N is a fallback, not a design.</strong> It depends on perfectly even traffic and a fixed cluster size</li><li><strong>Count by an identity you issued.</strong> Use the OAuth client ID or subscription ID. IP addresses are shared by many users and are easy to change</li><li><strong>Key the limit by consumer and API.</strong> One number per partner is rarely the policy anyone actually wants</li><li><strong>Build the counter ID from the request.</strong> A deterministic ID lets every gateway find the same counter without asking anyone</li></ul><p>The shortest version: if you can add a server and your limit changes, you did not build a limit. You built a suggestion.</p><p><strong>Previous:</strong> <a href="https://medium.com/@pareshyadav.ksp/rl-1-the-distributed-gatekeeper-designing-rate-limiting-for-an-enterprise-api-platform-0da73f324d7a">RL-1 — The Distributed Gatekeeper</a> · <strong>Next:</strong> <a href="https://medium.com/@pareshyadav.ksp/rl-3-the-race-at-99-atomic-updates-and-counting-algorithms-eab38811b508">RL-3 — Atomic Updates and Counting Algorithms</a></p><p>If this helped, follow for more on agents, system design, and production AI.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba0165106b55" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RL-1 — The Distributed Gatekeeper: Designing Rate Limiting for an Enterprise API Platform]]></title>
            <link>https://medium.com/@pareshyadav.ksp/rl-1-the-distributed-gatekeeper-designing-rate-limiting-for-an-enterprise-api-platform-0da73f324d7a?source=rss-819484d48518------2</link>
            <guid isPermaLink="false">https://medium.com/p/0da73f324d7a</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[api-design]]></category>
            <category><![CDATA[rate-limiting]]></category>
            <category><![CDATA[api-gateway]]></category>
            <dc:creator><![CDATA[Paresh Yadav]]></dc:creator>
            <pubDate>Fri, 06 Nov 2026 12:51:59 GMT</pubDate>
            <atom:updated>2026-11-08T02:10:05.614Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A single gateway can rate limit with a local counter. Several gateways need shared state, and shared state alone is not enough: the updates must be atomic, the failure behaviour deliberate, and the performance matched to the traffic.</em></p><h3>Who this is for</h3><p>This is the overview article of the <strong>RL series</strong> on rate limiting. It is written for <strong>solution architects</strong>, <strong>API platform engineers</strong> and <strong>senior developers</strong> who review gateway and integration designs. You do not need to have built a rate limiter. You need enough vocabulary to ask: <em>where does the counter live, who updates it, and what happens when it cannot be reached?</em></p><p>It walks the whole design once, end to end. <a href="https://medium.com/@pareshyadav.ksp/rl-2-the-shared-counter-identity-policy-and-document-design-ba0165106b55">RL-2</a>, <a href="https://medium.com/@pareshyadav.ksp/rl-3-the-race-at-99-atomic-updates-and-counting-algorithms-eab38811b508">RL-3</a> and <a href="https://medium.com/@pareshyadav.ksp/rl-4-when-the-rate-limiters-own-store-goes-down-failure-cost-and-observability-7b56e8843df8">RL-4</a> then take the hard parts one at a time. The numbers are illustrations chosen to make the arithmetic easy, not measurements.</p><h3>1. The problem begins</h3><p>Imagine an enterprise telecom platform exposing several APIs to external partners.</p><p>Partners access customer accounts, subscriptions, services and billing information through an API Gateway. Behind the gateway sits a Camel/CXF integration layer, followed by microservices and databases such as PostgreSQL and Couchbase.</p><p>Initially, the platform has one API Gateway instance. The architecture team introduces a rate-limiting policy:</p><p><strong>Each API consumer can make a maximum of 100 requests per minute to the Account API.</strong></p><p>The gateway maintains a counter for every consumer. Whenever a request arrives, it checks the counter. If the count is below 100, the request is accepted and the counter is incremented. Otherwise, the gateway rejects the request with HTTP 429 (Too Many Requests).</p><p>This works perfectly until traffic grows.</p><p>To handle increasing traffic, the platform introduces three API Gateway instances behind a load balancer.</p><p>Suddenly, a problem emerges.</p><h3>2. The distributed gateway problem</h3><p>A partner sends requests through the load balancer. Some requests reach Gateway 1, others Gateway 2 and Gateway 3.</p><p>Each gateway maintains its own independent counter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5nCkO4lez0ImwNzidj9bLg.png" /></figure><ul><li>Gateway 1: local limit 100, requests accepted 100</li><li>Gateway 2: local limit 100, requests accepted 100</li><li>Gateway 3: local limit 100, requests accepted 100</li><li><strong>Total: 100 global limit, 300 accepted</strong></li></ul><p>The partner was supposed to receive 100 requests per minute, but the platform accepted 300.</p><p>The problem is not the rate-limiting algorithm. The problem is that the gateways do not share their state.</p><p>This is a classic distributed-systems problem: multiple independent instances need to coordinate around one logical piece of state.</p><h3>3. Introducing OpenSearch as shared storage</h3><p>The architecture team decides to use the existing OpenSearch infrastructure as the shared rate-limit state store.</p><p>Instead of maintaining independent counters, every gateway consults a common OpenSearch index.</p><p>The architecture now looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l-asvHWXvGP8Nrh_9pooQA.gif" /></figure><p>All gateways now consult the same shared counter.</p><p>For example:</p><ul><li>Gateway 1 accepts 40 requests.</li><li>Gateway 2 accepts 20 requests.</li><li>Gateway 3 accepts 15 requests.</li></ul><p>OpenSearch maintains a shared count of 75.</p><p>When the next request arrives through any gateway, it sees the shared state and knows that only 25 requests remain.</p><p>The important architectural principle is that <strong>the counter belongs to the consumer, not to an individual gateway instance.</strong></p><h3>4. How should the counter be represented?</h3><p>The team creates a dedicated OpenSearch index called api-rate-limits.</p><p>Each counter document represents a particular consumer, API and time window.</p><p>Example document:</p><pre>{<br>  &quot;_id&quot;: &quot;customerA_accountAPI_202611061030&quot;,<br>  &quot;consumerId&quot;: &quot;customerA&quot;,<br>  &quot;apiId&quot;: &quot;accountAPI&quot;,<br>  &quot;windowStart&quot;: &quot;2026-11-06T10:30:00Z&quot;,<br>  &quot;windowDurationSeconds&quot;: 60,<br>  &quot;requestCount&quot;: 75,<br>  &quot;limit&quot;: 100<br>}</pre><p>The document ID is deterministic so all gateway instances refer to the same logical counter.</p><p>Different consumers and APIs have different documents:</p><ul><li>Customer A, Account API: 100 per minute</li><li>Customer A, Payment API: 20 per minute</li><li>Customer B, Account API: 500 per minute</li><li>Customer B, Payment API: 100 per minute</li></ul><p>This introduces policy-based rate limiting.</p><p>The gateway identifies the consumer, determines the API and retrieves the applicable policy. It then uses the corresponding counter document.</p><p>For OAuth-secured APIs, the OAuth client ID or API subscription ID can be used as the consumer identity.</p><p>Using an IP address alone is often unsuitable because multiple legitimate consumers may share a public IP address.</p><h3>5. The critical challenge: Atomic updates</h3><p>The team initially proposes a simple implementation:</p><ol><li>Gateway reads the counter.</li><li>Gateway checks whether the count is below 100.</li><li>Gateway increments the counter.</li><li>Gateway accepts the request.</li></ol><p>But two gateways can execute these steps simultaneously.</p><p>Suppose the current count is 99.</p><ul><li><strong>T1</strong> — Gateway 1 reads 99</li><li><strong>T2</strong> — Gateway 2 reads 99</li><li><strong>T3</strong> — Gateway 1 checks 99 &lt; 100</li><li><strong>T4</strong> — Gateway 2 checks 99 &lt; 100</li><li><strong>T5</strong> — Gateway 1 increments to 100</li><li><strong>T6</strong> — Gateway 2 increments to 101</li></ul><p>Both requests may be accepted.</p><p>This is a race condition.</p><p>The team realizes that checking and incrementing must be treated as one atomic operation.</p><p>OpenSearch supports scripted document updates and optimistic concurrency control. A carefully designed update script can perform the check and increment against one document as a single document-level operation.</p><p>Conceptually:</p><pre>UPDATE rate-limit document:</pre><pre>IF requestCount &lt; limit:<br>    requestCount = requestCount + 1<br>    RETURN ALLOW<br>ELSE:<br>    RETURN REJECT</pre><p>The gateway must use the update result to decide whether to forward the request.</p><p>It must not perform an independent search followed by an unconditional update.</p><p>For concurrent requests targeting the same document, the implementation must handle version conflicts and retry safely, without accidentally counting one logical request multiple times.</p><p><strong>Important:</strong> OpenSearch is not a purpose-built rate-limiting engine. Its document-level update capabilities make this design possible, but performance, concurrency, indexing and refresh behaviour need to be tested. For high-throughput, strict real-time rate limiting, Redis or a dedicated rate-limit service is generally a more natural choice.</p><h3>6. Choosing the right rate-limiting algorithm</h3><p>The architecture team next evaluates the algorithms.</p><h3>Fixed Window Counter</h3><p>The simplest approach is to maintain a counter for each one-minute interval.</p><p>At the beginning of the next minute, a new counter is created.</p><p>Its weakness is the boundary problem.</p><p>A consumer can send 100 requests at 10:00:59 and another 100 at 10:01:00.</p><p>The system accepts 200 requests within approximately two seconds, even though the policy is 100 requests per minute.</p><h3>Sliding Window Log</h3><p>The gateway maintains individual request timestamps.</p><p>Whenever a request arrives, it removes timestamps older than 60 seconds and counts the remaining requests.</p><p>This provides accurate rolling-window enforcement but requires more storage and processing.</p><h3>Sliding Window Counter</h3><p>The system maintains two counters:</p><ul><li>Previous window count.</li><li>Current window count.</li></ul><p>It estimates the rolling request count by weighting the previous window.</p><p>This is a practical compromise between accuracy and storage requirements.</p><h3>Token Bucket</h3><p>The system maintains a bucket of tokens.</p><p>For example:</p><ul><li>Bucket capacity: 100 tokens.</li><li>Refill rate: 10 tokens per second.</li><li>Each request consumes one token.</li></ul><p>When tokens are available, the request is accepted. Otherwise, it is rejected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XNNa1hHZTwCmoMHxJSuv_w.gif" /></figure><p>Token Bucket allows short bursts while controlling the sustained request rate.</p><p>The team selects an algorithm based on the actual API policy rather than assuming that every API should use the same algorithm.</p><h3>7. What happens when OpenSearch becomes unavailable?</h3><p>Now the architecture team faces another production question.</p><p>What happens if OpenSearch becomes unavailable?</p><p>The gateway cannot verify the shared quota.</p><p><strong>Two possible strategies emerge.</strong></p><blockquote><strong>Fail Open</strong></blockquote><blockquote>The gateway continues accepting requests without checking the shared counter.</blockquote><blockquote>This protects API availability but temporarily bypasses global rate-limit enforcement.</blockquote><blockquote><strong>Fail Closed</strong></blockquote><blockquote>The gateway rejects requests because it cannot verify the quota.</blockquote><blockquote>This protects the backend but may cause legitimate customers to experience failures.</blockquote><p>The team decides that the policy should depend on the business criticality of each API:</p><ul><li><strong>Public read API</strong> — fail open with local protection</li><li><strong>Payment API</strong> — fail closed, or use a bounded fallback</li><li><strong>Expensive reporting API</strong> — fail closed</li><li><strong>Internal health API</strong> — a separate protection policy</li></ul><p>There is no universally correct answer. The architecture must balance availability against the risk of uncontrolled traffic.</p><h3>8. Performance and capacity trade-offs</h3><p>The team now considers the cost of checking OpenSearch for every request.</p><p>Imagine the platform receives 10,000 requests per second.</p><p>If every request performs a shared-state operation, OpenSearch must sustain that update workload.</p><p>This introduces several concerns:</p><ul><li>Network latency between gateways and OpenSearch.</li><li>Update contention on frequently accessed consumer documents.</li><li>Primary shard hotspots.</li><li>Concurrent update conflicts and retries.</li><li>Cluster availability and capacity.</li><li>Counter-document cleanup.</li></ul><p>One possible optimization is allocating tokens in batches.</p><p>For example, with a global limit of 100 per minute:</p><ul><li>Gateway 1 obtains 30 tokens.</li><li>Gateway 2 obtains 30 tokens.</li><li>Gateway 3 obtains 30 tokens.</li></ul><p>Each gateway consumes its allocation locally.</p><p>This reduces shared-store operations but introduces capacity fragmentation.</p><p>If Gateway 1 uses only 5 of its 30 tokens, its remaining 25 tokens may be stranded while Gateway 2 has exhausted its allocation.</p><p>If a gateway crashes, its unused allocation also needs a recovery or expiry mechanism.</p><p>This illustrates an important architectural trade-off:</p><p><strong>Centralized enforcement improves global accuracy, while distributed token allocation improves performance at the cost of allocation inefficiency and more complex recovery.</strong></p><h3>9. Observability and operational monitoring</h3><p>The team also recognizes that rate limiting is not just an enforcement mechanism. It must be observable.</p><p>The platform already uses OpenTelemetry, Prometheus, Grafana and centralized logging.</p><p>It introduces metrics such as:</p><ul><li>http_requests_total</li><li>http_requests_rejected_total</li><li>rate_limit_remaining</li><li>rate_limit_check_duration_seconds</li><li>opensearch_errors_total</li><li>rate_limit_update_conflicts_total</li></ul><p>Grafana dashboards help answer:</p><ul><li>Which consumers are regularly exceeding their quotas?</li><li>Which APIs are rejecting the most requests?</li><li>Is rate limiting introducing significant latency?</li><li>Is OpenSearch becoming a bottleneck?</li><li>Are gateways experiencing update conflicts?</li><li>Is the platform rejecting legitimate traffic?</li></ul><p>This enables the operations team to distinguish genuine traffic abuse from infrastructure problems.</p><h3>10. The final architectural understanding</h3><p>The team has now understood that rate limiting is not simply a counter maintained inside an API Gateway.</p><p>It is a distributed coordination problem involving identity, policy, shared state, concurrency, consistency, availability and performance.</p><p>The final design separates responsibilities:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BSl64dUsvP3UlGG3blkSeg.gif" /></figure><ul><li><strong>API Gateway</strong> — intercepts requests</li><li><strong>OAuth / Security</strong> — identifies the consumer</li><li><strong>Policy engine</strong> — determines applicable limits</li><li><strong>OpenSearch</strong> — maintains shared counter documents</li><li><strong>Rate-limit algorithm</strong> — decides allow or reject</li><li><strong>Backend</strong> — processes accepted requests</li><li><strong>Prometheus / Grafana</strong> — monitor enforcement and performance</li></ul><p>The team also documents an important architectural qualification: OpenSearch is being reused as shared storage because it is already available in the platform, not because it is necessarily the optimal counter store.</p><p>For moderate traffic, an appropriately tested implementation may be viable. For very high request rates or strict enforcement requirements, a dedicated low-latency counter store should be evaluated.</p><h3>The takeaway</h3><p>A single API Gateway can enforce a rate limit using a local counter.</p><p>Multiple API Gateway instances require coordination.</p><p>A shared store provides that coordination, but shared storage alone is insufficient. The updates must be atomic, the failure behaviour must be deliberate, and the performance characteristics must match the traffic profile.</p><p>That is the difference between implementing rate limiting and designing distributed rate limiting for an enterprise API platform.</p><h3>What the rest of the series covers</h3><ul><li><a href="https://medium.com/@pareshyadav.ksp/rl-2-the-shared-counter-identity-policy-and-document-design-ba0165106b55"><strong>RL-2</strong> </a>— the shared counter in detail: why splitting the limit fails, who the consumer really is, and how the document ID works</li><li><a href="https://medium.com/@pareshyadav.ksp/rl-3-the-race-at-99-atomic-updates-and-counting-algorithms-eab38811b508"><strong>RL-3</strong> </a>— the race at 99 in detail: the atomic scripted update, and the four counting algorithms side by side</li><li><a href="https://medium.com/@pareshyadav.ksp/rl-4-when-the-rate-limiters-own-store-goes-down-failure-cost-and-observability-7b56e8843df8"><strong>RL-4</strong></a> — when the store fails: failure policy, the cost of checking every request, cleanup, and metrics</li></ul><p><strong>Next:</strong> <a href="https://medium.com/@pareshyadav.ksp/rl-2-the-shared-counter-identity-policy-and-document-design-ba0165106b55">RL-2 — The Shared Counter: Identity, Policy and Document Design</a></p><p>If this helped, follow for more on GenAI, agents and system design.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0da73f324d7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Observability Series 9 — How to Learn Observability Without Becoming an SRE]]></title>
            <link>https://medium.com/@pareshyadav.ksp/observability-series-9-how-to-learn-observability-without-becoming-an-sre-19556af66b89?source=rss-819484d48518------2</link>
            <guid isPermaLink="false">https://medium.com/p/19556af66b89</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[career-development]]></category>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[software-architect]]></category>
            <category><![CDATA[observability]]></category>
            <dc:creator><![CDATA[Paresh Yadav]]></dc:creator>
            <pubDate>Thu, 29 Oct 2026 12:56:43 GMT</pubDate>
            <atom:updated>2026-10-30T14:38:09.968Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Master the concepts, touch the tools once, and let Ops run the clusters.</em></p><p>When I started, I picked the wrong layer first. I read about Prometheus, then Grafana, then Tempo, and collected product names the way you collect vocabulary in a language you cannot yet speak. I could tell you what each tool was called. I could not have told you which question a trace answers and a metric does not.</p><p>That is the trap, and it is specific: the tools are numerous, well documented, and easy to install, so learning them feels like progress. Meanwhile the concepts — what makes a signal joinable, which metric type answers which question, where instrumentation belongs — are the part that transfers. Tools change every few years. The three questions from <a href="https://medium.com/@pareshyadav.ksp/observability-series-1-you-cannot-pause-production-10df2065891f">story 1</a> have not.</p><p>The other half of the trap is the opposite fear: that taking observability seriously means becoming the person who runs the observability platform. It does not. Being clear about that boundary is what makes the subject learnable in weeks rather than years.</p><h3>Three depths, not one</h3><p>The way out is to decide, in advance, how deep to go on each topic. My notes sort every subject into three levels. I have found the sorting itself more valuable than any item on the list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cPlikIqWYLiG3Rb64isuzw.png" /><figcaption>Three columns: deep concepts to master, medium topics to practice once, basic topics to know exist</figcaption></figure><p><strong>Deep</strong> is the conceptual layer, and there is no substitute for owning it. Traces, spans, and context propagation. The golden signals. Counter versus gauge versus histogram. The boundary rule. Sampling as a design choice rather than a config value. These are the things you use in a design review, when there is no tool in front of you and someone asks how we will know if the new service is slow.</p><p><strong>Medium</strong> is the hands-on layer: do it once, properly, so it stops being abstract. Configure a Collector and see receivers, processors, and exporters do their jobs. Write enough PromQL to build one dashboard. Open a trace in Jaeger or Tempo and read the waterfall. Wire a Grafana data source. Get a trace id into a log line and search by it. One pass through each is enough to make the concepts concrete and to make you a useful conversation partner for the people who do this daily.</p><p><strong>Basic</strong> is awareness only. Micrometer and the Prometheus client wrappers exist and you will meet them. Alert rule files exist and operations will own them. Tail sampling internals exist and you will read about them the day you need them. Knowing the name and the purpose is the whole requirement.</p><p>Awareness sounds like too little, and it is enough for a specific reason: you cannot look up something you cannot name. The documentation for all of these is good, and it is available the moment you need it. What stops people is not missing detail, it is not knowing that a mechanism exists at all, so the question never gets asked. A name and one sentence about its purpose is what makes the rest findable later.</p><p>My notes compress this into one line: concepts very deep, hands-on moderate, operations shallow. What I like about it is that it gives you permission to stop. Without a ladder, every unread page feels like a gap. With one, most are correctly filed under “someone else’s job, and I know its name.”</p><h3>Five milestones, in order</h3><p>Depth tells you how far. It does not tell you what to do first. Order matters here more than in most subjects, because each step is only motivating once the previous one exists.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1E9IMMxqRuZF6_xOd8l-FA.png" /><figcaption>Five milestones from an end-to-end trace to a design review, each with what it teaches</figcaption></figure><p>The first milestone is one trace across two services, visible in a UI. Not a dashboard, not an alert — one request, drawn as a waterfall, that you produced yourself. My notes plan it as a small Java service calling a small Python service that writes to SQLite — deliberately unimpressive, a demo shape from a learning plan, not a production system. It works because it forces every piece of the pipeline into place at once: instrumentation, a Collector, a store, a UI. When the trace appears, the whole chain from <a href="https://medium.com/@pareshyadav.ksp/observability-series-6-who-does-what-in-the-observability-stack-ed227f9ade33">story 6</a> stops being a diagram.</p><p>Then metrics: a dashboard showing request rate, error rate, latency percentiles, and CPU. This is where PromQL and histogram queries become real, and where <a href="https://medium.com/@pareshyadav.ksp/observability-series-3-counter-gauge-histogram-f120422fd3d6">story 3</a>’s metric types become choices you have made rather than words you have read.</p><p>Then correlation: put trace_id in the log line and find one request&#39;s lines by searching for it. Small change — and it is the moment the three signals become one system.</p><p>Then sampling and objectives: set a sampling rate, watch what you keep and what you lose, and design a golden-signal dashboard for a service. This is the first step where the answer depends on judgment instead of configuration.</p><p>All four of those fit on one machine. A local stack with a Collector and the three backends is enough for everything up to sampling, and running it yourself has a side effect worth more than the exercises: you find out which parts are fiddly. The moment a trace does not appear, you learn where the pipeline can break, in the order <a href="https://medium.com/@pareshyadav.ksp/observability-series-8-making-it-survive-production-a6da3a42734b">story 8</a> describes — wrong port, missing header, un-instrumented hop. That knowledge is hard to get from reading, and it is exactly the knowledge that makes you useful in a design discussion.</p><p>Last, a design review: write an observability plan for a service that does not exist yet. Which boundaries get spans. Which three metrics. What the SLIs are. What you would want in the log line. If you can write that document and defend it, you have the thing this series was for. Nothing about it requires operating a cluster.</p><h3>How you know it worked</h3><p>My notes finish with a competency list, and it reads better as a self-check than as a curriculum. Five statements, and the honest test is whether you could do each one this week.</p><p>You can design an application that is observable from the start, rather than instrumented after an incident. You can instrument a service with OpenTelemetry without copying a tutorial line by line. You can read a Grafana dashboard and a trace waterfall and say what they mean, including which parts are estimates. You can sit with an SRE and agree on SLIs and SLOs, using the same words for the same things. And you can explain <em>why</em> something is slow, with a trace open, instead of guessing at the component you understand least.</p><p>That last one is the whole series in one sentence. It is also exactly what I could not do at the start, when I had a request id in four log files and no way to say which hop spent the time.</p><p>Notice what is not on the list. Running a Prometheus cluster. Tuning Loki. Owning the alerting pipeline. Operating a tail-sampling gateway. Those are real skills, and they belong to people who do them properly. The list above is the application architect’s half of the contract. It is achievable while you keep your actual job.</p><h3>What comes after this</h3><p>Observability is the first month of a longer plan in my notes. The rest is only sketched: flow and asynchronous communication, resilience patterns, domain boundaries, operability, and integration. Each is its own subject, and none of them is covered here.</p><p>There is a reason observability comes first, though, and it is not arbitrary. Every one of those later subjects is a claim about behavior under stress — this retry protects us, this boundary isolates that failure, this queue absorbs that spike. You cannot evaluate a single one of those claims in a system you cannot see. Observability is not the most interesting month. It is the one that makes the others checkable.</p><h3>What to carry forward</h3><ul><li>Learning tool names feels like progress and is the wrong layer. Concepts transfer; products get replaced.</li><li>Sort every topic into deep, medium, or basic, and let the sorting give you permission to stop.</li><li>Concepts very deep, hands-on moderate, operations shallow.</li><li>Do the milestones in order. One trace first, because it forces the whole pipeline into place.</li><li>The end state is a design document you can defend, not a cluster you can operate.</li><li>Observability comes first because every later resilience claim is untestable without it.</li></ul><p>And the thread that ran through the whole series: I began with a request id I generated by hand — correlation, and nothing else. The distance from there to here is not a product. It is a trace id that survives every hop, three metric types chosen on purpose, signals placed at boundaries, one id shared by all three signals, and a sampling decision made deliberately. Each of those is a choice made in code, before anything breaks.</p><p>You cannot pause production. You can decide, today, which questions it will be able to answer.</p><p><em>If this helped, follow for more on agents, system design, and AI.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19556af66b89" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Observability Series 8b — Sampling and Cost]]></title>
            <link>https://medium.com/@pareshyadav.ksp/observability-series-8b-sampling-and-cost-d9720558a674?source=rss-819484d48518------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9720558a674</guid>
            <category><![CDATA[observability]]></category>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[sre]]></category>
            <category><![CDATA[opentelemetry]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Paresh Yadav]]></dc:creator>
            <pubDate>Thu, 29 Oct 2026 12:56:07 GMT</pubDate>
            <atom:updated>2026-10-29T12:56:07.762Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Full tracing everywhere is a bill, not a strategy.</em></p><p><a href="https://medium.com/@pareshyadav.ksp/observability-series-8-making-it-survive-production-a6da3a42734b">Story 8</a> got the agent running and the header verified. One question still decides whether the setup survives its first month: how much of this do you actually keep?</p><p>The instinct is to keep everything — every trace, every span, forever — because the one you throw away will be the one you needed. The instinct is comfortable. It does not survive contact with volume. Traces are the largest signal by a wide margin. One request can produce a dozen spans, each with attributes, so trace storage grows with traffic multiplied by the depth of your call graph.</p><p>Sampling is how you decide what to keep. Do it thoughtlessly and you lose the interesting requests. Do it well and you lose almost nothing you would have looked at.</p><h3>The one-line sampler</h3><p>The simplest lever is a sampling rate at the source. Two environment variables:</p><pre>OTEL_TRACES_SAMPLER=parentbased_traceidratio<br>OTEL_TRACES_SAMPLER_ARG=0.1</pre><p>That is a documented sampler name. For it, the argument is a probability between zero and one. 0.1 means one in ten new traces is recorded. It is the example from my notes, not a rate measured against any production system — your rate depends on your traffic and your budget.</p><p>The parentbased prefix is the important half of that name, and easy to skim past. The decision is made once, at the start of the trace, and every downstream service respects the parent&#39;s decision instead of rolling its own dice. Without that, each hop would decide independently and you would get traces with holes in the middle — recorded at the gateway, dropped at the integration layer, recorded again at the database.</p><p>Worth knowing: if you configure no sampler at all, the default is parentbased_always_on. That means everything is recorded, which is fine on a laptop and expensive in production. Sampling is a decision you have to make on purpose, and the default makes it for you if you do not.</p><h3>Four ways to choose</h3><p>One piece of vocabulary first, because it splits the four strategies into two families. Deciding at the start of a request is <strong>head</strong> sampling: cheap, because nothing has to be stored while you wait, and blind, because at that moment nobody knows yet whether the request will be slow or fail. Deciding at the end is <strong>tail</strong> sampling: informed, because the outcome is known, and expensive, because the spans must be held somewhere until then. Nearly every trade-off below is a version of that same tension.</p><p>A fixed ratio at the head is only one of four strategies. The others trade off differently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0cmnRGMOnZaiuqucQJg99A.png" /><figcaption>Four sampling strategies with what each keeps and what it costs you</figcaption></figure><p><strong>Probabilistic</strong> sampling keeps a fixed percentage at random. It is cheap, predictable, and indifferent to whether a request was interesting. Ten percent of your traces means roughly ninety percent of your failures are gone.</p><p><strong>Error-based</strong> sampling keeps every failed request, plus a sample of successful ones. This is closer to how people actually investigate: you almost never open a trace to admire a request that worked. You get the failure every time and still see what normal looks like.</p><p><strong>Rate-limited</strong> sampling caps how many traces per second you keep. Its value is protective — during a traffic spike, when your telemetry volume spikes too, the backend is under the most stress. A ceiling keeps the observability system from becoming part of the incident.</p><p><strong>Tail-based</strong> sampling waits until the request is finished, then decides based on what happened. Slow? Keep it. Failed? Keep it. Boring and fast? Drop it. In principle, this is what you want, because the decision uses the information that makes a trace worth keeping.</p><p>The catch is mechanical, and it is the reason tail sampling is an operations project rather than a config line. To decide after the fact, the Collector has to hold the spans in memory until it believes the trace is complete. To make a correct decision, every span of that trace has to arrive at the same Collector instance — otherwise each instance sees a fragment and judges a partial picture. Scaling it means routing by trace id, with a load-balancing exporter in front of the sampling Collectors. That is real infrastructure work, which is fine, as long as you know you are choosing it.</p><p>For an application architect the practical version is: start with error-based or a modest ratio, and treat tail sampling as something you ask for when the value is proven, not as the opening move.</p><h3>Never sample the thing you alert on</h3><p>There is one hard rule in this story, and it is the one I would put on a wall.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7btlxmWBy8cBtPqFdm8X_w.png" /><figcaption>Metrics never sampled and kept for weeks to months; traces sampled and kept for days to weeks; logs following the trace decision</figcaption></figure><p>Metrics must not be sampled. Not at ten percent, not at ninety.</p><p>The reason is arithmetic. rate() works out how much a counter actually increased over a window. histogram_quantile() works out where a percentile falls using the actual bucket counts. Both do arithmetic on the real increments. Drop some of those samples and the rate is wrong and the quantile is wrong — not noisier, wrong — and every alert built on them fires on fiction or stays quiet during a real failure.</p><p>This is also why metrics are cheap enough to keep whole. A counter is a number per scrape, not a document per request. The signal you alert on is the signal that costs least to keep complete, which is a convenient arrangement.</p><p>Traces are the opposite: expensive per request, and valuable in examples rather than in totals. You do not need every trace; you need a representative one and every broken one. That is precisely what sampling is for.</p><p>Logs sit in between. The useful default is to follow the trace decision. If a trace was kept, keep the logs that carry its trace id, because those are the lines you will read when you open that trace. This is why trace_flags from <a href="https://medium.com/@pareshyadav.ksp/observability-series-7-the-same-trace-id-in-every-log-line-72d6fa97fd62">story 7</a> earns its place in the log line: it records which side of that decision the request fell on.</p><h3>Retention, and why the numbers differ</h3><p>Retention is the second dial, and it should not be one number for the whole stack.</p><p>Metrics are kept for weeks to months. They are small, and they are what you compare against: this week’s latency versus last quarter’s, before and after a release. Long history is where metrics earn their value.</p><p>Traces are kept for days to weeks. A trace’s usefulness has a short half-life — you open it while investigating something recent. Nobody debugs last quarter’s individual request, and if they did, the trace would not be the missing piece.</p><p>Logs are kept for weeks, often with a compliance requirement attached that has nothing to do with debugging and everything to do with what an auditor expects.</p><p>Two ranges, three signals. The shape of each signal decides its retention. Set one global retention period and you either pay to keep traces you will never open, or throw away metric history you would have wanted.</p><h3>Cost is a design decision</h3><p>Most of the cost is decided in application code, not in the observability cluster. That is the uncomfortable part of this story.</p><p>Every span you emit, every attribute you attach, every log line you write at info level in a hot path — those are the inputs. The stack does not get to choose; it stores what arrives. A team can spend months tuning retention and sampling to compensate for instrumentation that was never selective in the first place.</p><p>That is why <a href="https://medium.com/@pareshyadav.ksp/observability-series-5-where-to-put-the-signals-3ebae1d5d041">story 5</a>’s boundary rule is a cost control as much as a design rule. Instrumenting boundaries rather than every method means fewer spans per request, which means a smaller bill and, just as importantly, a trace a human can read. The affordable version of this system and the useful version turn out to be the same version.</p><h3>What to carry forward</h3><ul><li>Sampling is a decision. The default is parentbased_always_on, which records everything.</li><li>parentbased_traceidratio with an argument of 0.1 keeps one in ten new traces; parentbased is what stops each hop from deciding separately and punching holes in traces.</li><li>Probabilistic sampling is blind to what mattered. Error-based sampling keeps the requests you actually open.</li><li>Rate limiting protects the backend when a spike would otherwise take out your telemetry too.</li><li>Tail-based sampling decides after the fact, but needs buffering and every span of a trace on one Collector instance — route by trace id if you scale it.</li><li>Never sample metrics. Rates and quantiles are arithmetic on real increments, and alerts built on partial data are fiction.</li><li>Retention differs by signal: metrics weeks to months, traces days to weeks, logs weeks.</li><li>Most of the cost is decided by what your code emits, so the boundary rule is a budget rule too.</li></ul><p>Next, and last: how to learn the rest of this without becoming the person who operates the clusters.</p><p><em>If this helped, follow for more on agents, system design, and AI.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9720558a674" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Observability Series 8 — Making It Survive Production]]></title>
            <link>https://medium.com/@pareshyadav.ksp/observability-series-8-making-it-survive-production-a6da3a42734b?source=rss-819484d48518------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6da3a42734b</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[opentelemetry]]></category>
            <category><![CDATA[sre]]></category>
            <category><![CDATA[observability]]></category>
            <dc:creator><![CDATA[Paresh Yadav]]></dc:creator>
            <pubDate>Thu, 29 Oct 2026 12:13:31 GMT</pubDate>
            <atom:updated>2026-10-29T12:13:31.469Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A demo that works on a laptop has answered none of the questions production will ask.</em></p><p>Everything so far has been design — which signals exist, where they belong, how they join. Getting that running on one machine, for one request, is a good afternoon’s work.</p><p>Production asks four different questions. Does the instrumentation start at all, in a container you did not build? Does context actually cross the wire, or stop at the hop nobody checked? What does it cost — in overhead and in bill? And can you turn parts of it down without turning all of it off?</p><p>This story is those four questions. The next one decides the bill.</p><h3>Four lines to instrument a JVM</h3><p>The OpenTelemetry Java agent needs no code changes. Attach it to the JVM and it instruments the libraries it recognizes, then starts emitting. On an OSGi container like Apache Karaf, that means editing startup options and nothing else.</p><pre>JAVA_OPTS=&quot;$JAVA_OPTS -javaagent:/path/to/opentelemetry-javaagent.jar&quot;<br>JAVA_OPTS=&quot;$JAVA_OPTS -Dotel.service.name=integration-layer&quot;<br>JAVA_OPTS=&quot;$JAVA_OPTS -Dotel.exporter.otlp.endpoint=http://otel-collector:4317&quot;<br>JAVA_OPTS=&quot;$JAVA_OPTS -Dotel.metrics.exporter=none&quot;<br>JAVA_OPTS=&quot;$JAVA_OPTS -Dotel.logs.exporter=none&quot;</pre><p>Each of those four properties has a default that matters. Read them one at a time.</p><p>otel.service.name is the name every span from this JVM will be grouped under. If you leave it out, the agent reports unknown_service:java, and in a stack with several JVMs you get several services with the same useless name. Set it deliberately.</p><p>otel.exporter.otlp.endpoint is where telemetry goes. This line is the one my notes got subtly wrong, and it is the trap from <a href="https://medium.com/@pareshyadav.ksp/observability-series-6-who-does-what-in-the-observability-stack-ed227f9ade33">story 6</a>: port 4317 is OTLP over gRPC, while the agent has defaulted to http/protobuf since version 2.0. As written, that configuration sends HTTP to a gRPC port. Either add -Dotel.exporter.otlp.protocol=grpc or change the port to 4318.</p><p>otel.metrics.exporter=none and otel.logs.exporter=none turn those two signals off. Both default to otlp, so this is a deliberate choice: send traces only, and let metrics and logs arrive by their existing paths. In a stack that already has metrics, that is a reasonable first step. It is also the kind of line that gets copied into a project where nobody remembers why metrics are missing. Write down why.</p><h3>What arrives without any code</h3><p>“Zero-code instrumentation” sounds like marketing until you see what those four lines actually buy. It is worth being concrete.</p><p>The agent wraps the libraries it recognizes. Incoming HTTP requests become server spans, with the route and the status code attached. Outgoing HTTP calls become client spans, and the traceparent header is injected into them for you — which is the entire propagation mechanism from <a href="https://medium.com/@pareshyadav.ksp/observability-series-4-one-request-many-services-5acafcacb331">story 4</a>, handled without a line of your code. JDBC calls become spans with the database and the query text. Messaging producers and consumers get spans, so context crosses a queue. In an integration stack, the routing and web-service layers have their own instrumentations too.</p><p>Hold that list up against <a href="https://medium.com/@pareshyadav.ksp/observability-series-5-where-to-put-the-signals-3ebae1d5d041">story 5</a>’s boundary rule, and something clicks: the agent’s coverage is almost exactly the boundary list. HTTP in, HTTP out, database, queue. That is not a coincidence — the same reasoning that says boundaries are where the surprises live is why those are the libraries worth instrumenting automatically.</p><p>What the agent cannot know is your domain. It has no idea that these three steps together are “validate order,” and it cannot guess which business identifier matters. That is the small, deliberate set of manual spans and attributes you add yourself. Everything else, you configure — not write.</p><h3>Check the header, not the dashboard</h3><p>The failure I want to warn about is not a crash. It is a stack that looks instrumented and still produces broken traces.</p><p>Verify the wire first, not a dashboard. Look at an outbound request from an instrumented service and confirm the traceparent header is present, and that the trace id part is identical on the request that leaves and the request that arrives at the next hop.</p><p>If it is missing, nothing downstream can work, and no amount of Collector configuration will help. If it is present but the trace id changes between hops, something is starting a new trace instead of continuing yours.</p><p>Look wherever request headers are visible: a proxy that logs them, a debug log of outbound headers, or the receiving service’s own record of what arrived. The tool does not matter. Seeing the header with your own eyes does, because a dashboard with some traces in it looks the same whether the coverage is complete or half missing.</p><p>This check takes a minute and tells you more than an hour of clicking. My habit now is to check per hop, in order, the first time a stack is instrumented. One bad hop is enough.</p><h3>One hop without the agent</h3><p>Here is what one un-instrumented service does to a trace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kCSmttyYCZU2NZTMKOVvaw.gif" /><figcaption>Top row: every hop has the agent and shares one trace id. Bottom row: the integration layer has no agent, the header is dropped and a new trace id begins</figcaption></figure><p>In the healthy row, the gateway starts a trace, the integration layer continues it, and the commerce application continues it again. One trace id, one waterfall, the whole request in one picture.</p><p>In the broken row, the integration layer has no agent. It receives a request carrying traceparent and it does not know what that header means, so it does not pass it on. Its outbound call to the commerce application has no context. The commerce application, seeing no incoming trace, starts a fresh one.</p><p>You now have two traces for one request. Neither is labeled as half of something. The gateway’s trace ends at a hop that appears to be a dead end, and the commerce application’s trace begins out of nowhere with no parent. Nothing errors. Nobody is told.</p><p>This is why tracing has a coverage property that metrics do not. A service with no metrics is a gap you can see — an empty panel. A service with no trace propagation breaks the traces of its neighbours, which were instrumented correctly. The weakest hop sets the quality of the whole picture, so “we instrumented most services” is weaker than it sounds.</p><h3>What it costs to run</h3><p>I want to be careful here, because this is where my notes and I part company.</p><p>My notes record a latency overhead of one to five percent for the Java agent. I cannot stand behind that number. OpenTelemetry’s own performance page for the Java agent declines to give a single figure and says overhead depends on your application, your libraries, and your configuration, and that you have to measure it in your own environment. I have not measured this stack, so I will not quote a percentage I cannot cite.</p><p>What I can say usefully is what drives the cost, because that part is structural. More instrumented libraries means more spans. More spans per request means more work per request and more data leaving the process. Every attribute you attach is bytes on the wire and bytes in storage. And an exporter that cannot keep up applies back pressure, which is a production concern rather than a benchmark curiosity.</p><p>The honest framing: overhead is real, it is a function of choices you control, and the only number worth believing is one you measured against your own load. Instrument the boundaries, keep attribute lists deliberate, and measure before and after in an environment that resembles production.</p><p>If someone asks you what the agent costs, the correct answer is a measurement plan, not a percentage.</p><h3>Turning instrumentation down</h3><p>Selective instrumentation is the next lever — and the other place my notes were simply wrong.</p><p>My notes list two environment variables — OTEL_INSTRUMENTATION_COMMON_EXCLUDE_PATTERNS and an include equivalent — for choosing what gets instrumented. Those names do not appear in the Java agent&#39;s documentation. If you set them, nothing happens, which is the worst kind of wrong configuration.</p><p>The real mechanisms are these. To silence one library, disable it by name: otel.instrumentation.camel.enabled=false, and the same shape for cxf, jdbc, and the rest. To ignore your own packages, use otel.javaagent.exclude-classes=com.example.*. And if you want an allow-list instead of a deny-list, set otel.instrumentation.common.default-enabled=false to turn everything off, then re-enable the specific instrumentations you want.</p><p>That last option is the one I would reach for on a legacy stack. Default-off with a handful of libraries enabled gives you a small, deliberate set of spans, and it stops a chatty framework from filling every trace with noise you did not ask for.</p><p>Turning automatic instrumentation down does not mean losing your own spans. Manual spans around business operations survive all of this, and they are where the attributes that matter belong — the current names from <a href="https://medium.com/@pareshyadav.ksp/observability-series-4-one-request-many-services-5acafcacb331">story 4</a> for technical context, and your own namespaced business ids from <a href="https://medium.com/@pareshyadav.ksp/observability-series-7-the-same-trace-id-in-every-log-line-72d6fa97fd62">story 7</a>. The agent’s job is coverage of boundaries. Your job is the handful of places where a human will want a name.</p><h3>What to carry forward</h3><ul><li>The Java agent needs no code changes: a -javaagent line and a few properties on the JVM.</li><li>Set otel.service.name or your service reports as unknown_service:java.</li><li>4317 is gRPC, 4318 is HTTP, and the agent has defaulted to HTTP since 2.0. Match protocol to port or data vanishes silently.</li><li>otel.metrics.exporter=none and otel.logs.exporter=none are deliberate switches, not defaults. Write down why you set them.</li><li>Verify traceparent on the wire, per hop, before you trust any dashboard.</li><li>One un-instrumented hop splits one trace into two orphans, and breaks the traces of correctly instrumented neighbours.</li><li>Nobody can give you an overhead percentage for your stack, including me. Measure it.</li><li>To reduce instrumentation, disable named libraries, exclude classes, or default everything off and allow-list. The notes’ EXCLUDE_PATTERNS variables do not exist.</li></ul><p>Next: sampling and retention — how to keep the traces that matter without paying to store the ones that do not.</p><p><em>If this helped, follow for more on agents, system design, and AI.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6da3a42734b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>