<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anton Brilliantov</title>
    <description>The latest articles on DEV Community by Anton Brilliantov (@anton_brilliantov).</description>
    <link>https://dev.to/anton_brilliantov</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4056475%2F7d56fe3c-096c-42b1-88dd-e2ea7367624d.png</url>
      <title>DEV Community: Anton Brilliantov</title>
      <link>https://dev.to/anton_brilliantov</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anton_brilliantov"/>
    <language>en</language>
    <item>
      <title>A Notice Board For Every Keeper</title>
      <dc:creator>Anton Brilliantov</dc:creator>
      <pubDate>Fri, 27 Nov 2026 06:00:00 +0000</pubDate>
      <link>https://dev.to/anton_brilliantov/a-notice-board-for-every-keeper-3pi1</link>
      <guid>https://dev.to/anton_brilliantov/a-notice-board-for-every-keeper-3pi1</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8ttnfdy9gf4q2p99w1nm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8ttnfdy9gf4q2p99w1nm.png" alt="A Notice Board For Every Keeper - the cover: Nora next to four steps: put a note, read the board, follow news, heal" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  A Notice Board For Every Keeper
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;Every keeper checks one board at the gate instead of phoning the others: read the whole board when you arrive, follow new notes while you work, and fix your memory from the board when they disagree. Built, barely used yet.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;👋 Hi, I'm Anton - a software engineer. These days I work on a platform: contracts, generated code, data paths and the tooling around them. Running notes live on my GitHub: &lt;strong&gt;&lt;a href="https://github.com/brilliant-almazov" rel="noopener noreferrer"&gt;github.com/brilliant-almazov&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This part is about built code that is barely used yet: the state-watch package was lifted into the shared library from one service, and two services import it. The bug in "What went wrong" is real and fixed.&lt;/p&gt;

&lt;p&gt;This is part 11 of the series on what a shared platform does for every service, told as a zoo. Maybe you already do it better, maybe you'd do it another way - this is how it is going, and where it stops.&lt;/p&gt;




&lt;h2&gt;
  
  
  In real life
&lt;/h2&gt;

&lt;p&gt;Morning at the zoo. Nora wants to know one thing: "Who fed Miso?" Biscuit: "Ask Pickle!" Pickle: "Ask Nora!" Three keepers, three phones, and nobody knows - because the answer lives in three heads and none of them is the right one.&lt;/p&gt;

&lt;p&gt;Pip puts a notice board at the gate. "Write it here. Everyone reads it." Fed Miso? Pin a note. Changed the feeding time? Pin a note.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzxsxm6ck1j2jsddfj9qv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzxsxm6ck1j2jsddfj9qv.png" alt="A four-panel comic: Nora asks who fed Miso, Biscuit says ask Pickle, Pickle says ask Nora; Pip next to a notice board says write it here, everyone reads it; Biscuit, late, reads the whole board, then the news; Miso tore a note and Pickle fixes memory from the board" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The board comes with two habits. Biscuit arrives late: he reads the whole board first, then follows the new notes as they go up - he does not start from whatever he half-remembers from yesterday. And when Miso tears a note down by accident, Pickle compares what she remembers with the board and fixes her memory from the board, not the other way round.&lt;/p&gt;

&lt;h2&gt;
  
  
  Replicas phoning each other
&lt;/h2&gt;

&lt;p&gt;A service runs as several replicas, and some state has to be the same in all of them: which jobs are on, which source is paused, which version of a rule is current. The temptations are familiar. Each replica asks a database on every request, which is slow. Or each replica keeps its own copy and learns about changes when someone remembers to tell it, which is the three keepers on the phone.&lt;/p&gt;

&lt;p&gt;The library's state-watch package is the board: observed state, an in-memory projection in every replica, and reconciliation when they drift. Its first real version lived in one service - the one that keeps metrics - and the library lifted it so others would not write it again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F676wksz3a3ntkfmieal2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F676wksz3a3ntkfmieal2.png" alt="Three tiles with faces: a publisher, happy; the watched store, proud; every replica, happy; labels read put or delete, and snapshot plus deltas; pills read built, and barely used yet" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Put, read, follow, heal
&lt;/h2&gt;

&lt;p&gt;In the shape of the code - names shortened, a form:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;pub&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;desired&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;// pin a note on the board&lt;/span&gt;
&lt;span class="n"&gt;pub&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;         &lt;span class="c1"&gt;// take a note down&lt;/span&gt;
&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                  &lt;span class="c1"&gt;// at start: read the whole board into memory&lt;/span&gt;
&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                   &lt;span class="c1"&gt;// then follow every new note&lt;/span&gt;
&lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Reconcile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;           &lt;span class="c1"&gt;// board vs memory: prune what is gone, upsert what changed&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fze1dj5e45nnmvj2nf4cf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fze1dj5e45nnmvj2nf4cf.png" alt="A dark card with the state-watch form; the last line - the subscription lives until Stop, not until the start context ends - is highlighted; pills read built, and barely used yet" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The board itself is a watched key-value store; the first backend is the NATS key-value store. A publisher writes and deletes keys. Each replica's watcher reads a snapshot of all keys on start - Biscuit reading the whole board - and then follows the deltas. The reconciler is the self-healing part: it compares the projection in memory with the store and fixes memory by pruning what is gone and upserting what changed.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Step&lt;/th&gt;
&lt;th&gt;Keeper's habit&lt;/th&gt;
&lt;th&gt;What it protects against&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;put / delete&lt;/td&gt;
&lt;td&gt;pin a note, take it down&lt;/td&gt;
&lt;td&gt;state living in one head&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;sync at start&lt;/td&gt;
&lt;td&gt;read the whole board first&lt;/td&gt;
&lt;td&gt;starting from a stale memory&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;run&lt;/td&gt;
&lt;td&gt;follow new notes&lt;/td&gt;
&lt;td&gt;missing a change while working&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;reconcile&lt;/td&gt;
&lt;td&gt;fix memory from the board&lt;/td&gt;
&lt;td&gt;a missed note, a torn note&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkhs1k7gmvt7sqg7uqtt1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkhs1k7gmvt7sqg7uqtt1.png" alt="An animation: the publisher puts a note, feed at noon; it lands on the watched store; replica 1 follows it; replica 2 reads it too" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What goes on a board
&lt;/h2&gt;

&lt;p&gt;A board is for short notes that every keeper must agree on, not for the zoo's archive. As a form - the keys and values are placeholders:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;key:   &amp;lt;area&amp;gt;/&amp;lt;thing&amp;gt;              e.g. jobs/&amp;lt;name&amp;gt;, sources/&amp;lt;name&amp;gt;
value: { "enabled": true, "revision": &amp;lt;n&amp;gt; }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The rule of thumb I use for what belongs there: a value that every replica must hold the same, that changes rarely compared with how often it is read, and that is small enough to hold in memory whole. A list of switches fits. A history of every change does not - that belongs in a table, and the board holds only where the table is now.&lt;/p&gt;

&lt;p&gt;The other rule is the direction. The board is the truth and memory is a projection of it. A replica never writes its memory back to the board to "fix" it; it only reads. When the two disagree, the board wins, which is exactly what the reconciler enforces.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who reads the board
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fykqqte7n4flaubgmi2wf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fykqqte7n4flaubgmi2wf.png" alt="Bars: steps - snapshot, deltas, reconcile - 3; services importing it 2; service it was lifted from 1; Nora says two keepers read it so far; pills read built, and barely used yet" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fitjn5kj0f42ppgg571oh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fitjn5kj0f42ppgg571oh.png" alt="Columns: files about 40, commits since October 6, services 2; Pickle, bored, says built, waiting for readers; a pill reads counted, rounded" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Two services import the package. That is the honest size: a board with two keepers reading it, and a zoo that still has its phones.&lt;/p&gt;

&lt;h2&gt;
  
  
  What went wrong
&lt;/h2&gt;

&lt;p&gt;The board had one real bug, and it is the most instructive part of this story. Before a fix in October, the subscription that follows new notes was tied to the context of the start - and that context ends when start is over. So a replica read the whole board, began to follow new notes, and then quietly stopped. Nothing failed. The memory simply stopped changing.&lt;/p&gt;

&lt;p&gt;That is Biscuit reading the board when he arrives, then walking away from the gate for the rest of the day. The fix in the library's changelog is one line of meaning: the subscription lives until Stop, not until the start context ends. The reconciler would eventually have repaired the memory, but a self-healing loop that hides a stopped subscription is not healing, it is covering.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbjn3bftfucqas12v1hxn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbjn3bftfucqas12v1hxn.png" alt="Before and after: the first version - start context ended the subscription; stale, memory stopped following - and the fix - until Stop, the subscription lives on; healing, reconcile catches drift; a pill reads fixed" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The lesson I keep: when something has to run for the life of a process, tie it to the life of the process - not to the call that started it. A context is a promise about how long something may run, and the start context promises very little.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi0mjaakcnh70jfqcy3in.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi0mjaakcnh70jfqcy3in.png" alt="Service tiles with faces: the publisher, the watched store and two replicas are happy; a late replica happy; phone calls bored; the reconciler proud; other services bored; pills read built, and barely used yet" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I do not claim
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Not that many services use the board. Two do.&lt;/li&gt;
&lt;li&gt;Not that the reconciler replaces a working subscription. It catches drift.&lt;/li&gt;
&lt;li&gt;Not a measured delay between a put and every replica seeing it.&lt;/li&gt;
&lt;li&gt;Not that every backend is supported. The first one is the NATS key-value store.&lt;/li&gt;
&lt;li&gt;Not the exact API. The Go above is a form.&lt;/li&gt;
&lt;li&gt;Not that the rule of thumb for what goes on a board is the library's. It is mine.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What of this is method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One board, many readers.&lt;/strong&gt; Desired state in a watched store, not in heads.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read everything, then follow.&lt;/strong&gt; A snapshot at start, deltas after.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tie a lifetime to the process, not the start.&lt;/strong&gt; A subscription ends at Stop.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Zoo keeping, built in - Part 11.&lt;/strong&gt; Next: &lt;em&gt;Moving Old Animals Out Without Closing The Zoo&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;your replicas share state&lt;/strong&gt;, do they read it from a board or ask each other? If &lt;strong&gt;you watch a key-value store&lt;/strong&gt;, what happens to a replica that missed a delta? If &lt;strong&gt;you had a subscription stop quietly&lt;/strong&gt;, how did you notice? Which keeper in your zoo is still on the phone?&lt;/p&gt;

</description>
      <category>programming</category>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>The Feeder That Learns From Bites</title>
      <dc:creator>Anton Brilliantov</dc:creator>
      <pubDate>Thu, 26 Nov 2026 11:51:37 +0000</pubDate>
      <link>https://dev.to/anton_brilliantov/the-feeder-that-learns-from-bites-5caj</link>
      <guid>https://dev.to/anton_brilliantov/the-feeder-that-learns-from-bites-5caj</guid>
      <description>&lt;p&gt;&lt;em&gt;The queue to the feeder narrows when the animal bites and widens when it is calm - and every keeper reads the same counter, so the animal is not fed by five keepers at once.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;👋 Hi, I'm Anton - a software engineer. These days I work on a platform: contracts, generated code, data paths and the tooling around them. Running notes live on my GitHub: &lt;strong&gt;&lt;a href="https://github.com/brilliant-almazov" rel="noopener noreferrer"&gt;github.com/brilliant-almazov&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The learning limit was lifted from one service into the shared library; in the library it is built and no service imports it yet, and the counter under it has three backends. The curve in this part is a shape, not a measurement.&lt;/p&gt;

&lt;p&gt;This is part 10 of the series on what a shared platform does for every service, told as a zoo. Maybe you already do it better, maybe you'd do it another way - this is how it is going, and where it stops.&lt;/p&gt;




&lt;h2&gt;
  
  
  In real life
&lt;/h2&gt;

&lt;p&gt;Next door to the zoo lives a cat who does not belong to us. Miso, in this story, is the neighbour, and the neighbour has the thing we need - so we feed the neighbour, and the neighbour gives something back. Biscuit runs the feeder. He is enthusiastic: "More food? More food!"&lt;/p&gt;

&lt;p&gt;Miso bites. "HISS."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6k4e2j1nvb3nll1z8e4u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6k4e2j1nvb3nll1z8e4u.png" alt="A four-panel comic: Biscuit at a wide feeder offers more food and Miso hisses; Pip narrows the feeder one step after the bite; Pickle asks narrower still and Pip says never below the floor; Nora says one counter for all the keepers and Miso, calm at a wider feeder, purrs" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pip knows what a bite means: too much, too fast. Narrow the feeder by one step. Another bite, another step. But never below the floor - Pickle asks "narrower still?" and Pip says no: a feeder narrowed to nothing feeds nobody. Then, after a quiet while with no bites, the feeder widens again, one step at a time, until Miso purrs. And Nora adds the rule that makes it work with more than one keeper: there is one counter for all of them, so five keepers do not each think the feeder is theirs.&lt;/p&gt;

&lt;h2&gt;
  
  
  A limit you cannot know in advance
&lt;/h2&gt;

&lt;p&gt;Outside sources - the ones a service calls over the network and does not own - have limits. Sometimes they are written down, often they are not, and they change: a busy hour, a new plan, a different region. A fixed limit in configuration is either too careful and wastes capacity, or too generous and gets bitten.&lt;/p&gt;

&lt;p&gt;The second problem is replicas. A service runs as several copies. A limit kept in each copy's memory is a limit per copy: three replicas, three times the calls the source agreed to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmvph7vhgzww9ogks4hci.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmvph7vhgzww9ogks4hci.png" alt="Three tiles with faces: every replica, happy; the shared counter, proud; a source, bored; labels read a slot?, and within the window; pills read built, and barely used yet" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A window that learns
&lt;/h2&gt;

&lt;p&gt;The library's rate window answers both. It keeps two windows - per second and per minute - and it reacts to the source. When the source answers "limit", the window shrinks by a step, but not below a minimum. When a recovery period passes without any "limit", it grows by a step. And the occupied slots are not kept in memory: they live in the library's distributed counter, so the limit is one for all replicas. The library's description puts it in those words - the limit is common to every replica.&lt;/p&gt;

&lt;p&gt;As a form - the names are illustrative:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;rate_window&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;per_second&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;n&amp;gt;&lt;/span&gt;
  &lt;span class="na"&gt;per_minute&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;n&amp;gt;&lt;/span&gt;
  &lt;span class="na"&gt;throttle_step&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;n&amp;gt;&lt;/span&gt;       &lt;span class="c1"&gt;# the source says "limit": narrow by a step
&lt;/span&gt;  &lt;span class="na"&gt;minimum&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;n&amp;gt;&lt;/span&gt;             &lt;span class="c1"&gt;# never below
&lt;/span&gt;  &lt;span class="na"&gt;recovery&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;duration&amp;gt;&lt;/span&gt;     &lt;span class="c1"&gt;# no refusals this long: one step wider
&lt;/span&gt;  &lt;span class="na"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;redis | nats-kv | postgres&lt;/span&gt;   &lt;span class="c1"&gt;# shared by every replica
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5vv0xk2vbvt0nh6a9yi1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5vv0xk2vbvt0nh6a9yi1.png" alt="A dark card with the rate window settings as a form; the minimum line is highlighted; pills read built, and barely used yet" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The shape of the ceiling over time looks like the comic: flat while things are calm, down a step on each bite, resting on the floor, then climbing back after quiet periods. The picture below is that shape, drawn - not a measurement of any source.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiev1o0wct809oa8ql44z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiev1o0wct809oa8ql44z.png" alt="A line: the ceiling steps down from 10 on bites to a floor at 6, then recovers step by step to 10 in the quiet; a dashed floor line; Miso says bite less, eat more; a pill reads a shape, not a measurement" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Event&lt;/th&gt;
&lt;th&gt;What the window does&lt;/th&gt;
&lt;th&gt;Why&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;the source answers "limit"&lt;/td&gt;
&lt;td&gt;shrinks by a step&lt;/td&gt;
&lt;td&gt;it bit: too much, too fast&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;it shrinks to the minimum&lt;/td&gt;
&lt;td&gt;stops shrinking&lt;/td&gt;
&lt;td&gt;a feeder of zero feeds nobody&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;a recovery period with no "limit"&lt;/td&gt;
&lt;td&gt;grows by a step&lt;/td&gt;
&lt;td&gt;it is calm: try a little more&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;a call from any replica&lt;/td&gt;
&lt;td&gt;takes a slot in the shared counter&lt;/td&gt;
&lt;td&gt;one limit for the whole service&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;From the calling side, the shape is short - names shortened, a form:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c1"&gt;// a call to an outside source - a form&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Acquire&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;                      &lt;span class="c1"&gt;// no free slot in the shared counter: wait or refuse&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;saysLimit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Throttle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;            &lt;span class="c1"&gt;// it bit: one step narrower, not below the minimum&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What counts as a bite is the source's own signal - an HTTP 429, a quota error, whatever that source says when it means "too much". Recognising it is the one part each caller writes, because only the caller knows how its source says no.&lt;/p&gt;

&lt;h2&gt;
  
  
  One counter, three backends
&lt;/h2&gt;

&lt;p&gt;The shared part sits on the library's distributed counter: one interface, three backends - Redis, a NATS JetStream key-value store, and PostgreSQL - with a decorator that adds metrics. A service picks whichever its stand already runs. The window does not care which.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuq0xzshg92iqe5k0boec.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuq0xzshg92iqe5k0boec.png" alt="Columns: windows 2, counter backends 3, services importing 0; Biscuit, bored, says lifted from one service, waiting; pills read built, and barely used yet" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fddvr6rp1zdeb64m0lm56.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fddvr6rp1zdeb64m0lm56.png" alt="Before and after: per replica - N limits, each replica guesses alone; fixed, the same after every bite - and shared - 1 limit in one counter for all; learns, down on a bite, up when quiet" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvpebccejx98kce1pc9wl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvpebccejx98kce1pc9wl.png" alt="An animation: the window is 10; the source says limit and turns angry, the window goes to 9; more bites take it down to the floor at 6; the source is calm again and the window climbs back step by step" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Where it came from
&lt;/h2&gt;

&lt;p&gt;The window was not designed in the library first. It was written in a service that called an outside source and needed exactly this, and then it was lifted into the library so the next service would not write it again. That is how most of the library grows: one resident solves a problem, and the solution moves to the keeper's handbook. In the library itself, no service imports it yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  What went wrong
&lt;/h2&gt;

&lt;p&gt;The failure this answers is the one every service that calls an outside source meets sooner or later: a fixed limit that is right on a quiet day and wrong on a busy one, multiplied by the number of replicas. Each replica behaves well on its own, and the source sees the sum.&lt;/p&gt;

&lt;p&gt;The honest lesson is about where the code lives. A good mechanism inside one service helps one service. Lifting it into the library is half the work; the other half is the second service that uses it, and that has not happened yet. Until it does, this is a tool on a shelf.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flcn58iigcbly7d3w4rmt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flcn58iigcbly7d3w4rmt.png" alt="Service tiles with faces: three replicas happy; the shared counter proud; a biting source angry; the floor bored; pills read built, and barely used yet" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I do not claim
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Not a measured curve. The line is a shape.&lt;/li&gt;
&lt;li&gt;Not that any service imports the library version yet. None does.&lt;/li&gt;
&lt;li&gt;Not the right numbers for step, floor or recovery. They are per source.&lt;/li&gt;
&lt;li&gt;Not the exact settings format. The form above shows the shape.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What of this is method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Learn the limit from the refusals.&lt;/strong&gt; Down a step on "limit", up a step on quiet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Never below a floor.&lt;/strong&gt; A limit of zero is an outage you made yourself.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One limit per service, not per replica.&lt;/strong&gt; Keep the slots in a shared counter.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Zoo keeping, built in - Part 10.&lt;/strong&gt; Next: &lt;em&gt;A Notice Board For Every Keeper&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;you call outside sources with limits&lt;/strong&gt;, is your limit fixed or learned? If &lt;strong&gt;you run several replicas&lt;/strong&gt;, does each keep its own limit? If &lt;strong&gt;you lifted a mechanism from a service into a library&lt;/strong&gt;, who was its second user? How does your feeder react to a bite?&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Same "Seat Taken", Before And After The Race</title>
      <dc:creator>Anton Brilliantov</dc:creator>
      <pubDate>Wed, 25 Nov 2026 08:56:17 +0000</pubDate>
      <link>https://dev.to/anton_brilliantov/same-seat-taken-before-and-after-the-race-1ahp</link>
      <guid>https://dev.to/anton_brilliantov/same-seat-taken-before-and-after-the-race-1ahp</guid>
      <description>&lt;p&gt;&lt;em&gt;Whether the keeper saw the seat was taken, or two visitors sat down at the same moment, "seat taken" should sound the same. Built, barely used yet.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;👋 Hi, I'm Anton - a software engineer. These days I work on a platform: contracts, generated code, data paths and the tooling around them. Running notes live on my GitHub: &lt;strong&gt;&lt;a href="https://github.com/brilliant-almazov" rel="noopener noreferrer"&gt;github.com/brilliant-almazov&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This part is about built code that is barely used yet: the package is in the shared library, and no service imports it so far. The printed write guard in our services follows the same rule by its own route; this part is about the rule and the library's version of it.&lt;/p&gt;

&lt;p&gt;This is part 9 of the series on what a shared platform does for every service, told as a zoo. Maybe you already do it better, maybe you'd do it another way - this is how it is going, and where it stops.&lt;/p&gt;




&lt;h2&gt;
  
  
  In real life
&lt;/h2&gt;

&lt;p&gt;There is one good bench in the zoo, in the shade, next to the giraffes. Miso is on it. Pickle walks up: "Can I sit?" Nora, passing by, answers for the cat: "Seat taken." Clear, polite, done.&lt;/p&gt;

&lt;p&gt;The next day the bench is empty, and Pickle and Biscuit see it at the same moment. They both run, they both sit, and they land on each other. "Ouch!" "Mine!"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fw5fcp4dmtfvmdw91y5sn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fw5fcp4dmtfvmdw91y5sn.png" alt="A four-panel comic: Pickle asks to sit on a bench where Miso sits and Nora says seat taken; Pickle and Biscuit sit on the bench at once, ouch, mine; Biscuit complains he got error 23505 while the other got seat taken; Nora says seat taken, both times, and Biscuit says fair is fair" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The joke is in the third panel. One of them gets told "seat taken". The other one, who lost the race by a hair, gets told "error 23505". Same bench, same outcome - you do not get to sit - and two completely different answers depending on when exactly you lost. Biscuit is outraged, and he is right. In the last panel Nora fixes it the only fair way: "Seat taken. Both times."&lt;/p&gt;

&lt;h2&gt;
  
  
  Two ways to lose a key
&lt;/h2&gt;

&lt;p&gt;A service that keeps something unique - an email, a name, a slug - usually checks before it writes: is the key taken? If it is, the caller gets a clean refusal with a reason and the field. That is the keeper who saw the cat on the bench.&lt;/p&gt;

&lt;p&gt;But a check before a write cannot see a write that happens between the check and the write. Two requests can both pass the check, and one of them loses at the unique index. What that loser hears depends on how the write path was written. Often it is the database's own error - a unique violation code - mapped to something generic, or leaking through as is.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9jmatbqqi1ia63dnjyb2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9jmatbqqi1ia63dnjyb2.png" alt="Three tiles with faces: a pre-check, happy; the write, worried; one refusal, proud; labels read free, write, and race recognised; pills read built, and barely used yet" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the caller that is two answers to one question. A client that handles "seat taken" well will fail on the race, and nobody will see it in tests, because tests rarely race.&lt;/p&gt;

&lt;h2&gt;
  
  
  One reason, both times
&lt;/h2&gt;

&lt;p&gt;The library's conflict package makes the rule explicit: a pre-check that finds the key taken and a race recognised at the write give the same refusal. A probe answers "is it taken?" before the write; a recogniser looks at the write's error and answers "was that a race on this key?"; both produce one reason with one field. In the shape of the code - names shortened:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c1"&gt;// one refusal for a taken key - a form&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;probe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Taken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;fault&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Reason&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;KeyTaken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;// seen before the write&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;race&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Race&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;fault&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Reason&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;KeyTaken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;// two writers at once&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhnd3tw5b4l1z14ln7olj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhnd3tw5b4l1z14ln7olj.png" alt="A dark card with the conflict form; the line with the race returning the same reason is highlighted; pills read built, and barely used yet" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Path&lt;/th&gt;
&lt;th&gt;What the caller heard before&lt;/th&gt;
&lt;th&gt;What it hears now&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;pre-check finds it taken&lt;/td&gt;
&lt;td&gt;a reason and the field&lt;/td&gt;
&lt;td&gt;the same reason and field&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;race lost at the write&lt;/td&gt;
&lt;td&gt;a database code, or a generic error&lt;/td&gt;
&lt;td&gt;the same reason and field&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;no conflict&lt;/td&gt;
&lt;td&gt;success&lt;/td&gt;
&lt;td&gt;success&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffyxkfhl7ma4d9prbp7hw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffyxkfhl7ma4d9prbp7hw.png" alt="Columns: reasons a caller sees for one taken key - before 2, after 1; Pickle says one answer, easy to test; a pill reads by design" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The benefit is not only fairness. One reason means one branch in the client and one test case for it. And the race path - the one nobody tests because it is hard to make happen - now goes through the same code as the easy path, which is the one everybody tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a lost race looks like from inside
&lt;/h2&gt;

&lt;p&gt;In PostgreSQL, the loser of the race gets an error like this - the shape is standard, the names are placeholders:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ERROR:  duplicate key value violates unique constraint "&amp;lt;table&amp;gt;_&amp;lt;column&amp;gt;_key"
SQLSTATE 23505
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That error is true and useless to a caller. It names a constraint, not a field the caller sent; it uses the database's vocabulary, not the API's; and it says nothing a client can branch on except "something about uniqueness". The recogniser's job is to read it and answer one question: was this a race on the key I care about? If yes, the caller gets the same reason and field as the pre-check. If it is some other unique constraint, it stays some other error.&lt;/p&gt;

&lt;p&gt;This is also why the pre-check is still worth keeping. It is not the guarantee - the unique index is - but it is the common path, it is cheap, and it gives the answer without a failed write. The race path exists for the rare moment when two people want the same bench, and now that moment sounds exactly like the common one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frqa937b3cwm3p1h7en9y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frqa937b3cwm3p1h7en9y.png" alt="An animation: writer A and writer B both see the seat free; A writes first; B loses the race and turns angry; B hears seat taken, field email, and turns happy" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Built, barely used yet
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F60rufgfdld81xewj0sgx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F60rufgfdld81xewj0sgx.png" alt="Bars: files 5, commits since October 0, services importing it 0; Miso, bored, says a fine bench, nobody sits; pills read built, and barely used yet" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the honest state. The package is small - five files - and it has not changed since it landed. No service imports it. Our services guard their writes with a printed write guard that follows the same rule - one refusal for a taken key, with the race mapped - and the library package is the shared version of that rule waiting for its first tenant. When I wrote a list of things in the library that are declared but not taken, this one was on it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fa3eo5azlz6car8lvxoro.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fa3eo5azlz6car8lvxoro.png" alt="Before and after: two answers - a reason when the pre-check saw it; a db code when the race lost it - and one answer - 1 reason with the field, both times; 1 test for the caller to write" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What went wrong
&lt;/h2&gt;

&lt;p&gt;The failure this answers is the classic one: the pre-check gives a nice answer, the race gives an ugly one, and the ugly one only appears under load. A pre-check alone feels safe, because every test passes - tests rarely send two requests at the same instant.&lt;/p&gt;

&lt;p&gt;The second thing that went wrong is the one I am reporting on myself: a rule this useful, built in the shared library, with no service using it. A package nobody imports is a bench nobody sits on - fine to look at, and it proves nothing until someone does. The next step for it is a first real caller, not more code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwbm15uwqq0nlezkpwq1u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwbm15uwqq0nlezkpwq1u.png" alt="Service tiles with faces: the pre-check, the race check and the caller are happy; the bench and services bored; the library proud; pills read built, and barely used yet" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I do not claim
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Not that any service uses the package. None imports it yet.&lt;/li&gt;
&lt;li&gt;Not how often the race happened in production. I did not measure it.&lt;/li&gt;
&lt;li&gt;Not that the printed write guard and the package are the same code. They follow the same rule.&lt;/li&gt;
&lt;li&gt;Not the exact API. The Go above is a form.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What of this is method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One question, one answer.&lt;/strong&gt; "Taken" sounds the same before and after the race.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Route the hard path through the easy one.&lt;/strong&gt; The race ends in the code everybody tests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A rule nobody uses is a proposal.&lt;/strong&gt; Count the callers before counting it done.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Zoo keeping, built in - Part 9.&lt;/strong&gt; Next: &lt;em&gt;The Feeder That Learns From Bites&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;you pre-check unique keys&lt;/strong&gt;, what does the loser of a race hear? If &lt;strong&gt;you map unique violations&lt;/strong&gt;, do they become the same reason as the pre-check? If &lt;strong&gt;you have built code nobody uses yet&lt;/strong&gt;, how do you find its first caller? What does "seat taken" sound like in your API?&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>No Night Watchman For Partitions</title>
      <dc:creator>Anton Brilliantov</dc:creator>
      <pubDate>Tue, 24 Nov 2026 09:29:51 +0000</pubDate>
      <link>https://dev.to/anton_brilliantov/no-night-watchman-for-partitions-29d0</link>
      <guid>https://dev.to/anton_brilliantov/no-night-watchman-for-partitions-29d0</guid>
      <description>&lt;p&gt;&lt;em&gt;The cage is built when the resident arrives, not by a watchman who walks the zoo at night counting whether there are enough cages for tomorrow.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;👋 Hi, I'm Anton - a software engineer. These days I work on a platform: contracts, generated code, data paths and the tooling around them. Running notes live on my GitHub: &lt;strong&gt;&lt;a href="https://github.com/brilliant-almazov" rel="noopener noreferrer"&gt;github.com/brilliant-almazov&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Partitions at write time are built into the shared library; four services use the package. I describe the mechanism, not a measurement of its cost on a busy table.&lt;/p&gt;

&lt;p&gt;This is part 8 of the series on what a shared platform does for every service, told as a zoo. Maybe you already do it better, maybe you'd do it another way - this is how it is going, and where it stops.&lt;/p&gt;




&lt;h2&gt;
  
  
  In real life
&lt;/h2&gt;

&lt;p&gt;Biscuit has a night job. With a lamp, every night, he walks the zoo and counts the empty cages: are there enough for tomorrow's arrivals? "Enough cages for tomorrow? Again..." It is the most boring job in the zoo, and Biscuit does it with exactly the enthusiasm it deserves.&lt;/p&gt;

&lt;p&gt;One night he oversleeps. A new resident arrives in the morning, and there is no cage. Pickle finds it standing on the path with its parcel: "A new resident and no cage!"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ff6bq0wkvas4l5fidy4jn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ff6bq0wkvas4l5fidy4jn.png" alt="A four-panel comic: Biscuit under a lamppost at night asks again whether there are enough cages for tomorrow; Biscuit asleep while Pickle finds a new resident with no cage; Pip next to a fresh cage says it arrived, build its cage now; Nora says into the book only when it stands" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pip's answer is to fire the night shift. A cage is built when a resident arrives - at that moment, for that resident, not ahead of time by someone guessing. And Nora adds the rule that keeps the register honest: the cage goes into the book only when it actually stands. Not when someone started building it.&lt;/p&gt;

&lt;h2&gt;
  
  
  A partition per time range
&lt;/h2&gt;

&lt;p&gt;Some of our tables are partitioned by time: one partition per day, per month, per year. A row must land in a partition that covers its timestamp. The classic way to make sure that partition exists is a scheduled job that creates the next few partitions ahead of time - the night watchman. Before this package, the library had exactly one such watchman, and it knew exactly one table: the audit journal.&lt;/p&gt;

&lt;p&gt;The night watchman fails in the boring ways. It runs on a schedule, so it guesses how far ahead to go. It oversleeps when the scheduler is down. It knows only the tables someone told it about. And a row for a range nobody guessed - a late event, a timestamp in the future - finds no cage.&lt;/p&gt;

&lt;h2&gt;
  
  
  The cage comes with the resident
&lt;/h2&gt;

&lt;p&gt;The partition package does the opposite. At the moment of a write, it makes sure the partition for that row's range exists, creates it if it does not, and only then lets the row in. In the library's own words: partitions are created at the moment of writing, there is no default step, the name is remembered only after the creating transaction commits, and there are no background scanners.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frzu9oxkiq87jm4oshdc9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frzu9oxkiq87jm4oshdc9.png" alt="Three tiles with faces: a write, happy; the partition check, proud; the table, happy; labels read a row for a range, and create if missing; a pill reads built" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a form - the names are illustrative:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;partition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;table&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;schema.table&amp;gt;&lt;/span&gt;
  &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;created_at&lt;/span&gt;
  &lt;span class="na"&gt;step&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Month&lt;/span&gt;              &lt;span class="c1"&gt;# Day | Week | Month | Year | Every(d); no default
# on write: no partition for the row's range -&amp;gt; create it, then insert
# the name is remembered only after the creating transaction commits
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F96sagjf89b8n9qai3ltu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F96sagjf89b8n9qai3ltu.png" alt="A dark card with the partition form; the step line, Month, with the list of allowed steps and no default, is highlighted; a pill reads built" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In PostgreSQL terms, the first row of a new month does roughly this - a form, the naming is illustrative:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- the row's range has no partition yet&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;table&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;range&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="no"&gt;OF&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;table&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;FOR&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'&amp;lt;range start&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;TO&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'&amp;lt;range end&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;table&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;-- every later row of that range goes straight to the INSERT&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three decisions in that form carry the design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No default step.&lt;/strong&gt; The application chooses Day, Week, Month, Year or an arbitrary period, and the package refuses to guess. A default would be right for some tables and silently wrong for others.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remembered after commit.&lt;/strong&gt; The package caches the names of partitions it knows exist, so it does not ask the database on every write. It adds a name to that cache only after the transaction that created the partition commits. If the transaction rolls back, the partition does not exist, and a cache that remembered it anyway would let the next row in through a door that is not there. That is Nora's rule: into the book only when the cage stands.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No scanner at all.&lt;/strong&gt; Nothing walks the tables in the background. The only time a partition is created is when a row needs it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frn3cxl7w8aqkl8bszwgh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frn3cxl7w8aqkl8bszwgh.png" alt="Bars: background scanners 0, steps to choose from 5, services using it 4; Biscuit says I sleep at night now; a pill reads built" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F865xjn5vh5ojlhkkikhr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F865xjn5vh5ojlhkkikhr.png" alt="A waffle of six cells: five teal cells with checks - Day, Week, Month, Year, Every; one red cell with a cross - a default step, none, the app chooses; Nora says you choose the step; a pill reads built" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Night watchman&lt;/th&gt;
&lt;th&gt;At write time&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;when a partition appears&lt;/td&gt;
&lt;td&gt;on a schedule, ahead&lt;/td&gt;
&lt;td&gt;when a row needs it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;a row for an unguessed range&lt;/td&gt;
&lt;td&gt;no partition, failed write&lt;/td&gt;
&lt;td&gt;its partition is created&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;which tables&lt;/td&gt;
&lt;td&gt;the one it knew&lt;/td&gt;
&lt;td&gt;any table that declares a step&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;the cache of known names&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;filled only after commit&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcyro8akbi6aznl4u25m6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcyro8akbi6aznl4u25m6.png" alt="An animation: a write for next month reaches the partition check, which finds no partition yet, creates it in the same moment, and the row lands in the table with the name cached" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Who asked for it
&lt;/h2&gt;

&lt;p&gt;The package came from a request: the admin service wanted a partitioned journal of console calls, and the only partition helper the library had was the one built for its own audit journal. Instead of a second watchman for a second table, the library got a package any table can use. Four services use it today - the admin service, the identity service, the security service and the project data service.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcacveum00dpfsj10ubs7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcacveum00dpfsj10ubs7.png" alt="Before and after: a watchman - a scanner on a schedule, guessing ahead; 1 table, the only one it knew - and at write time - 0 scanners, the write makes the cage; any table, the step is a parameter" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What went wrong
&lt;/h2&gt;

&lt;p&gt;The failure this answers is a design one, not an incident I can point to: a scheduled partition creator is a second moving part that must be right for a write to succeed, and it is only right as long as its guess about the future is right. Every table that wanted partitions would have needed its own watchman or its own entry in the one that existed.&lt;/p&gt;

&lt;p&gt;The quieter lesson is in the cache. Remembering a partition before its transaction commits is the kind of bug that never shows up in a test - until a rollback happens in exactly the wrong place. Writing "only after commit" into the package's own description is how we keep that rule from being optimised away.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl1ccwhd2sybvrei6yigh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl1ccwhd2sybvrei6yigh.png" alt="Service tiles with faces: the admin journal, identity, security and project data are happy; the partition check proud; the night watchman bored; the write happy; the step happy; a pill reads built" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I do not claim
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Not a measurement of the cost of the check on a busy table. It is built, not benchmarked here.&lt;/li&gt;
&lt;li&gt;Not that every partitioned table has moved to the package. Four services use it.&lt;/li&gt;
&lt;li&gt;Not that a night watchman is never right. It is not needed here.&lt;/li&gt;
&lt;li&gt;Not the exact settings format. The form above shows the shape.&lt;/li&gt;
&lt;li&gt;Not the exact statements the package runs. The SQL above is a form of the idea.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What of this is method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Create the cage when the resident arrives.&lt;/strong&gt; Not ahead, by guessing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Remember only what committed.&lt;/strong&gt; A cache filled before commit lies after a rollback.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No default where defaults differ.&lt;/strong&gt; The application chooses the step.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Zoo keeping, built in - Part 8.&lt;/strong&gt; Next: &lt;em&gt;Same "Seat Taken", Before And After The Race&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;you partition by time&lt;/strong&gt;, who creates the next partition - a job or the write? If &lt;strong&gt;your job oversleeps&lt;/strong&gt;, what happens to the first row of the new month? If &lt;strong&gt;you cache partition names&lt;/strong&gt;, when exactly do you add one? Who walks your zoo with a lamp at night?&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>softwareengineering</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>A New Species Is One Line In The Register</title>
      <dc:creator>Anton Brilliantov</dc:creator>
      <pubDate>Mon, 23 Nov 2026 07:32:58 +0000</pubDate>
      <link>https://dev.to/anton_brilliantov/a-new-species-is-one-line-in-the-register-35gp</link>
      <guid>https://dev.to/anton_brilliantov/a-new-species-is-one-line-in-the-register-35gp</guid>
      <description>&lt;p&gt;&lt;em&gt;A new species does not need a new cage welded by hand. It needs one line in the register - and writing that line turned up blank pages nobody had noticed.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;👋 Hi, I'm Anton - a software engineer. These days I work on a platform: contracts, generated code, data paths and the tooling around them. Running notes live on my GitHub: &lt;strong&gt;&lt;a href="https://github.com/brilliant-almazov" rel="noopener noreferrer"&gt;github.com/brilliant-almazov&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The dictionary section of the manifest and the closed-set package behind it are built into the shared library and its generator; five services use the package. The two findings below were found and fixed in the same pass.&lt;/p&gt;

&lt;p&gt;This is part 7 of the series on what a shared platform does for every service, told as a zoo. Maybe you already do it better, maybe you'd do it another way - this is how it is going, and where it stops.&lt;/p&gt;




&lt;h2&gt;
  
  
  In real life
&lt;/h2&gt;

&lt;p&gt;A new species arrives at the zoo: a lizard nobody has kept before. Nora reaches for the welding torch - "A new lizard! Weld a cage?" Pip stops her: "Put the torch down, Nora."&lt;/p&gt;

&lt;p&gt;Because a new species in a well-run zoo is not a new cage. It is one line in the register: name, what it eats, how warm it likes it. The cage follows from the line.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7arxywrwgfbaxmg8my2u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7arxywrwgfbaxmg8my2u.png" alt="A four-panel comic: Nora with an empty cage asks to weld a cage for a new lizard and Pip tells her to put the torch down; Pip next to a sign reading lizard, warm, sunny says one line, the cage follows; Pickle finds two columns never filled and Nora asks since when; Miso says the checker said no to everyone and Pip adds even to the right answers" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Writing the line is where the story turns funny. Pickle opens the register to add the lizard and finds two columns that were never filled in for anybody - "since when?" asks Nora, and nobody knows. And Miso reports that the checker at the gate, the one who checks that the register matches the cages, had been saying no to everyone. Pip finishes the joke: "Even to the right answers."&lt;/p&gt;

&lt;h2&gt;
  
  
  A closed set of codes is a species
&lt;/h2&gt;

&lt;p&gt;Our services have many small closed sets: statuses, kinds, types of things, each code with a title, sometimes with a parent code or a group. Every one of them needs the same handful of operations: parse a code, check it is valid, get its title, ask whether one code descends from another, ask whether a code belongs to a group.&lt;/p&gt;

&lt;p&gt;Before, a new set meant a new piece of Go in the service - a cage welded by hand. Now the shared library has one package for closed sets, and the service manifest has a &lt;code&gt;dictionary&lt;/code&gt; section. A new kind is a manifest entry; the printed package of the service holds only the table of codes; parsing, checks and walking the tree live in the library.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuzmea54q0ntygl2z9cg2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuzmea54q0ntygl2z9cg2.png" alt="Three tiles with faces: one manifest line, happy; the generator, proud; a service table, happy; labels read printed, and lookups in the library; a pill reads built" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a form - the names are illustrative:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;dictionary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;kind&amp;gt;&lt;/span&gt;
    &lt;span class="na"&gt;values&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;code:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;a&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;title:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;A&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;code:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;b&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;title:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;B&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;parent:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;a&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwyylujqrbzpbo43geca6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwyylujqrbzpbo43geca6.png" alt="A dark card with the dictionary section as a form, the line with the name of the kind highlighted, and a note that the service prints only the table while lookups, checks and tree walks are in the library; a pill reads built" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The library's changelog puts it as plainly as the comic: a new kind of dictionary is a line of the manifest, without a line of Go.&lt;/p&gt;

&lt;h2&gt;
  
  
  Five gates on five lookups
&lt;/h2&gt;

&lt;p&gt;A lookup that runs on every request is a place where small costs pile up. The closed-set package has allocation ceilings on its five lookups - parse, valid, title, descends, in group - the same kind of gate that the library uses elsewhere: a test fails if a lookup starts allocating more than its ceiling.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F23ky65x091ncqhmm7mm7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F23ky65x091ncqhmm7mm7.png" alt="Bars: lines of Go for a new kind 0, allocation gates on lookups 5, services using it 5; Pickle says gates on every lookup; a pill reads built" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Lookup&lt;/th&gt;
&lt;th&gt;Question it answers&lt;/th&gt;
&lt;th&gt;Gate&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;parse&lt;/td&gt;
&lt;td&gt;is this string a code of the set?&lt;/td&gt;
&lt;td&gt;allocation ceiling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;valid&lt;/td&gt;
&lt;td&gt;is this code allowed?&lt;/td&gt;
&lt;td&gt;allocation ceiling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;title&lt;/td&gt;
&lt;td&gt;what do people call it?&lt;/td&gt;
&lt;td&gt;allocation ceiling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;descends&lt;/td&gt;
&lt;td&gt;is this code under that one?&lt;/td&gt;
&lt;td&gt;allocation ceiling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;in group&lt;/td&gt;
&lt;td&gt;does this code belong to the group?&lt;/td&gt;
&lt;td&gt;allocation ceiling&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;On the reading side, a handler uses the set through the same five questions. In the shape of the code, with names shortened:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c1"&gt;// in a handler - a form&lt;/span&gt;
&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;kinds&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;            &lt;span class="c1"&gt;// is this a code of the set?&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;kinds&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Valid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;refuse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reasonUnknownKind&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    &lt;span class="c1"&gt;// a refusal with a reason, not a panic&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;kinds&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Descends&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;kinds&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;InGroup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;kinds&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;          &lt;span class="c1"&gt;// what people call it&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;None of those five functions is written in the service. The service wrote the table; the questions came with the library.&lt;/p&gt;

&lt;h2&gt;
  
  
  The blank pages
&lt;/h2&gt;

&lt;p&gt;Writing the dictionary section through the generator was the first time anyone read the old manifest fields closely enough to print from them. Two findings came out of it, both in the library's changelog.&lt;/p&gt;

&lt;p&gt;The manifest had fields for a migration's enum type and its values. They were declared - you could write them, and nothing complained - but the generator never printed them. A field that is accepted and ignored is worse than a missing field: it tells the author the job is done.&lt;/p&gt;

&lt;p&gt;And the drift check in a service made from the template - the check that compares the manifest with what is printed - always refused. Every run, every service. A check that always says no gets ignored, and an ignored check is no check at all.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Faggo2ggdox6cfu55qxia.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Faggo2ggdox6cfu55qxia.png" alt="Columns: fields never printed 2, a check that always refused 1; Miso, angry, says declared is not done; a pill reads found and fixed" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuf0e0pj12yri2hfc6gl7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuf0e0pj12yri2hfc6gl7.png" alt="Before and after: by hand - Go code, lookup, checks, tree, per kind; silent, declared fields not printed - and one line - 0 lines of Go per new kind; 5 gates, allocation ceilings on lookups" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr3d7nu6xqfpkhmod4api.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr3d7nu6xqfpkhmod4api.png" alt="An animation: a new line in the manifest, lizard; the generator prints it; the service has a table and lookups ready" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What went wrong
&lt;/h2&gt;

&lt;p&gt;Both findings are the same failure in two costumes: something declared looked done. Fields accepted by the manifest looked like they worked, because nothing rejected them. A drift check existed, so drift looked guarded - except it rejected everything, so everyone learned to ignore it. Neither was found by looking for it. Both were found because a new, small feature had to walk through the same code honestly.&lt;/p&gt;

&lt;p&gt;The lesson I keep from it: every declaration needs a reader that proves it is used. A field that is declared must be printed, or rejected. A check must be seen to pass on a correct input before its "no" means anything.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhdr12qpyh7m756xfm3k7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhdr12qpyh7m756xfm3k7.png" alt="Service tiles with faces: the collector, identity, project data and tokens are happy; the generator proud; the drift check happy; a hand-made cage bored; the register happy; a pill reads built" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I do not claim
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Not that every closed set in every service has moved to the manifest. Five services use the package.&lt;/li&gt;
&lt;li&gt;Not how long the two blank fields were blank. The changelog records the find, not the start.&lt;/li&gt;
&lt;li&gt;Not measured numbers for the gates here. They are ceilings that fail a test when crossed.&lt;/li&gt;
&lt;li&gt;Not the exact manifest format. The form above shows the shape.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What of this is method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A new kind is data, not code.&lt;/strong&gt; One line in the manifest; the library does the rest.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Declared is not done.&lt;/strong&gt; A field is printed or rejected; a check is seen to pass before its "no" counts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Small features walk old code honestly.&lt;/strong&gt; That is where blank pages are found.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Zoo keeping, built in - Part 7.&lt;/strong&gt; Next: &lt;em&gt;No Night Watchman For Partitions&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;your closed sets live in code&lt;/strong&gt;, how many cages did you weld last year? If &lt;strong&gt;your manifests accept fields&lt;/strong&gt;, how do you know each one is read? If &lt;strong&gt;you have a check that always fails&lt;/strong&gt;, who still looks at it? What blank page is waiting in your register?&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Thirteen Routines, One Keeper</title>
      <dc:creator>Anton Brilliantov</dc:creator>
      <pubDate>Sun, 22 Nov 2026 06:18:46 +0000</pubDate>
      <link>https://dev.to/anton_brilliantov/thirteen-routines-one-keeper-59le</link>
      <guid>https://dev.to/anton_brilliantov/thirteen-routines-one-keeper-59le</guid>
      <description>&lt;p&gt;&lt;em&gt;Every pen in the zoo is fed by the same routine; the pen only carries a name tag. Thirteen routines of an entity are written once in the library, and a service binds names and keys to them.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;👋 Hi, I'm Anton - a software engineer. These days I work on a platform: contracts, generated code, data paths and the tooling around them. Running notes live on my GitHub: &lt;strong&gt;&lt;a href="https://github.com/brilliant-almazov" rel="noopener noreferrer"&gt;github.com/brilliant-almazov&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The thirteen routines are built into the shared library as one runtime; four services import it so far. Everything below describes the runtime and its shape; I did not count how much copied code it replaced.&lt;/p&gt;

&lt;p&gt;This is part 6 of the series on what a shared platform does for every service, told as a zoo. Maybe you already do it better, maybe you'd do it another way - this is how it is going, and where it stops.&lt;/p&gt;




&lt;h2&gt;
  
  
  In real life
&lt;/h2&gt;

&lt;p&gt;Nora carries a bag of rule books. One per pen. "Rules for pen seven, version thirteen..." Every book says almost the same thing - when to feed, how to count, what to do when the bowl is empty - and every book is a little different, because each was copied from the previous one and then fixed in its own way.&lt;/p&gt;

&lt;p&gt;Pip takes the bag away. "One book. Every pen." Nora's answer is the real joy of the change: "Finally! Light bag."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flds9n4rg5wlrlcrtd8y0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flds9n4rg5wlrlcrtd8y0.png" alt="A four-panel comic: Nora with a pile of rule books, version thirteen; Pip says one book, every pen, and Nora says finally, light bag; Miso next to its name tag says my part is just the tag; Pickle fixes a typo in the book and Pip says every pen got it" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What stays at each pen is a name tag. Miso's tag says "MISO, table: cats", and that is Miso's whole part in the routine. And when Pickle finds a typo in the book and fixes it, Pip delivers the punchline: every pen got the fix, at once, because there is only one book.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thirteen things every entity does
&lt;/h2&gt;

&lt;p&gt;Look at enough services and the same thirteen things show up for almost every entity. Read one by id, read a list, check that one exists, count, read many by ids. Create, find-or-create, update, upsert, soft-delete. Consume a message once, recount the table through the bus, answer a gRPC method.&lt;/p&gt;

&lt;p&gt;The library's scenario runtime holds the logic of each of those thirteen exactly once, as a generic. The file of an entity in a service is a thin binding: which table, which key, which routines this entity uses. The library's description says it in one line - the logic of each scenario lives here once, the entity file in a service is a thin binding.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6w6134lkwhqdu6yymzvc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6w6134lkwhqdu6yymzvc.png" alt="A waffle of thirteen cells in three colours: five read routines, five write routines, three bus and job routines; Pip says thirteen, written once; a pill reads built" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Kind&lt;/th&gt;
&lt;th&gt;Routines&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;read&lt;/td&gt;
&lt;td&gt;by id, list, exists, count, by ids&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;write&lt;/td&gt;
&lt;td&gt;create, find-or-create, update, upsert, soft delete&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;bus and jobs&lt;/td&gt;
&lt;td&gt;consume once, backfill through the bus, a gRPC method&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Two of these routines already had parts of their own in this series: consume-once (&lt;em&gt;One Ticket, Punched Once&lt;/em&gt;) and the backfill (&lt;em&gt;Feeding By Sectors&lt;/em&gt;). The other eleven are the same idea, smaller.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvvb1f1pbdmtwgdtbbz39.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvvb1f1pbdmtwgdtbbz39.png" alt="Three tiles with faces: a thin binding, happy; the generic, proud; the database, happy; labels read names and keys, one SQL shape; pills read built, and used by a few services" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A name tag, and the routine it borrows
&lt;/h2&gt;

&lt;p&gt;What a binding carries, as a form - the names are illustrative, the shape is the point:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# an entity in a service - a thin binding
&lt;/span&gt;&lt;span class="na"&gt;entity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;name&amp;gt;&lt;/span&gt;
&lt;span class="na"&gt;table&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;schema.table&amp;gt;&lt;/span&gt;
&lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;id&lt;/span&gt;
&lt;span class="na"&gt;scenarios&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;byid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;create&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;update&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;softdelete&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And what a routine does with it. Soft delete, for example, is one statement the generic writes for every entity that asks for it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;table&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;mark&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;TRUE&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;key&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$1&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;mark&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;TRUE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;-- zero rows -&amp;gt; a probe: is the row missing, or already deleted?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3qbq6rxoekwsvny1oesp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3qbq6rxoekwsvny1oesp.png" alt="A dark card: the binding form - entity, table, key, scenarios - and the soft-delete statement; the UPDATE line is highlighted; a pill reads built" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That one statement shows why a routine is worth writing once. "Delete" sounds trivial until you ask what zero updated rows mean. The row may not exist - that is a not-found for the caller. The row may already be deleted - that is fine, deleting twice is the same as deleting once. A hand-written delete in each service answers that question each time, slightly differently, and some forget to ask it. The generic asks it once, with a probe after zero rows, for every entity.&lt;/p&gt;

&lt;p&gt;So the list of what a binding does not carry is longer than the binding itself:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;its own SQL for any of the thirteen routines;&lt;/li&gt;
&lt;li&gt;its own answer to "zero rows" after a write;&lt;/li&gt;
&lt;li&gt;its own transaction rules for consuming a message or a backfill window;&lt;/li&gt;
&lt;li&gt;its own copy of a fix someone made elsewhere.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  One fix, every pen
&lt;/h2&gt;

&lt;p&gt;The benefit people notice first is less code. The benefit that matters is the fix. When a routine is wrong, it is wrong in one place, and the fix reaches every service that binds to it with the next version of the library - not "every service whose author remembers to copy the fix".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe2aeqbw7ut2l1p2n1du8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe2aeqbw7ut2l1p2n1du8.png" alt="An animation: a bug in the routine makes the generic and three services worried; the generic is fixed once and turns proud; services A, B and C turn happy one by one; a pill reads every pen has it" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr03rs5vr1r5b35lc685y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr03rs5vr1r5b35lc685y.png" alt="Before and after: copies - 13 times N, the same logic per service; drift, one copy fixed, others not - and one keeper - 13 generics written once; thin, a binding per entity" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Who uses it
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fle248oy6211ekncx3um3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fle248oy6211ekncx3um3.png" alt="Columns: files about 120, commits since October about 15, services 4; Miso, bored, says only four use it yet; pills read counted, rounded, and used by a few services" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The runtime is young and still moving - around fifteen commits since the start of October and around a hundred and twenty files. Four services import it: the identity service, the token service and two more. The rest of the zoo still feeds its pens the older way, and that is the honest size of this part: one book, a handful of pens using it, more to move.&lt;/p&gt;

&lt;h2&gt;
  
  
  What went wrong
&lt;/h2&gt;

&lt;p&gt;The reason for this runtime is the oldest failure in any codebase with many services: the same logic copied, then fixed in some copies and not in others. Thirteen routines times every entity of every service is a lot of copies, and a soft delete that treats "already deleted" as an error in one service and as success in another would be exactly the kind of difference nobody finds until a caller trips on it.&lt;/p&gt;

&lt;p&gt;The second lesson is in the binding. A binding that grows logic - a special case here, an extra query there - is the first page of a new rule book. The binding stays a name tag on purpose; when an entity needs something truly its own, that is written as its own code, not smuggled into the tag.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgakt5ucbms11ez2kpy8t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgakt5ucbms11ez2kpy8t.png" alt="Service tiles with faces: identity, tokens, project data and processing are happy; the generic proud; a copy by hand bored; a new pen happy; the reviewer happy; pills read built, and used by a few services" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I do not claim
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Not that every service uses the runtime. Four do.&lt;/li&gt;
&lt;li&gt;Not how many lines of copied code it replaced. I did not count.&lt;/li&gt;
&lt;li&gt;Not that thirteen routines cover every entity's needs. They cover the common thirteen.&lt;/li&gt;
&lt;li&gt;Not the exact binding format. The forms above show the shape.&lt;/li&gt;
&lt;li&gt;Not that the runtime is finished. It is young and still changing.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What of this is method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Write a routine once, bind it many times.&lt;/strong&gt; The service carries a name tag, not a rule book.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ask the awkward question once.&lt;/strong&gt; Zero rows after a delete is answered in the generic, for everyone.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the binding thin on purpose.&lt;/strong&gt; Logic in a tag is the first page of a new copy.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Zoo keeping, built in - Part 6.&lt;/strong&gt; Next: &lt;em&gt;A New Species Is One Line In The Register&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;your services share generic data routines&lt;/strong&gt;, where does the binding stop and the code start? If &lt;strong&gt;you copy CRUD between services&lt;/strong&gt;, how do you find the copy that missed a fix? If &lt;strong&gt;you tried generics for this&lt;/strong&gt;, which of the thirteen was hardest to make generic? How many rule books does your keeper carry?&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Feeding By Sectors</title>
      <dc:creator>Anton Brilliantov</dc:creator>
      <pubDate>Fri, 20 Nov 2026 05:32:17 +0000</pubDate>
      <link>https://dev.to/anton_brilliantov/feeding-by-sectors-3ack</link>
      <guid>https://dev.to/anton_brilliantov/feeding-by-sectors-3ack</guid>
      <description>&lt;p&gt;&lt;em&gt;A recount of a big table goes out the way food goes out in a zoo: by sectors, along the paths, one cart per sector - not one walker carrying everything through the night.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;👋 Hi, I'm Anton - a software engineer. These days I work on a platform: contracts, generated code, data paths and the tooling around them. Running notes live on my GitHub: &lt;strong&gt;&lt;a href="https://github.com/brilliant-almazov" rel="noopener noreferrer"&gt;github.com/brilliant-almazov&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The backfill routine is built into the shared library as one of its thirteen generic routines; a few services use that runtime. The example of twenty windows below is an example cut, not a measurement of any real recount.&lt;/p&gt;

&lt;p&gt;This is part 5 of the series on what a shared platform does for every service, told as a zoo. Maybe you already do it better, maybe you'd do it another way - this is how it is going, and where it stops.&lt;/p&gt;




&lt;h2&gt;
  
  
  In real life
&lt;/h2&gt;

&lt;p&gt;Feeding time. Nora brings all the food for the whole zoo in one go and, to save time, tips it into the nearest pen. The nearest pen happens to be Ember's. Ember, a dragon, looks at the mountain and says the only thing a dragon can say: "Mine now. All of it." The rest of the zoo is hungry.&lt;/p&gt;

&lt;p&gt;The next idea is the night walker. Biscuit takes a wheelbarrow and walks the whole zoo, pen by pen, all night: "Pen one... pen two... pen nine thousand..." It works, slowly, alone, and nobody can see how far he got or help him when he gets tired.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fob6df7kl7lqykf8nb3n0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fob6df7kl7lqykf8nb3n0.png" alt="A four-panel comic: Nora sees the dragon sitting on all the food, the dragon says mine now; Biscuit walks pens under a lamppost all night; Pip says first pen, last pen, one note per sector; Biscuit takes pens 1 to 100 and Pickle takes 100 to 200" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then Pip does what keepers in real zoos do. Look at the first pen and the last pen. Cut the zoo into sectors. Write one note per sector, put the notes on the paths, and let whoever is free take a note: Biscuit takes pens one to a hundred, Pickle takes a hundred to two hundred. Nobody carries everything, everybody can see which notes are still waiting, and a dropped note is just picked up again.&lt;/p&gt;

&lt;h2&gt;
  
  
  A goroutine that walks the table
&lt;/h2&gt;

&lt;p&gt;Every service eventually needs to recount something: fill a new column for old rows, rebuild a derived value, re-publish what changed. The tempting shape is a background goroutine that starts with the service, scans the table from top to bottom, and does the work as it goes.&lt;/p&gt;

&lt;p&gt;That shape has all of Biscuit's problems. It is one walker per replica, or one walker with a lock. Nobody sees how far it got. If the process restarts, the walk restarts or needs its own bookkeeping. And it runs outside the one thing the platform already has for "work that happens later": the bus. In our platform that is not a style preference. Any asynchronous processing - a backfill, a recount, a re-publish - goes through the bus, producer to consumer; a goroutine that scans a table on its own is not an option at all.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fznl4r3703mjtqd12oraq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fznl4r3703mjtqd12oraq.png" alt="Three tiles with faces: the producer, proud; the bus, happy; a consumer, happy; labels read a window per message and one window, one transaction; pills read built, and used by a few services" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  One query, then windows on the bus
&lt;/h2&gt;

&lt;p&gt;The backfill routine of the library does it in two halves.&lt;/p&gt;

&lt;p&gt;The producer asks the table one question: the smallest and the largest key. It cuts that range into windows &lt;code&gt;[from, to)&lt;/code&gt; and publishes each window as a message. The consumer takes a window and does the work for the rows in it, in one transaction. As a form - names illustrative:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;producer:  SELECT min(id), max(id) FROM &amp;lt;table&amp;gt;;      -- one query
           publish { from: 1,      to: 100001 }
           publish { from: 100001, to: 200001 }
           publish ...                                -- one window per message
consumer:  BEGIN; &amp;lt;work on rows where from &amp;lt;= id &amp;lt; to&amp;gt;; COMMIT;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0a137zorf2ts04vxcuge.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0a137zorf2ts04vxcuge.png" alt="A dark card with the backfill form: the producer's min and max query, window messages, and the consumer's one transaction per window; the min and max line is highlighted; a pill reads built" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Everything the night walker could not do now comes from the bus. Progress is the number of window messages still waiting. A failed window is redelivered alone, without redoing the windows before it. More consumers means more sectors fed at once. And the producer does not scan anything: it reads two numbers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqzifxgelta9ep0eep7b6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqzifxgelta9ep0eep7b6.png" alt="Bars: queries to plan the cut, min and max, 1; transactions per window 1; goroutines scanning the table 0; Biscuit says no more night walks; a pill reads built" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Question&lt;/th&gt;
&lt;th&gt;Night walker&lt;/th&gt;
&lt;th&gt;Windows on the bus&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;how far did it get?&lt;/td&gt;
&lt;td&gt;inside one process's memory&lt;/td&gt;
&lt;td&gt;messages done vs waiting&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;what if a step fails?&lt;/td&gt;
&lt;td&gt;the walker decides, or stops&lt;/td&gt;
&lt;td&gt;that window is redelivered&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;can two help?&lt;/td&gt;
&lt;td&gt;only with extra locking&lt;/td&gt;
&lt;td&gt;any free consumer takes a window&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;what does planning cost?&lt;/td&gt;
&lt;td&gt;a scan of the whole table&lt;/td&gt;
&lt;td&gt;one query for min and max&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  What a window asks of the work
&lt;/h2&gt;

&lt;p&gt;Moving a recount onto the bus changes one thing about the work itself: a window can arrive more than once. The bus delivers at least once, and a window whose consumer died after the commit but before the acknowledgement will come back. So the work for a window has to be safe to repeat.&lt;/p&gt;

&lt;p&gt;For most recounts that comes for free, because they set a value rather than add to it: "fill the new column from the old ones" gives the same row the second time. For the few that add or send, the previous part of this series applies unchanged - the once-per-message routine punches the window's message id in the same transaction as the work.&lt;/p&gt;

&lt;p&gt;There is also a question of size. A window is one transaction, and a transaction holds its locks until it commits. Wide windows mean fewer messages and longer locks; narrow windows mean more messages and shorter locks. How wide a window should be is a choice per table, and I do not claim a right number.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Window width&lt;/th&gt;
&lt;th&gt;Messages on the bus&lt;/th&gt;
&lt;th&gt;Locks held per transaction&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;wide&lt;/td&gt;
&lt;td&gt;few&lt;/td&gt;
&lt;td&gt;long&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;narrow&lt;/td&gt;
&lt;td&gt;many&lt;/td&gt;
&lt;td&gt;short&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  What twenty windows look like
&lt;/h2&gt;

&lt;p&gt;To show the idea, an example: a key range cut into twenty windows, some done, some in flight, some still on the bus. The numbers are an example cut, not a run.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2cq8dynqa1khxji0ewv4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2cq8dynqa1khxji0ewv4.png" alt="A waffle of twenty cells: twelve done, three in flight, five waiting on the bus; Pickle says each one done on its own; a pill reads an example, not a measurement" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4utbdryprwx388bdbn8v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4utbdryprwx388bdbn8v.png" alt="An animation: the producer reads min and max, publishes window 1 to 100001 on the bus, a consumer finishes it in one transaction, then the next window travels; a pill reads no walker at night" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fguo12eq99m1k93ege48g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fguo12eq99m1k93ege48g.png" alt="Before and after: a walker - 1 walker, the whole table by itself; hidden, not on the bus - and windows - N windows from-to on the bus; 1 transaction per window, any consumer" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What went wrong
&lt;/h2&gt;

&lt;p&gt;The thing this routine closes is a habit: the background goroutine that scans a table is the first thing anyone writes for a recount, because it is the shortest code. It is also the one shape that hides its progress, fights its own replicas and lives outside the bus. The rule that asynchronous work goes through the bus came first; the routine is what makes following that rule shorter than breaking it.&lt;/p&gt;

&lt;p&gt;One more honest note: windows over a key range assume the keys are spread evenly enough that windows of equal width carry similar work. A range with a dense patch makes some windows heavy. The routine cuts by key, not by row count.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1gs6kslrha0iokmuyru8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1gs6kslrha0iokmuyru8.png" alt="Service tiles with faces: the producer, the bus and two consumers are happy; the table happy; a night walker bored; a failed window worried; the retry happy; a pill reads built" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I do not claim
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Not a measured recount. The twenty windows are an example.&lt;/li&gt;
&lt;li&gt;Not that windows of equal width carry equal work. They are cut by key.&lt;/li&gt;
&lt;li&gt;Not that every recount in every service uses the routine. A few services use the runtime.&lt;/li&gt;
&lt;li&gt;Not the exact message shape. The form above shows the idea.&lt;/li&gt;
&lt;li&gt;Not a right window width. It is a choice per table.&lt;/li&gt;
&lt;li&gt;Not that the work in a window is safe to repeat by itself. That is the work's job, or the once-per-message routine's.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What of this is method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Plan with one query, work through the bus.&lt;/strong&gt; Min and max, then windows as messages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One window, one transaction.&lt;/strong&gt; A failure costs one window, not the whole walk.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make the right path the short one.&lt;/strong&gt; The rule says "through the bus"; the routine makes it less code than a goroutine.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Zoo keeping, built in - Part 5.&lt;/strong&gt; Next: &lt;em&gt;Thirteen Routines, One Keeper&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;you recount big tables&lt;/strong&gt;, does the work run as a walker or as messages? If &lt;strong&gt;you cut by key range&lt;/strong&gt;, what do you do with the dense patch? If &lt;strong&gt;a backfill failed halfway&lt;/strong&gt;, how did you know where to restart? Who walks your zoo at night?&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>softwareengineering</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>One Ticket, Punched Once</title>
      <dc:creator>Anton Brilliantov</dc:creator>
      <pubDate>Thu, 19 Nov 2026 15:20:44 +0000</pubDate>
      <link>https://dev.to/anton_brilliantov/one-ticket-punched-once-20f8</link>
      <guid>https://dev.to/anton_brilliantov/one-ticket-punched-once-20f8</guid>
      <description>&lt;p&gt;&lt;em&gt;The broker may bring the same message three times. The consumer punches its id and does the work in one transaction, so the second and third visits find the ticket already punched.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;👋 Hi, I'm Anton - a software engineer. These days I work on a platform: contracts, generated code, data paths and the tooling around them. Running notes live on my GitHub: &lt;strong&gt;&lt;a href="https://github.com/brilliant-almazov" rel="noopener noreferrer"&gt;github.com/brilliant-almazov&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The once-per-message consumer is built into the shared library as one of its thirteen generic routines, and a handful of services use that runtime. I describe the mechanism and its shape; I did not measure how many duplicates it has caught.&lt;/p&gt;

&lt;p&gt;This is part 4 of the series on what a shared platform does for every service, told as a zoo. Maybe you already do it better, maybe you'd do it another way - this is how it is going, and where it stops.&lt;/p&gt;




&lt;h2&gt;
  
  
  In real life
&lt;/h2&gt;

&lt;p&gt;The zoo has a turnstile, and Nora stands next to it with a hole punch. Every visitor has a ticket; Nora punches it, the turnstile turns, the visitor goes in. Simple.&lt;/p&gt;

&lt;p&gt;Then Biscuit arrives. Biscuit is the zoo's courier dog, and he is very, very reliable - so reliable that when he is not sure a ticket got through, he brings it again. "Me again! Same ticket!" It is the third time this hour.&lt;/p&gt;

&lt;p&gt;The first time, Nora punches the ticket and lets Biscuit in: "Punched. Welcome!" The second time, she looks at the ticket and sees the hole: "Already punched." Biscuit is a little offended - "But I ran so fast!" - but the zoo does not let one ticket in twice.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe20ip3bb3wwxui0wvysw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe20ip3bb3wwxui0wvysw.png" alt="A four-panel comic: Biscuit at the turnstile with the same ticket for the third time this hour; Nora punches it the first time and Biscuit is delighted; the next time Nora says already punched and Biscuit says but I ran so fast; Pip says punch and open in one move, Pickle asks never just one of them" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last panel is the part that matters. Pip insists that the punch and the turnstile happen in one move. If Nora punched a ticket and the turnstile jammed, the visitor would be locked out with a used ticket. If the turnstile turned and Nora forgot to punch, the same ticket would come in again tomorrow. Never one without the other.&lt;/p&gt;

&lt;h2&gt;
  
  
  At least once is a promise about delivery, not about work
&lt;/h2&gt;

&lt;p&gt;Message brokers promise to deliver at least once. That is a good promise: a message is not lost when a consumer dies halfway. It also means that a consumer will, sooner or later, see the same message twice - after a redelivery, a reconnect, a restart in the wrong moment. If the work is "add a record" or "send a notice", twice is a bug.&lt;/p&gt;

&lt;p&gt;Each consumer used to guard against that on its own, or not at all. The shared library now has a generic consumer routine that does it the same way everywhere: receive a message once per &lt;code&gt;x-message-id&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fngbv5vllqr7ww356t4rk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fngbv5vllqr7ww356t4rk.png" alt="Three tiles with faces: the broker, bored; the inbox, proud; the handler, happy; labels read x-message-id and same transaction; pills read built, and used by a few services" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The punch and the entry, in one transaction
&lt;/h2&gt;

&lt;p&gt;The routine keeps a small inbox table of message ids. For each message it inserts the id and, in the same transaction, runs the handler. As a form - the names are illustrative:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;BEGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;inbox&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;CONFLICT&lt;/span&gt; &lt;span class="k"&gt;DO&lt;/span&gt; &lt;span class="k"&gt;NOTHING&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;-- 0 rows: seen before  -&amp;gt; acknowledge, skip the work&lt;/span&gt;
&lt;span class="c1"&gt;-- 1 row : new          -&amp;gt; do the work here, in this transaction&lt;/span&gt;
&lt;span class="k"&gt;COMMIT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;-- the punch and the work land together, or neither does&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foxqxcn0ves0n18kqfdgu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foxqxcn0ves0n18kqfdgu.png" alt="A dark card with the inbox transaction as a form; the insert with ON CONFLICT DO NOTHING is highlighted; a pill reads built" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The order inside the transaction is the whole design. If the handler fails, the transaction rolls back and the id is not stored - the next delivery is treated as new, which is right, because the work did not happen. If the handler succeeds, the id and the work commit together, and every later delivery hits the conflict and is skipped. There is no moment in which the ticket is punched but the visitor is outside, or the visitor is inside with an unpunched ticket.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Delivery&lt;/th&gt;
&lt;th&gt;Inbox insert&lt;/th&gt;
&lt;th&gt;Work&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;first&lt;/td&gt;
&lt;td&gt;1 row&lt;/td&gt;
&lt;td&gt;done, same transaction&lt;/td&gt;
&lt;td&gt;committed together&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;first, handler fails&lt;/td&gt;
&lt;td&gt;rolled back&lt;/td&gt;
&lt;td&gt;not done&lt;/td&gt;
&lt;td&gt;next delivery is new&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;second, same id&lt;/td&gt;
&lt;td&gt;0 rows&lt;/td&gt;
&lt;td&gt;skipped&lt;/td&gt;
&lt;td&gt;acknowledged&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;third, same id&lt;/td&gt;
&lt;td&gt;0 rows&lt;/td&gt;
&lt;td&gt;skipped&lt;/td&gt;
&lt;td&gt;acknowledged&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcvsty9w0f9zbfo9zfu47.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcvsty9w0f9zbfo9zfu47.png" alt="An animation: the broker delivers a message, the inbox punches the new id and the handler does the work; the same id arrives a second and a third time and is skipped at the inbox; a pill reads handled once" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  One of thirteen routines
&lt;/h2&gt;

&lt;p&gt;The once-per-message consumer is not a separate library. It is one of thirteen generic routines in the library's scenario runtime - the next-but-one part of this series is about all thirteen. A service that consumes messages does not write the inbox, the conflict rule or the transaction; it binds its handler to the routine.&lt;/p&gt;

&lt;p&gt;What is left for the service is the part only the service knows. In the shape of the code, with the names shortened:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c1"&gt;// a consumer in a service - a form&lt;/span&gt;
&lt;span class="n"&gt;inbox&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Once&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// the work, inside the routine's transaction&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The handler runs inside the routine's transaction instead of opening its own, which is how the punch and the work end up in one commit. A handler that opened a second connection and wrote there would quietly step outside the turnstile - that is the one rule a service has to keep, and it is the kind of rule a review can see.&lt;/p&gt;

&lt;p&gt;There is a small cost, and it is worth naming. The inbox is a table that grows with every message, and it needs the same care as any growing table. The routine owns the punch; how long used tickets are kept is not part of what I describe here, and I do not claim it is solved.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fheg4w3ybjag8cluts5ez.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fheg4w3ybjag8cluts5ez.png" alt="A waffle of thirteen cells: one teal cell with a check - consume, punched once; twelve indigo cells - the other twelve routines; Pip says one of thirteen, the same for all; a pill reads built" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftme111b95e6r94sdt7hm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftme111b95e6r94sdt7hm.png" alt="Bars: files about 120, commits since October about 15, services importing it 4; Pickle says four services, one punch; a pill reads counted, rounded" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx2137ol5drz0o7g6z6e4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx2137ol5drz0o7g6z6e4.png" alt="Before and after: at least once - 2 effects for one message delivered twice; by hand, each consumer guards itself - and punched once - 1 effect per x-message-id; 1 transaction for the punch and the work" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What went wrong
&lt;/h2&gt;

&lt;p&gt;The failure this routine answers is the quiet kind: duplicates that nobody notices until two notices go out, or a counter is one too high. Every consumer that guarded itself did it slightly differently, and a consumer that did not guard itself did not look any different from the outside - until a redelivery.&lt;/p&gt;

&lt;p&gt;The second lesson is about where the punch lives. A common shortcut is to check "have I seen this id?" in one step and do the work in another. Between the two steps, a second delivery can pass the same check. Inserting the id and doing the work in one transaction removes that gap instead of narrowing it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjpdd5fwuqrlbwrc26iev.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjpdd5fwuqrlbwrc26iev.png" alt="Service tiles with faces: the broker happy, the inbox proud, the handler happy; a repeat bored, the books happy; pills read built, and used by a few services" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I do not claim
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Not exactly-once delivery. The broker still delivers at least once; the work happens once.&lt;/li&gt;
&lt;li&gt;Not that every consumer in every service uses the routine. A few services do.&lt;/li&gt;
&lt;li&gt;Not a count of duplicates caught. I did not measure it.&lt;/li&gt;
&lt;li&gt;Not that this covers effects outside the database transaction. A call to another system inside the handler is still the handler's problem.&lt;/li&gt;
&lt;li&gt;Not the exact names. The SQL and the Go above are forms that show the shape.&lt;/li&gt;
&lt;li&gt;Not a retention rule for the inbox. It grows, and that is a separate decision.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What of this is method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Punch and entry in one transaction.&lt;/strong&gt; The id and the work commit together, or neither.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Accept at least once; make the work once.&lt;/strong&gt; Do not fight the broker's promise.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write the guard once, bind it everywhere.&lt;/strong&gt; A routine in the library, not a habit in each consumer.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Zoo keeping, built in - Part 4.&lt;/strong&gt; Next: &lt;em&gt;Feeding By Sectors&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;your consumers are idempotent&lt;/strong&gt;, where does the punch live - in the same transaction as the work, or next to it? If &lt;strong&gt;you rely on the broker for exactly once&lt;/strong&gt;, what happens on a redelivery after a restart? If &lt;strong&gt;you had a duplicate in production&lt;/strong&gt;, how did you find it? How many times did your last message come through the turnstile?&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>The Error That Escaped Without A Collar</title>
      <dc:creator>Anton Brilliantov</dc:creator>
      <pubDate>Wed, 18 Nov 2026 06:14:26 +0000</pubDate>
      <link>https://dev.to/anton_brilliantov/the-error-that-escaped-without-a-collar-17jc</link>
      <guid>https://dev.to/anton_brilliantov/the-error-that-escaped-without-a-collar-17jc</guid>
      <description>&lt;p&gt;&lt;em&gt;One exit for every error of every transport: a mapped code instead of Unknown, a fixed message instead of internal text, and a panic that becomes Internal instead of taking the process with it.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;👋 Hi, I'm Anton - a software engineer. These days I work on a platform: contracts, generated code, data paths and the tooling around them. Running notes live on my GitHub: &lt;strong&gt;&lt;a href="https://github.com/brilliant-almazov" rel="noopener noreferrer"&gt;github.com/brilliant-almazov&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The exit guard is built into the shared library and is on by default in its gRPC server chain; its tests, benchmarks and leak checks were run as targeted runs with the race detector. How often the old leak happened in production I did not measure, and I do not claim a number.&lt;/p&gt;

&lt;p&gt;This is part 3 of the series on what a shared platform does for every service, told as a zoo. Maybe you already do it better, maybe you'd do it another way - this is how it is going, and where it stops.&lt;/p&gt;




&lt;h2&gt;
  
  
  In real life
&lt;/h2&gt;

&lt;p&gt;Every animal that leaves an enclosure in our zoo wears a collar. The collar says whose animal it is and where it belongs. Keepers put it on at the gate, every time, by hand.&lt;/p&gt;

&lt;p&gt;One morning Nora finds Biscuit, our dog, trotting along the main path with no collar at all. "Whose dog is this?!" Biscuit, very pleased with himself, answers the only thing he can: "Unknown! Woof!"&lt;/p&gt;

&lt;p&gt;It gets worse. A dog without a collar does not know what not to say. Biscuit happily tells every visitor what he saw behind the scenes: "Table seven, row forty-two!" Miso hisses "Shh! Nobody asked you" - but by then the visitors have heard it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3xy9h6l137ny9oorlrn7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3xy9h6l137ny9oorlrn7.png" alt="A four-panel comic: Nora finds Biscuit without a collar and asks whose dog it is, Biscuit says Unknown; Biscuit barks table seven, row forty-two and Miso hushes him; Pip at the gate says nobody leaves without a collar, even Biscuit; Pickle says someone fainted at the gate and Pip says carried out, tag: internal" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The zoo's fix is not "keepers, please remember the collar". The fix is a keeper at the one gate everybody leaves through. Nobody leaves without a collar - even Biscuit. And when somebody faints at the gate, the gate keeper does not panic either: the animal is carried out with a plain tag that says "internal", and the zoo stays open.&lt;/p&gt;

&lt;h2&gt;
  
  
  The mapper you had to remember
&lt;/h2&gt;

&lt;p&gt;In our services, a handler turns a domain error into an answer for the caller. For gRPC that is a status code with a reason; for HTTP a status and a body; for a consumer a decision to drop the message or try again. The library has a builder for exactly that mapping, and for a long time each handler called it itself.&lt;/p&gt;

&lt;p&gt;That is the keeper who has to remember the collar. The library's changelog describes what happened when one did not: the forgotten call handed the caller &lt;code&gt;Unknown&lt;/code&gt; with the internal text of the error, and a panic in a consumer flew into the goroutine of the resource that ran it. Two failures, one cause: the last step of every error was optional.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7o6bcvfnwujb9c77qlps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7o6bcvfnwujb9c77qlps.png" alt="Three tiles with faces: a handler that forgot, angry, sends a raw error to one exit guard, proud, which gives the caller, happy, a coded refusal; a pill reads built, on by default" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  One gate for three transports
&lt;/h2&gt;

&lt;p&gt;The library now has one exit for errors, with three doors on it. In the shape of the code - names shortened, the meaning is what matters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c1"&gt;// one exit for every transport - a form&lt;/span&gt;
&lt;span class="n"&gt;guard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Answer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;        &lt;span class="c1"&gt;// gRPC / HTTP: a mapped status, never raw text&lt;/span&gt;
&lt;span class="n"&gt;guard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Recover&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;         &lt;span class="c1"&gt;// a panic -&amp;gt; Internal, a fixed message, the span marked&lt;/span&gt;
&lt;span class="n"&gt;guard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Settle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;// a consumer: drop the message, or retry it&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fec73jyv0gb1q8oeendv0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fec73jyv0gb1q8oeendv0.png" alt="A dark card with the three calls of the exit guard and the consumer's rule: codes in the drop list, such as InvalidArgument, drop the message, anything else retries; the Recover line is highlighted; pills read built and tested" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt; is the collar. Whatever error a handler returns, it goes through the mapping on the way out, so a forgotten mapper is no longer a leak - the gate maps it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Recover&lt;/strong&gt; is the keeper at the gate when someone faints. A panic in a handler becomes &lt;code&gt;Internal&lt;/code&gt; with a fixed message, the trace span is marked, and the process keeps serving everyone else.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Settle&lt;/strong&gt; is the consumer's door. A message whose error code is in the drop list - by default &lt;code&gt;InvalidArgument&lt;/code&gt; and its neighbours, errors that will not get better by trying again - is dropped; anything else is retried. Before, that decision was another thing each consumer had to remember.&lt;/p&gt;

&lt;p&gt;The guard is on by default in the chain of the library's gRPC server. A service does not import it to get it - which is why the count of services that import it directly is zero, and the count that run it is every service on that server.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Door&lt;/th&gt;
&lt;th&gt;Before&lt;/th&gt;
&lt;th&gt;After&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;gRPC&lt;/td&gt;
&lt;td&gt;the handler maps, or the caller gets &lt;code&gt;Unknown&lt;/code&gt; with internal text&lt;/td&gt;
&lt;td&gt;the gate maps every error&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;HTTP&lt;/td&gt;
&lt;td&gt;the same, by hand per handler&lt;/td&gt;
&lt;td&gt;the same gate, the same mapping&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;consumer&lt;/td&gt;
&lt;td&gt;a panic flies into the resource goroutine&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;Internal&lt;/code&gt;, span marked, process alive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;consumer decision&lt;/td&gt;
&lt;td&gt;each consumer decides drop or retry&lt;/td&gt;
&lt;td&gt;one rule: drop codes are dropped, the rest retried&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  What the caller sees
&lt;/h2&gt;

&lt;p&gt;The difference is easiest to see from the outside. The same failure, as a caller received it before and after the gate - shapes only, with the internal text replaced by a placeholder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;before:  code = Unknown
         message = "&amp;lt;internal error text: query, table, row&amp;gt;"

after:   code = &amp;lt;the mapped code, e.g. NotFound / FailedPrecondition&amp;gt;
         reason = &amp;lt;a reason code the caller can branch on&amp;gt;

panic:   code = Internal
         message = "&amp;lt;a fixed panic message&amp;gt;"     # the span is marked, the process lives
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The caller of the first answer can do nothing but log it and give up, and the text in it belongs to the service, not to the caller. The caller of the second can branch on the reason. The third answer is the important quiet one: a single broken request no longer takes the process down with it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe1jjz8pu7pq59hmezzej.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe1jjz8pu7pq59hmezzej.png" alt="Before and after: each handler maps - Unknown with the internal text; a panic in the resource goroutine - and one exit - a code mapped at the gate; Internal, the process keeps running" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tested at the gate
&lt;/h2&gt;

&lt;p&gt;A gate is only worth something if it holds under load and under races. The tests, benchmarks and goroutine-leak checks for the guard were written in a pass over several prompt sets and run as targeted runs with the race detector.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F92pxhc6zk5q14xe79ux1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F92pxhc6zk5q14xe79ux1.png" alt="Columns: benchmark cases - the guard 7, the gRPC server 3, the HTTP edge 2; Pickle says: and all of it under -race; a pill reads tested, targeted runs with -race" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1yn32qd5xtzxhcundtsh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1yn32qd5xtzxhcundtsh.png" alt="Bars: files about 25, commits since October 5, services importing it directly 0; Miso says: I never call it, it's in my server; a pill reads on by default in the server chain" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdl20mm888kb5lojs3r13.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdl20mm888kb5lojs3r13.png" alt="An animation: a handler sends a raw error without a mapper, the exit guard maps it, the caller gets a code, and no internal text leaves" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What went wrong
&lt;/h2&gt;

&lt;p&gt;Two real leaks, both from the same design: the last step of an error was the handler's job. A forgotten mapper sent &lt;code&gt;Unknown&lt;/code&gt; with internal text to a caller - the dog without a collar, telling visitors about table seven. A panic in a consumer escaped into the goroutine of the resource that ran it - the animal fainting in the middle of the path instead of at the gate.&lt;/p&gt;

&lt;p&gt;The lesson is the one this whole series keeps repeating. A rule that every handler must remember is not a rule; it is a hope. The fix was not a review checklist or a linter warning but a gate in the one place every error passes, on by default.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq0i763nsut77xuey0wll.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq0i763nsut77xuey0wll.png" alt="Service tiles with faces: the gRPC handler, the HTTP handler and the consumer are happy; the exit guard is proud, the caller happy, a panic worried; pills read built, and tested with -race" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I do not claim
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Not how often the leak hit callers before the gate. I did not count it.&lt;/li&gt;
&lt;li&gt;Not that every service already runs the newest guard. It is on by default for services on the library's server.&lt;/li&gt;
&lt;li&gt;Not that the drop list fits every consumer. It is the default.&lt;/li&gt;
&lt;li&gt;Not a full load test. The guard has benchmarks and race runs, not a production measurement.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What of this is method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The last step of every error lives at one gate.&lt;/strong&gt; Not in each handler.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A panic is an answer, not an exit.&lt;/strong&gt; Internal, a fixed message, the span marked, the process alive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Drop or retry is decided once.&lt;/strong&gt; By the error's code, in one place.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Zoo keeping, built in - Part 3.&lt;/strong&gt; Next: &lt;em&gt;One Ticket, Punched Once&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;your handlers map their own errors&lt;/strong&gt;, how would you find the one that forgot? If &lt;strong&gt;you recover panics&lt;/strong&gt;, where - per handler, or at one gate? If &lt;strong&gt;your consumers decide drop or retry&lt;/strong&gt;, is that decision written once or many times? What did your last error without a collar say to a caller?&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>A Viewing Window, Not A Key To The Cage</title>
      <dc:creator>Anton Brilliantov</dc:creator>
      <pubDate>Tue, 17 Nov 2026 07:58:21 +0000</pubDate>
      <link>https://dev.to/anton_brilliantov/a-viewing-window-not-a-key-to-the-cage-3i0e</link>
      <guid>https://dev.to/anton_brilliantov/a-viewing-window-not-a-key-to-the-cage-3i0e</guid>
      <description>&lt;p&gt;&lt;em&gt;An admin screen may look at any table of any service - through glass. Read only, a timeout, caps, a log line, one at a time, and the glass is shut until someone opens it on purpose.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;👋 Hi, I'm Anton - a software engineer. These days I work on a platform: contracts, generated code, data paths and the tooling around them. Running notes live on my GitHub: &lt;strong&gt;&lt;a href="https://github.com/brilliant-almazov" rel="noopener noreferrer"&gt;github.com/brilliant-almazov&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The guarded query is built into the shared library and is off by default. No service imports it directly yet; everything below describes what is built, not how much it is used.&lt;/p&gt;

&lt;p&gt;This is part 2 of the series on what a shared platform does for every service, told as a zoo. Maybe you already do it better, maybe you'd do it another way - this is how it is going, and where it stops.&lt;/p&gt;




&lt;h2&gt;
  
  
  In real life
&lt;/h2&gt;

&lt;p&gt;Ember, the small dragon of our zoo, guards the gold. That is what dragons do, and in our zoo the gold is the data: every resident keeps its own pile in its own cave, and nobody else is supposed to touch it.&lt;/p&gt;

&lt;p&gt;Nora, the keeper, wants to count the coins. Not take them - just count. "Give me a key, I'll just count." Ember's answer is the answer every database owner has given: "Nobody touches my gold." And Ember is right. A key does not know the difference between counting and carrying.&lt;/p&gt;

&lt;p&gt;So the zoo puts a viewing window into the cave wall. Pickle presses a nose to the glass and is delighted: "I can see every coin!" Biscuit tries to pass a bone through - "can I feed it?" - and learns what glass is for: look only. And when too many faces press against the window at once, Pip does the one thing that keeps the dragon calm: "Full. No waiting. Come back later."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyufg47khb0j7c4gh8zpg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyufg47khb0j7c4gh8zpg.png" alt="A four-panel comic: Nora asks the dragon on its gold for a key to count, the dragon refuses; Pickle at a big window sees every coin; Biscuit asks to pass a bone through the glass and Ember says look only; Miso wants to wait at a full window and Pip says no waiting, come back later" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That is the whole part in four panels. The admin screen can look at any table - through the service, through glass, one look at a time.&lt;/p&gt;

&lt;h2&gt;
  
  
  The key nobody should have
&lt;/h2&gt;

&lt;p&gt;Admin screens want data. A list of records, a count, a join to check one thing on a Tuesday. The easy answer is a database address per service in the admin's configuration, and from then on the admin holds a key to every cave. A key does not know the difference between a SELECT and an UPDATE, does not know when to stop, and leaves no trace in the service that owns the data.&lt;/p&gt;

&lt;p&gt;The library's answer is a guarded query that lives inside the service. The admin screen asks the service; the service runs the query on its own terms; the database address never leaves the resident. The line in the library's description says it plainly: the admin gets the schema and any selection through the service, not through a direct database address.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiin3yh8hzkxeembo66qd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiin3yh8hzkxeembo66qd.png" alt="Three tiles with faces: an admin screen, the service proud in the middle, its small pool happy; labels read no address and read only; pills read built, and off by default" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Six panes of glass
&lt;/h2&gt;

&lt;p&gt;Every query that comes through the window passes the same guards.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Faouqdwnf4jipgccdvnf0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Faouqdwnf4jipgccdvnf0.png" alt="A waffle of eight cells: six green cells with checks - six guards on every query; one amber cell - one switch, off by default; one red cell with a cross - one refusal, busy, at once; Ember says look all you like; a pill reads built" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Guard&lt;/th&gt;
&lt;th&gt;What it stops&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;a read-only transaction&lt;/td&gt;
&lt;td&gt;any write, however it is spelled&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;a statement timeout&lt;/td&gt;
&lt;td&gt;a query that would run all afternoon&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;a row cap&lt;/td&gt;
&lt;td&gt;a result that would not fit on any screen&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;a byte cap&lt;/td&gt;
&lt;td&gt;a few rows with huge values&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;its own small pool, or a replica&lt;/td&gt;
&lt;td&gt;the window starving the service's real work&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;one log line per query&lt;/td&gt;
&lt;td&gt;a look nobody can account for later&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The settings, as a form - the names here are illustrative, the shape is what the library takes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;data_query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;enabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;              &lt;span class="c1"&gt;# off by default
&lt;/span&gt;  &lt;span class="na"&gt;concurrency&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;n&amp;gt;&lt;/span&gt;            &lt;span class="c1"&gt;# over it: busy at once, no waiting
&lt;/span&gt;  &lt;span class="na"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;small own pool | replica&amp;gt;&lt;/span&gt;
  &lt;span class="na"&gt;statement_timeout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;duration&amp;gt;&lt;/span&gt;
  &lt;span class="na"&gt;max_rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;n&amp;gt;&lt;/span&gt;
  &lt;span class="na"&gt;max_bytes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;n&amp;gt;&lt;/span&gt;
&lt;span class="c1"&gt;# every query: a read-only transaction, the timeout, one log line
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkrhv52hxookheuu6py39.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkrhv52hxookheuu6py39.png" alt="A dark card with the window's settings as a form; the line enabled false, off by default, is highlighted; pills read built, and off by default" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Two choices in that form matter more than the rest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Off by default.&lt;/strong&gt; The window is a wall until someone turns it into glass on purpose, for one service, with a switch in that service's environment. A new service does not get an open window because it was born.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Busy means no.&lt;/strong&gt; When the number of running queries reaches the concurrency limit, the next one is refused at once - not queued, not made to wait. A queue in front of a database is a queue that grows exactly when the database is slow. Refusing at once keeps the cost of a look bounded and moves the waiting to the person who can decide whether to come back.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz52moqpwb7i3zmuj0ay4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz52moqpwb7i3zmuj0ay4.png" alt="An animation: an admin screen sends a read query to the service, which sets read only and the timeout and reads rows under the cap from the small pool; then a second query arrives while the first is running, the service turns angry and refuses it at once" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A key versus a window
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffk0k3i5by5pag7vxynl4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffk0k3i5by5pag7vxynl4.png" alt="Before and after: a key - everything, any table, any statement; unseen, no line in any log - and a window - read only, with a timeout and caps; logged, one line per query" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The difference is not only safety. A key spreads knowledge of a service's database into every tool that holds it: the address, the credentials, the shape of the tables. A window keeps that knowledge in the service, which already describes its own tables through the sign from the previous part. The admin screen asks "what do you have" and "show me" - and both answers come from the resident.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who looks through it yet
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh5nf394izkunr6ulzks6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh5nf394izkunr6ulzks6.png" alt="Columns: files about 40, commits since October 2, services using it 0; Ember, bored, says nobody at the glass yet; pills read built, and barely used yet" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The window is new. The package is small - around forty files - and it reached the library late in October. No service imports it directly, and on every server it is off unless switched on. That is the state I can describe: the glass is installed, the switch is in the off position, and the first visitor is the admin screen it was built for.&lt;/p&gt;

&lt;h2&gt;
  
  
  What went wrong
&lt;/h2&gt;

&lt;p&gt;The thing this part answers is a habit rather than an incident: when a screen needs data from a service, the fastest path is always a direct database address, and every such shortcut is a key handed out for good. The window exists because "just give the admin read access" kept being the easiest answer, and easy answers are the ones that stay.&lt;/p&gt;

&lt;p&gt;The second lesson is in the busy refusal. A first instinct for "too many queries" is a queue. A queue in front of a struggling database makes everything slower at the worst moment, so the library refuses instead and lets the caller decide.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy9rpvrt0jml9snr0d0i8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy9rpvrt0jml9snr0d0i8.png" alt="Service tiles with faces: the admin screen happy, the service proud, the small pool happy; the switch bored, a busy query angry, the log happy; pills read built, and off by default, barely used yet" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I do not claim
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Not that any service runs with the window open today. It is off by default and imported by none directly.&lt;/li&gt;
&lt;li&gt;Not that the guards are measured under load. They are built.&lt;/li&gt;
&lt;li&gt;Not that read only is enough on its own. It is one guard of six, on purpose.&lt;/li&gt;
&lt;li&gt;Not the exact names of the settings. The form above shows the shape.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What of this is method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Look through the owner, not around it.&lt;/strong&gt; The service holds its database address; tools ask the service.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Every look is bounded and written down.&lt;/strong&gt; Read only, a timeout, caps, a log line.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shut until opened, busy means no.&lt;/strong&gt; Off by default; over the limit, refuse at once.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Zoo keeping, built in - Part 2.&lt;/strong&gt; Next: &lt;em&gt;The Error That Escaped Without A Collar&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;your admin tools hold database addresses&lt;/strong&gt;, how many caves do they have keys to? If &lt;strong&gt;you route queries through the service&lt;/strong&gt;, what guards did you put on the glass? If &lt;strong&gt;you queue queries when busy&lt;/strong&gt;, what happens to the queue when the database is slow? Who in your zoo has a key that should be a window?&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>security</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Every Resident Writes Its Own Sign</title>
      <dc:creator>Anton Brilliantov</dc:creator>
      <pubDate>Mon, 16 Nov 2026 12:47:42 +0000</pubDate>
      <link>https://dev.to/anton_brilliantov/every-resident-writes-its-own-sign-28jj</link>
      <guid>https://dev.to/anton_brilliantov/every-resident-writes-its-own-sign-28jj</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fli1i6hxxkigka2mmielx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fli1i6hxxkigka2mmielx.png" alt="Every Resident Writes Its Own Sign - the cover: Pip next to a stack of signs: who am I, migrations, schemas, history, env" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Every Resident Writes Its Own Sign
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;Every server answers "who are you" by itself: its contract, migrations, tables, history and settings - and it cannot forget to, because nobody writes that code by hand.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;👋 Hi, I'm Anton - a software engineer. These days I work on a platform: contracts, generated code, data paths and the tooling around them. Running notes live on my GitHub: &lt;strong&gt;&lt;a href="https://github.com/brilliant-almazov" rel="noopener noreferrer"&gt;github.com/brilliant-almazov&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The self-description is built into the shared library and runs on every gRPC server that is built on it. Two of its eight answers - the guarded data query and the settings override - are off by default; I describe them as built, not as used.&lt;/p&gt;

&lt;p&gt;This is part 1 of the series on what a shared platform does for every service, told as a zoo. Maybe you already do it better, maybe you'd do it another way - this is how it is going, and where it stops.&lt;/p&gt;




&lt;h2&gt;
  
  
  In real life
&lt;/h2&gt;

&lt;p&gt;Our platform is a zoo. Every service is a resident with its own enclosure, the bus is the paths between the enclosures, acceptance is the vet, and tickets are tokens. The residents in this series are always the same: Pip, who shows visitors around; Nora, the keeper who still checks some things by hand; Biscuit, the dog who carries messages along the paths; Miso, the cat who owns a resource and ignores most requests; Pickle, the guinea pig who helps the vet; and Ember, the small dragon who guards the shared gold.&lt;/p&gt;

&lt;p&gt;Every zoo has signs. A board on a post in front of the enclosure: the name, what the resident eats, where it comes from. In most zoos a keeper writes the sign once, and the sign stays the same for years. So one day Nora stops in front of Miso's enclosure and reads: "eats fish". Miso looks at her with the face cats keep for this kind of moment. "Since spring I eat cake."&lt;/p&gt;

&lt;p&gt;The sign was right on the day it was painted. Then the resident changed, and the sign did not, because the sign and the resident are two different things and only one of them is alive.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc0mzawu2u60pbfp8ba3r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc0mzawu2u60pbfp8ba3r.png" alt="A four-panel comic: Nora reads a sign saying Miso eats fish, Miso says since spring it eats cake; Miso next to a sign it writes itself; Pickle asks what Miso ate last week and Miso offers its diary page by page; Pip asks who writes the sign when Miso naps and Miso says the sign writes itself" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The fix in the comic is the fix in the platform. The resident writes its own sign. Pickle can walk up and ask what Miso ate last week, and Miso hands over the diary, page by page. And when Pip asks who writes the sign while Miso naps, the answer is the punchline of the whole idea: nobody. The sign writes itself, because it is not a separate thing any more.&lt;/p&gt;

&lt;h2&gt;
  
  
  A page about a service is a sign that lies
&lt;/h2&gt;

&lt;p&gt;Every service I have worked with had a page about it somewhere: which tables it owns, which migrations ran, which settings it reads, which version is deployed. Every such page was correct when it was written and drifted afterwards. Not because people are careless, but because the page and the service change at different moments, for different reasons, by different hands.&lt;/p&gt;

&lt;p&gt;The shared Go platform library starts every gRPC server of every service through the same lifecycle. That gave us a place to put the sign where the resident cannot lose it: on the server itself, registered by the library, answering from the running process and its own database. A service does not add a line of code for it, and it has no switch to forget to turn on.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcpvet7r78cwrtpsq3oew.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcpvet7r78cwrtpsq3oew.png" alt="Three tiles with faces: an admin screen asks any gRPC server with eight questions; the server, proud, reads its own database read only; pills read built in the platform, and the data query is off by default" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Eight questions every server answers
&lt;/h2&gt;

&lt;p&gt;Any server built on the library answers eight questions. They fall into four groups: who I am, what my data looks like, a guarded query, and my settings.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx9gc156k5o4be8k3dbnd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx9gc156k5o4be8k3dbnd.png" alt="Bars: who am I and my contract 1, data - migrations, schemas, types, history 4, a guarded query 1, environment - read and override 2; Pickle asks: eight answers, zero lines?; pills read built on every server, and two of eight are off by default" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The shape of the answers, as a form with values left out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DescribeService        -&amp;gt; name, version, contract fingerprint (sha-256)
ListMigrations         -&amp;gt; applied migrations
ListEntityTypes        -&amp;gt; the entities this service owns
ListDataSchemas        -&amp;gt; tables, columns, indexes, partitions, foreign keys
ListEntityHistory      -&amp;gt; change records, cursor after_id
QueryData              -&amp;gt; a guarded read query            (off by default)
ListEnvironment        -&amp;gt; the keys this service reads
SetEnvironmentOverride -&amp;gt; LOG_LEVEL in memory until restart (off by default)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe2m01vtkamx9gn6squy0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe2m01vtkamx9gn6squy0.png" alt="A dark card listing the eight self-description calls with what each returns; the first line, the service description with the contract fingerprint, is highlighted; pills read built, and no service code, no env key for health" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A few details are worth a sentence each.&lt;/p&gt;

&lt;p&gt;The contract fingerprint is a SHA-256 of the compiled descriptors the server actually serves. Two servers with the same fingerprint speak the same contract, whatever their version strings say. That is the line on the sign that is hardest to fake.&lt;/p&gt;

&lt;p&gt;The schema answer is richer than a list of migration files: tables, columns, indexes, partitions and foreign keys, as the service describes its own database. Migrations say how the tables were meant to change; the schema answer says what they look like.&lt;/p&gt;

&lt;p&gt;The history answer reads the change journal that the library already keeps for entities and pages through it with a cursor, so the admin screen can show "what happened to this record" without a direct connection to that service's database.&lt;/p&gt;

&lt;p&gt;The settings override is the only answer that changes anything, and it changes as little as possible: the log level, in memory, until the next restart, and the call carries the id of whoever made it. It is off by default.&lt;/p&gt;

&lt;p&gt;Next to the sign sits a health service that every server also gets for free - "no line of code and no environment variable" was the requirement, and that is how it is built.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who gets the sign
&lt;/h2&gt;

&lt;p&gt;The sign is not something a service opts into. It comes with the server resource of the library. Counted by imports across our services, about thirty of them use the library's resources package, where that server lives - all but one of the services that import the library at all.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fenyrzeeeob4znwci7c9u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fenyrzeeeob4znwci7c9u.png" alt="A donut: about 30 services; import the resources package about 30, the rest 1; Miso, proud, says: I did not write a line; a pill reads counted by imports, rounded" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What the sign answers&lt;/th&gt;
&lt;th&gt;Where the answer comes from&lt;/th&gt;
&lt;th&gt;Can a service forget it?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;who I am, contract fingerprint&lt;/td&gt;
&lt;td&gt;the running server's descriptors&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;migrations, entity types, schemas&lt;/td&gt;
&lt;td&gt;the service's own database&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;change history&lt;/td&gt;
&lt;td&gt;the entity change journal&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;a guarded read query&lt;/td&gt;
&lt;td&gt;the database, through a fenced path&lt;/td&gt;
&lt;td&gt;off by default&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;settings it reads, log level override&lt;/td&gt;
&lt;td&gt;the running process&lt;/td&gt;
&lt;td&gt;override off by default&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That last column is the whole point. A page about a service is a promise someone has to keep. A sign the server writes is not a promise at all - it is a side effect of starting.&lt;/p&gt;

&lt;h2&gt;
  
  
  What changed for the people around the zoo
&lt;/h2&gt;

&lt;p&gt;The admin screen is meant to stop needing a database address for every service: it asks the service, and the service answers about itself. That is a quieter change than it sounds. It means the only component that holds the key to a resident's database is the resident, and the next part of this series is about the one place where we let people look inside anyway.&lt;/p&gt;

&lt;p&gt;The "is it deployed?" question became a call instead of a conversation. The fingerprint answers "which contract", the migrations answer "which schema", and nobody has to remember to update a page after a release.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fewje75w7z35fdp2beyum.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fewje75w7z35fdp2beyum.png" alt="Before and after: a page about a service - by hand, someone writes and forgets; stale, true on the day it was written - and the sign it writes - 0 lines of service code; live, answered by the running server" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F280nrkkcw19cbqwoscgs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F280nrkkcw19cbqwoscgs.png" alt="An animation: an admin screen, any server and its database, all bored; the admin asks who are you, the server answers itself, reads schemas and history read only, and the sign is filled in" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What went wrong
&lt;/h2&gt;

&lt;p&gt;Nothing dramatic broke on the way to the sign; what went wrong is the problem it answers. Pages about services drifted, as they always do, and every reader paid for it by asking a person instead of the service. The lesson behind putting the sign into the library is simple: anything that describes a service and is written by a person is out of date by the time a second person reads it.&lt;/p&gt;

&lt;p&gt;The second lesson is about scope. Two of the eight answers can do more than describe: one reads arbitrary data, one changes a setting. Both are off by default, and the guarded read got a part of its own, because "a sign" and "a key" are very different things to hand out.&lt;/p&gt;

&lt;p&gt;And the honest part: the sign is built and present on every server built on the library, but the reader it was built for is one admin screen. The value of a sign grows with the number of people who stop by to read it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F022paq3wvpze8rc5txyz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F022paq3wvpze8rc5txyz.png" alt="Service tiles with faces: identity, tokens, project data and the scheduler are happy; the admin screen is proud; the data query and the env override are bored, off by default; health is happy" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I do not claim
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Not that every service has every answer turned on. Two of eight are off by default.&lt;/li&gt;
&lt;li&gt;Not that the sign replaces documentation of &lt;em&gt;why&lt;/em&gt; a service exists. It answers &lt;em&gt;what&lt;/em&gt; it is now.&lt;/li&gt;
&lt;li&gt;Not that the admin screen uses all eight answers today.&lt;/li&gt;
&lt;li&gt;Not exact counts. The number of services is rounded from imports.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What of this is method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A description written by the thing itself does not drift.&lt;/strong&gt; Put the sign on the server, not on a page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero lines of service code, zero switches to forget.&lt;/strong&gt; If it can be forgotten, it will be.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Describe freely, change narrowly, off by default.&lt;/strong&gt; The one answer that changes something changes the least possible.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Zoo keeping, built in - Part 1.&lt;/strong&gt; Next: &lt;em&gt;A Viewing Window, Not A Key To The Cage&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;your services describe themselves&lt;/strong&gt;, what do they answer - version, schema, or more? If &lt;strong&gt;you keep pages about services&lt;/strong&gt;, how do you notice when one starts to lie? If &lt;strong&gt;you tried both&lt;/strong&gt;, which one did your on-call engineers actually read? What does the sign in front of your service say today?&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>microservices</category>
      <category>go</category>
      <category>observability</category>
    </item>
    <item>
      <title>Whose Bug Was It</title>
      <dc:creator>Anton Brilliantov</dc:creator>
      <pubDate>Sun, 15 Nov 2026 12:42:37 +0000</pubDate>
      <link>https://dev.to/anton_brilliantov/whose-bug-was-it-899</link>
      <guid>https://dev.to/anton_brilliantov/whose-bug-was-it-899</guid>
      <description>&lt;p&gt;&lt;em&gt;Twenty-three defects in the last twenty-two runs: eleven in the collector, four in config, three in other services, and five of our own.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;👋 Hi, I'm Anton - a software engineer. These days I work on a platform: contracts, generated code, data paths and the tooling around them. Running notes live on my GitHub: &lt;strong&gt;&lt;a href="https://github.com/brilliant-almazov" rel="noopener noreferrer"&gt;github.com/brilliant-almazov&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The count covers only the last twenty-two acceptance runs of the week, where every fix is itemised; one collector fix is still in review and the three defects in other services are open and planned, and both are marked that way below.&lt;/p&gt;

&lt;p&gt;This is part 4 of the series on one week of integration acceptance across a whole chain of services, after months of doing it the slow way. Maybe you already do it better, maybe you'd do it another way - this is how it went, and where it stops.&lt;/p&gt;




&lt;h2&gt;
  
  
  In real life
&lt;/h2&gt;

&lt;p&gt;The whole system is a zoo. The services are the residents, the bus is the paths, and acceptance is the vet - Pickle, a guinea pig with a card for each of eighteen enclosures. Nora is the keeper.&lt;/p&gt;

&lt;p&gt;Pickle's week of rounds found plenty. Biscuit, the courier dog, had a sore paw, and when Pickle confirmed it he said "Told you so!" with great satisfaction. Miso the cat was wearing a name sign that said BISCUIT, and observed, without opening her eyes, "That sign is not mine." Nora went to fix the sign. At one enclosure the cure was next door - and Pip, the guide, pointed out that next door was closed.&lt;/p&gt;

&lt;p&gt;And then, five times in one week, the problem was Pickle. Mixed-up cards, an old page in the notebook, a medicine bottle already empty when she tried it again. Pickle admitted it: "I mixed up the cards." Ember the dragon, who misses nothing, added: "Five times. I counted."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Felgyjlvpn7rn1oeny2bn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Felgyjlvpn7rn1oeny2bn.png" alt="A four-panel comic: Pickle says paw please, hm, sore, and Biscuit, angry, says told you so; Miso, bored, next to a sign reading Biscuit, says that sign is not mine, and Nora says fixing the sign; Pickle, bored, next to a fence, says the cure is next door, and Pip, worried, says next door is closed; Pickle, worried, says I mixed up the cards, and Ember says five times, I counted" width="800" height="678"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The sore paw is a defect in the collector's code. The wrong name sign is configuration on the stand. The closed door next door is a defect in another service, which the acceptance agent can find and cannot fix. And the vet's own mistakes are the acceptance side's false reds. The honest answer to "whose bug was it" has four parts, and one of them points back at the tester.&lt;/p&gt;

&lt;h2&gt;
  
  
  The count
&lt;/h2&gt;

&lt;p&gt;The acceptance agent counted defects only over the last twenty-two runs of the week, because those are the runs where every fix is written down item by item. Earlier runs found things too; they are not in this number.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Whose&lt;/th&gt;
&lt;th&gt;How many&lt;/th&gt;
&lt;th&gt;Status&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;the collector's code&lt;/td&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;td&gt;10 fixed, 1 fix in review&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;configuration and the stand&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;fixed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;other services&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;open, planned there&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;our own - the acceptance side&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;each listed with its fix&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;total&lt;/td&gt;
&lt;td&gt;23&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9j42t9h5arggvhe6rreg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9j42t9h5arggvhe6rreg.png" alt="A waffle of 23 cells in two rows: 10 teal cells with checks, the collector, fixed; 1 teal cell without a check, the collector, a fix in review; 4 indigo cells with checks, config and the stand, fixed; 3 amber cells, other services, open; 5 plum cells with crosses, our own, the acceptance side; Pickle, worried, says five of them were mine; pills read measured and 3 open, planned in other services" width="800" height="453"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Eleven in the collector
&lt;/h2&gt;

&lt;p&gt;The collector's eleven are the ordinary findings of driving a chain end to end: a status probe that could time out, a watchdog whose threshold did not arrive where it was needed and whose probe read the order's scenario, a queue for rebuilding a buffer, the body of a task post, a request-log row that was not closed when the answer never came, a delivery that had to happen exactly once, a priority that had to be clamped, configuration defaults, per-call balance answers in the emulator, and a number type in one provider's override.&lt;/p&gt;

&lt;p&gt;Two of them are worth telling. &lt;strong&gt;Priorities outside 0..100 were refused with an error.&lt;/strong&gt; The owner's norm is different: a number on a scale is clamped to its bound, no error. After the fix, six rows went from red to green. And &lt;strong&gt;configuration defaults&lt;/strong&gt; moved to one form for every leaf, so that a binary starts with sane values when a key is not set:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# every configuration leaf, the form (paraphrased)
WATCHDOG_STATUS_TIMEOUT=${WATCHDOG_STATUS_TIMEOUT:-10s}
&amp;lt;KEY&amp;gt;=${&amp;lt;KEY&amp;gt;:-&amp;lt;default&amp;gt;}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The one still in review is the most instructive. The emulator lets a test override its answer per call, and the balance override worked for one provider - five calls of five - and not for the other, zero of five, because a JSON number fell back to the fixture. The lesson the acceptance agent wrote down: &lt;strong&gt;measure each provider separately; a pass on one does not prove the other.&lt;/strong&gt; The fix is written and waits for its rerun.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# an emulator scenario override, answer by call number (form, values elided)
{"calls": {"N": {...}}}
one provider     5 of 5 calls took the override
the other        0 of 5 calls took the override   | fix in review, rerun pending
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwiebdex8gms1r4n8gl6b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwiebdex8gms1r4n8gl6b.png" alt="Bars: a binary with its neighbour's keys, before, 0 of 13; after the cleanup, 13 of 13; balance override, one provider, 5 of 5; the other provider, fix in review, 0 of 5; Biscuit, worried, says one provider is not proof for the other; pills read built and the second provider in review" width="800" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Four in configuration and the stand
&lt;/h2&gt;

&lt;p&gt;These were not code. The account list for the balance poll needed a fix. An alert called "emulation in production" never fired, because its job label did not match - fixed on the stand. A content service was raised switched off; the switch was named and turned on. And a binary carried another binary's configuration keys: thirteen binaries were checked, none was clean, and after the cleanup all thirteen were. The rule that came out of it is short: a binary knows only its own keys.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three in other services - open
&lt;/h2&gt;

&lt;p&gt;Three defects sit in services the acceptance agent does not own, and the rows they break stay red until those services change:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;results are delivered to a queue that has no consumer, so they stay unread;&lt;/li&gt;
&lt;li&gt;a status call with tenant 0 is refused with "tenant_id must be &amp;gt; 0", so the empty-result mark is lost;&lt;/li&gt;
&lt;li&gt;two norms for the collector contradict each other, and the choice between them is the owner's.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All three are &lt;strong&gt;planned&lt;/strong&gt; in their services. They are the reason the plan stands at 749 of 753 and not at a hundred, and the previous part of this series explains why they stay red rather than leave the scope.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs5859efg7lews0d2ilz3.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs5859efg7lews0d2ilz3.gif" alt="An animation: a red row, drawn as a letter, visits four tiles - the collector, the stand, next door, acceptance - and each tile frowns in turn; the pills change from the collector 11 times, to config and the stand 4 times, to another service 3 times, open, to our own probe 5 times" width="800" height="353"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Five of our own
&lt;/h2&gt;

&lt;p&gt;This is the part I would most like other teams to count. Five defects were the acceptance side's own:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5oadn5xhkjj2kmu1gok7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5oadn5xhkjj2kmu1gok7.png" alt="A dark card with our own five as a form: a retry on a spent scenario, a false red, a fresh scenario per try; verdicts on a stale build, a false minus 4 rows, a per-build ledger; a norm from an old document; 3 wrong citations, found when rows became CI tests; 49 wrong ENV key names in plan rows; the highlighted line reads counted in the last 22 runs, where every fix is itemised; a pill reads listed with their fixes" width="799" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;stale build&lt;/strong&gt; was the costliest. Verdicts were measured on a build that did not contain the fix under test, and one run showed the plan falling from 732 rows to 728 - four rows lost that had never been looked at on the right code. The fix was a per-build ledger on the acceptance side and a rule: a red mark counts only on the build that carries the fix.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;spent scenario&lt;/strong&gt; was the most embarrassing. A retry reused an emulator scenario whose call counter was already used up, so the second attempt failed for a reason that had nothing to do with the collector. Now every attempt gets a fresh copy of the scenario, and a test keeps it that way.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F50rubf9txpj20qfl79y8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F50rubf9txpj20qfl79y8.png" alt="Before and after: a retry on a spent scenario, red, the call counter was used up, false, the collector was fine; a fresh scenario per try, green, the same row, honestly, 1 test that keeps it so; pills read built and tested" width="800" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;three wrong citations&lt;/strong&gt; were found from the other direction: when the collector turned plan rows into CI tests named after them, three rows turned out to quote the wrong source. They were fixed in the plan.&lt;/p&gt;

&lt;h2&gt;
  
  
  Eleven fixed, four added
&lt;/h2&gt;

&lt;p&gt;In the same window the chain did not only get repaired; it also got new behaviour, each piece with its own plan rows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the acceptance control calls moved onto a bus;&lt;/li&gt;
&lt;li&gt;four new calls - a balance poll, page outcomes, balance changes and a utility poll - arrived with new plan rows;&lt;/li&gt;
&lt;li&gt;alert rules are now generated into config;&lt;/li&gt;
&lt;li&gt;the scenario id and the emulation flag are written to the request log.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftzo2tlbixu84c7u5831w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftzo2tlbixu84c7u5831w.png" alt="Columns: fixed 11, added 4; Nora, proud, says eleven cured, four new tricks; pills read built and 1 of 11 fixes in review" width="799" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The sign on the door
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7am465a9m73h98tmsdvo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7am465a9m73h98tmsdvo.png" alt="Nora, proud, waving next to a big sign reading first ask whose card it is; Nora says check your own cards before the paw; on the right the mechanism: a fresh scenario per try, a per-build ledger, out-of-scope-needs-owner-quote; pills read built and 3 open defects planned" width="800" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What went wrong
&lt;/h2&gt;

&lt;p&gt;Five of twenty-three is about one in five. The false reds among them - the spent scenario and the stale build - made the collector look worse than it was, and the wrong citations and key names made the plan itself less trustworthy until they were found. The most expensive was the simplest: a verdict without the name of the build it was measured on.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I do not claim
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Not that twenty-three is all the defects of the week. It is the count over the last twenty-two runs, where every fix is itemised.&lt;/li&gt;
&lt;li&gt;Not that the in-review fix works. It waits for its rerun.&lt;/li&gt;
&lt;li&gt;Not when the three open defects close. They are planned in services the acceptance agent does not own.&lt;/li&gt;
&lt;li&gt;Not that the acceptance side is now free of its own mistakes. It has fewer ways to make the same five.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What of this is method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Count your own.&lt;/strong&gt; A tester's false red is a defect, and it goes into the same table.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One provider is not proof for another.&lt;/strong&gt; Measure each one separately.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Open is a status, not a hiding place.&lt;/strong&gt; A defect in someone else's service stays red and named.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Eighteen domains in a week - Part 4.&lt;/strong&gt; This closes the series.&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;your test reports count defects by service&lt;/strong&gt;, is there a row for the tests themselves? If &lt;strong&gt;you test against more than one provider&lt;/strong&gt;, do you measure each separately? If &lt;strong&gt;a fix belongs to another team&lt;/strong&gt;, does the failing row stay red, or does it leave the plan? Whose bug was your last one?&lt;/p&gt;

</description>
      <category>debugging</category>
      <category>softwareengineering</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
