<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="/feed.xml" rel="self" type="application/atom+xml" /><link href="/" rel="alternate" type="text/html" /><updated>2026-09-24T03:39:00+00:00</updated><id>/feed.xml</id><title type="html">Devan</title><subtitle>A repository of thoughts and notes</subtitle><entry><title type="html">The Edge You Cannot See</title><link href="/articles/2026/08/01/the-edge-you-cannot-see.html" rel="alternate" type="text/html" title="The Edge You Cannot See" /><published>2026-08-01T00:00:00+00:00</published><updated>2026-08-01T00:00:00+00:00</updated><id>/articles/2026/08/01/the-edge-you-cannot-see</id><content type="html" xml:base="/articles/2026/08/01/the-edge-you-cannot-see.html"><![CDATA[<p>The phase was finished. Both environments served through a same-origin HTTPS load
balancer, dark, on parallel hostnames, validated end to end.</p>

<p>Then someone asked where the edge logs were.</p>

<p>There weren’t any. A backend service writes no request logs unless logging is
explicitly enabled, and the API default is <em>off</em>. All four backend services — two
per environment — had been silently unobservable since the day they were applied.</p>

<p>I checked live before writing a single line of the fix. Four out of four, logging
disabled. Nobody had turned it off. That is exactly what made it interesting.</p>

<h2 id="why-it-mattered-more-than-we-should-have-logs">Why it mattered more than “we should have logs”</h2>

<p>My first instinct was that this was mostly cosmetic. The container platform keeps
its own request log, so anything that <em>reaches</em> a service is already recorded,
with status, latency and URL. We weren’t blind.</p>

<p>That instinct was wrong, and the reason is worth internalising.</p>

<p>What was missing is everything the load balancer handles <strong>itself</strong>:</p>

<ul>
  <li>a request rejected by the WAF policy</li>
  <li>a 502 from a backend that never came up</li>
  <li>a request matching no path rule at all</li>
</ul>

<p>None of those reach a service. So they leave no trace anywhere. Not in the
application logs, not in the platform’s request log, nowhere.</p>

<p>They are also, by some distance, the failures hardest to reason about from a user
report. “It was down for me for about a minute” against a platform log showing an
uninterrupted stream of 200s is an unfalsifiable conversation. You cannot prove a
negative from an absence of evidence you created yourself.</p>

<p>And they get considerably more likely at cutover — the moment the edge stops being
dark and starts carrying every customer, which is the worst possible time to
discover you have no visibility at the one layer that’s new.</p>

<h2 id="three-design-calls-worth-stealing">Three design calls worth stealing</h2>

<p>The fix was small. The decisions inside it were the useful part.</p>

<p><strong>Default on, deliberately.</strong> The new toggle defaults to enabled. I thought about
this for longer than the code took, because “default off, opt in per environment”
is the more conventional shape for anything that costs money.</p>

<p>The argument that settled it: <em>the failure mode we’re fixing was reached by nobody
deciding anything.</em> No one weighed the cost of edge logs and chose to skip them.
The state arrived by omission. An edge that cannot be observed should not be a
state you can arrive at without a decision — so the default has to be the safe
value, and turning it off has to be a thing someone writes down and justifies.</p>

<p>Generalise it: <strong>make the value you get when nobody thinks about it the value you
would have chosen if they had.</strong></p>

<p><strong>A sample rate, not an on/off switch.</strong> Full sampling while the edge is dark:
volume is negligible, and a partial sample is worse than useless when you’re
chasing one specific request a tester reported by timestamp.</p>

<p>But the knob exists so that at cutover, when volume is real and someone says “this
is getting expensive,” the available answer is <em>sample down</em> — not <em>switch off and
lose the failure paths entirely</em>. If your only control is a boolean, cost pressure
will eventually find the off switch. Give the future a dial.</p>

<p><strong>Derive coupled fields together.</strong> The API rejects a non-zero sample rate on a
disabled logging config. If you pass both values through independently, a caller
can construct that invalid pair and discover it at apply time, halfway through a
change.</p>

<p>Deriving both from one local — disabled forces the rate to zero — means the
invalid combination cannot be expressed. Make the illegal state unrepresentable,
in Terraform as much as in a type system.</p>

<p>There’s a fourth, smaller one: both backends always share a single sample rate,
enforced by a test. A configuration where the web app logs and the API doesn’t is
<em>worse</em> than neither logging, because a half-covered dashboard reads as complete
coverage. Partial observability lies more convincingly than none.</p>

<h2 id="the-websocket-footnote">The websocket footnote</h2>

<p>Worth knowing before it confuses you at 2am: a websocket is <strong>one</strong> log entry,
written when the connection <em>closes</em>, with the entire connection lifetime recorded
as its latency.</p>

<p>That’s good news for cost — one entry per connection, not per frame — and mildly
alarming the first time you tail the logs during a live session and see nothing at
all. The entries lag by however long the socket stays open. A quiet log is not
evidence of a quiet system.</p>

<h2 id="the-module-had-no-tests">The module had no tests</h2>

<p>The reusable edge module shipped without a single test. It now has six, and one of
them is the one I’d fight to keep.</p>

<p>Five assert the logging contract: on by default at full sampling, both backends
always sharing one rate, disabling forces the rate to zero, out-of-range rates
rejected at both ends.</p>

<p>The sixth asserts something the other five never mention — the routing invariant.
Only the API prefix and the socket path are carved out; everything else defaults to
the web app. That’s the assumption the logging assertions quietly stand on. If
someone reorders the URL map, the logging tests keep passing while meaning
something completely different.</p>

<p><strong>A test that pins the assumption underneath your other tests is worth more than
another test of the feature.</strong> They’re rarer than they should be, because nobody
writes a test for the thing that isn’t changing.</p>

<h2 id="where-this-series-lands">Where this series lands</h2>

<p>Six parts, and the failures have a shape in common that I didn’t see until I wrote
them out.</p>

<p>The gate that validated its own input. The rejected deploy that kept running. The
credential with a thirty-day fuse. The edge with no logs. Not one of them would
have paged anyone. Every one of them was the system quietly <em>not</em> doing something,
with no signal that would ever have said so.</p>

<p>That’s the real argument for building it dark, and it’s a better one than “safer
cutover.” The dark period isn’t waiting time. It’s the only window you get where
the system is real enough to be wrong and cheap enough to be wrong in — where you
can find the failures that don’t announce themselves, before they’re carrying
everybody’s traffic.</p>

<p>The cutover itself is a DNS record. The value was in the month before it.</p>

<p>Which is, I notice, the same sentence I wrote at the start of the baseline series
about the two months before <em>that</em>. I set out to write about a migration and
ended up writing thirteen posts about instrumentation — about the difference
between a system that is working and one that is merely quiet, and how little of
that difference is visible unless you build something that can tell you.</p>

<p>If there’s one thing to take from either series: the failures that hurt aren’t
the ones that page you. Go and find the checks you’ve never seen fail.</p>]]></content><author><name></name></author><category term="articles" /><category term="observability" /><category term="load-balancing" /><category term="gcp" /><category term="infrastructure" /><category term="opentofu" /><category term="terraform" /><summary type="html"><![CDATA[Both environments were serving through a new load balancer, and all four backend services had been writing zero logs since the day they were applied. Nobody turned logging off. That was the problem.]]></summary></entry><entry><title type="html">Two Credentials, and the Weaker One Wins</title><link href="/articles/2026/07/25/two-credentials-and-the-weaker-one-wins.html" rel="alternate" type="text/html" title="Two Credentials, and the Weaker One Wins" /><published>2026-07-25T00:00:00+00:00</published><updated>2026-07-25T00:00:00+00:00</updated><id>/articles/2026/07/25/two-credentials-and-the-weaker-one-wins</id><content type="html" xml:base="/articles/2026/07/25/two-credentials-and-the-weaker-one-wins.html"><![CDATA[<p>The deploy gate needed to prove more than “the service answers.” The application’s
core feature is real-time, so a candidate revision that serves a healthy HTTP
response while its socket layer is broken is exactly the deploy we most wanted to
stop.</p>

<p>So the gate grew a second, deeper assertion: log in as a dedicated smoke user,
open a real-time connection, exercise the contract, and only then promote. It
gates every promotion, production included.</p>

<p>That assertion needs a credential. This is the story of the credential, and it’s
the one lesson from the whole project I’d most like to have learned from someone
else’s post.</p>

<h2 id="three-versions">Three versions</h2>

<p><strong>Version one: a stored session cookie.</strong> A valid session, captured once by hand
and put in the secret manager. Simple. Worked immediately. Long-lived secrets in a
CI system are a known smell, but it unblocked the gate.</p>

<p><strong>Version two: mint a session per run.</strong> The pipeline authenticates with the smoke
user’s password and gets a fresh session for that run, then revokes it. Nothing
long-lived, nothing to rotate, nothing to expire quietly.</p>

<p>Better in every way. We shipped it, cut both environments over, and deleted the
cookie secrets.</p>

<p><strong>Version three: delete the cookie code path.</strong> Which is where this gets
interesting, because at the time it looked like tidying up.</p>

<h2 id="why-the-dormant-path-was-not-dormant">Why the “dormant” path was not dormant</h2>

<p>The code still accepted a cookie. Both environments were configured with a
password. Every run minted its own session. The cookie branch was unreachable in
practice, and I’d have described it as inert.</p>

<p>Two things made it a live hazard.</p>

<p><strong>First: the cookie won.</strong> In the precedence order, a cookie supplied alongside a
password was <em>preferred</em>. So re-creating that secret — in a fork, in a new
environment, by an operator following documentation we hadn’t finished updating —
would silently move that environment back onto the old credential. Nothing reports
a downgrade. There is no log line for “using the weaker of two available
credentials,” because from the code’s point of view nothing unusual happened.</p>

<p><strong>Second: that credential dies on a timer.</strong> The application enforces a hard
thirty-day cap on session lifetime. So a stored cookie is not merely weaker, it is
a scheduled failure. Set it today, and in a month the gate stops working.</p>

<p>And here’s the bit that turns an inconvenience into a proper incident: when it
fails, the socket login returns a negative acknowledgement. Which is <strong>byte-for-byte
identical</strong> to what a genuinely broken build returns.</p>

<p>So the failure mode is: on a date nobody chose, weeks after the change that caused
it, a production deploy is blocked with a symptom that says the application is
broken. The on-call engineer starts by reading the pull request being deployed —
which is fine — and the actual cause is a secret that someone re-created a month
ago in good faith.</p>

<p>That is precisely the class of failure this entire workstream existed to remove.
A scheduled outage with a misleading symptom.</p>

<p>We also found that several places in the repository still instructed an operator to
create exactly that secret — including the description of the ticket that had
<em>automated its replacement</em>. Documentation rot isn’t cosmetic when the document
is a runbook. It’s a loaded instruction.</p>

<h2 id="the-fix">The fix</h2>

<p>Delete the branch. Specifically:</p>

<ul>
  <li>A cookie supplied alongside a password is <strong>ignored</strong>, not preferred.</li>
  <li>A cookie supplied <strong>alone fails closed</strong> with an error, rather than resolving to
a working credential mode. A stale secret in a fork cannot present as
functioning configuration.</li>
  <li>The error message <strong>names both real secrets explicitly</strong>, per environment.
This one is subtle and I think it’s the sharpest detail in the change: the
environments’ secret names differ by a suffix, and a reasonable operator guessing
the pattern produces a name the workflow never reads. That guess doesn’t fail
loudly — it produces an environment where the gate soft-passes while everyone
believes it is armed. An error message that guesses on your behalf is worth more
than one that’s merely accurate.</li>
  <li>Every instruction telling someone to create the old secret is gone.</li>
</ul>

<p>Net effect: about forty lines added, no behaviour change whatsoever for a
correctly configured environment. The change is entirely about which <em>incorrect</em>
configurations are now impossible.</p>

<h2 id="the-lesson">The lesson</h2>

<p><strong>A deprecated authentication path is not dormant while the code still accepts it.</strong></p>

<p>“We’re not using that any more” is a statement about today’s configuration. It is
not a statement about the code. Configuration changes — during a migration, it
changes constantly, in environments you didn’t create, by people reading
documentation you forgot to update.</p>

<p>And the asymmetry that makes this genuinely dangerous: if the weaker credential
<em>loses</em> the precedence order, a leftover secret is harmless clutter. If it <em>wins</em>,
the same leftover secret is a downgrade with no alarm attached. Same code, same
config, opposite risk — decided by a line of precedence logic nobody reviewed as a
security decision.</p>

<p>So: delete the old path in the same change that replaces it. If you genuinely
can’t, at minimum make the weaker option lose, and make choosing it say so out
loud.</p>

<p>Otherwise you haven’t deprecated anything. You’ve scheduled an incident and
written the misleading symptom yourself.</p>

<p>Have you got a fallback path in your system that would win if both were present?</p>]]></content><author><name></name></author><category term="articles" /><category term="security" /><category term="release-engineering" /><category term="ci-cd" /><category term="secrets" /><category term="incidents" /><summary type="html"><![CDATA[We replaced a long-lived session cookie with a credential minted per run, then left the old path in as a harmless fallback. It was not harmless — it was an outage with a thirty-day fuse.]]></summary></entry><entry><title type="html">Cloud Run Is Serverless Until It Isn’t</title><link href="/articles/2026/07/24/cloud-run-is-serverless-until-it-isnt.html" rel="alternate" type="text/html" title="Cloud Run Is Serverless Until It Isn’t" /><published>2026-07-24T00:00:00+00:00</published><updated>2026-07-24T00:00:00+00:00</updated><id>/articles/2026/07/24/cloud-run-is-serverless-until-it-isnt</id><content type="html" xml:base="/articles/2026/07/24/cloud-run-is-serverless-until-it-isnt.html"><![CDATA[<p>I recently took a client’s application from nothing to a real production
deployment on Google Cloud Run — stage and prod, infrastructure as code, secrets
managed, the works. Cloud Run is a lovely platform to say yes to. You hand it a
container, it hands you a URL, and the scaling is somebody else’s problem.</p>

<p>Then the real system arrives and the word “serverless” quietly stops meaning
“no infrastructure.” It means “different infrastructure, and it’s still yours.”</p>

<p>Here are the parts that actually took the time. None of them were the container.</p>

<h2 id="the-networking-you-thought-youd-escaped">The networking you thought you’d escaped</h2>

<p>The first wall was the database.</p>

<p>The app talks to a managed MongoDB, and that database only accepts connections
from a known set of IP addresses. Reasonable. Except a Cloud Run service, by
default, egresses from a shared, ever-changing pool of Google IPs. There is no
address to put on the allowlist.</p>

<p>So the serverless service that was supposed to free me from networking needed:
a VPC connector, direct VPC egress, and a Cloud NAT with a <em>static</em> external IP —
one stable address the database could trust. The moment you need a predictable
source IP, you are back to owning a network.</p>

<p>And once you own a network, you own its capacity. I sized the egress subnet at a
/28 — sixteen addresses, surely plenty for one service. It wasn’t. Direct VPC
egress consumes addresses faster than the intuition suggests, and under load the
subnet ran dry. Grew it to a /26 and the problem disappeared. That is a very
old-fashioned lesson — <em>subnet too small</em> — arriving inside a very modern
platform.</p>

<p>The trade-off worth naming: serverless sells you out of capacity planning right
up until you touch something with an IP allowlist. Then you get all of it back
at once, and it’s better to design for it on day one than to discover it when
production connections start getting refused.</p>

<h2 id="everything-has-a-bootstrapping-order">Everything has a bootstrapping order</h2>

<p>The subtler class of problem was ordering. Infrastructure as code loves to
describe the finished state — every service, every identity, every permission,
all present and referring to each other. Real infrastructure has to be <em>born</em>,
and at birth half of those things don’t exist yet.</p>

<p>Three of these bit me in the same week.</p>

<p><strong>The safe-rollout gate.</strong> I’d built a blue-green style deploy: bring the new
revision up alongside the old one, smoke-test it, shift traffic only once it’s
proven. Lovely — except it works by comparing against the <em>current good
revision</em>. On the very first deploy of a brand-new service, there is no current
revision to fall back to. The safe path can’t run because the thing that makes it
safe hasn’t been created yet. The fix was to detect that case and degrade
gracefully to a plain apply for the first deploy, then let the safe path take
over once a baseline exists.</p>

<p><strong>The CI identity.</strong> The deploy pipeline runs as a service account, and that
account needs permission to act as each service’s runtime identity. I’d listed
the production runtime identity in that grant — before the production service
account existed. The grant refused, because you can’t reference an identity that
hasn’t been created. The answer was to defer it: leave production out of the list
until its service account is actually stood up, then admit it.</p>

<p><strong>The trust between repos and the cloud.</strong> Deploys authenticate with workload
identity federation rather than long-lived keys, which means each application
repository has to be explicitly admitted to a shared identity provider. Stand up
a new environment and that trust has to be re-established, in order, before
anything can deploy at all.</p>

<p>The pattern underneath all three is the same: your infrastructure code has a
cold-start problem, and the default bug is <em>assuming the thing already exists</em>.
The finished-state description is correct for every day except the first one, and
the first one is the day you’re actually watching.</p>

<h2 id="the-unglamorous-safety-net">The unglamorous safety net</h2>

<p>The last thing that earned its keep was the least clever: a written cutover
runbook and a set of smoke tests treated as a contract.</p>

<p>Not smoke tests as “does the health check return 200.” Smoke tests as an explicit
list of the things that must be true after a deploy — the service answers, it
reaches the database, the real-time channel connects — codified so the deploy
itself can check them, and a human following the runbook can check the same list
by hand during a cutover. When the switch from the old environment to the new one
finally happened, the interesting part was how boring it was. That was the point.</p>

<h2 id="what-id-tell-the-version-of-me-who-started">What I’d tell the version of me who started</h2>

<p>Cloud Run genuinely removes a lot of work. It does not remove the network, the
identities, or the order those things have to come alive in. If you’re planning a
similar stand-up, spend your design time on the parts that aren’t serverless:</p>

<ul>
  <li>Decide your egress story <em>before</em> the first database connection is refused —
and size the subnet with room to spare.</li>
  <li>Assume every “reference” in your IaC will, at some point, point at something
that doesn’t exist yet. Make the first deploy a first-class case, not an
afterthought.</li>
  <li>Write the cutover down and make the deploy prove its own success. A boring
switch-over is a feature you build on purpose.</li>
</ul>

<p>None of this is exotic. That’s rather the point — the platform is new, but the
things that bite are the same things that always bite. Serverless just changes
where you meet them.</p>]]></content><author><name></name></author><category term="articles" /><category term="cloud-run" /><category term="gcp" /><category term="infrastructure" /><category term="opentofu" /><category term="release-engineering" /><summary type="html"><![CDATA[Bringing a client's application to production on Google Cloud Run, and the networking and bootstrapping snags a serverless platform doesn't warn you about.]]></summary></entry><entry><title type="html">The Deploy You Rejected Is Still Running</title><link href="/articles/2026/07/18/the-deploy-you-rejected-is-still-running.html" rel="alternate" type="text/html" title="The Deploy You Rejected Is Still Running" /><published>2026-07-18T00:00:00+00:00</published><updated>2026-07-18T00:00:00+00:00</updated><id>/articles/2026/07/18/the-deploy-you-rejected-is-still-running</id><content type="html" xml:base="/articles/2026/07/18/the-deploy-you-rejected-is-still-running.html"><![CDATA[<p>The safe-rollout gate did its job. A new revision came up at zero traffic under a
private tag, the smoke test failed, and the deploy refused to promote it. The
production service kept serving the previous revision. The pipeline went red.
Textbook.</p>

<p>Nobody asked what happened to the revision we’d just rejected.</p>

<h2 id="what-happened-to-it">What happened to it</h2>

<p>It kept running. For a day. Executing scheduled work against the production
database.</p>

<p>The mechanism is three innocuous facts standing on each other’s shoulders:</p>

<ol>
  <li>A revision that carries a <strong>tag</strong> must keep serving its own private URL, so
the platform considers it <em>addressable</em>.</li>
  <li>The platform will not deactivate an addressable revision. Ever. That’s the
contract — the tagged URL is supposed to work.</li>
  <li>These services run with a <strong>minimum instance count of one</strong>, so “not
deactivated” means a container is up. Continuously.</li>
</ol>

<p>And that container runs the application’s scheduler, which is in-process: timers
that start when the process starts, pointed at the production database and a
third-party CRM. It has no idea it lost a smoke test. Nothing told it. Nothing
could — it’s just a process that booted.</p>

<p>The coordination lock the application uses for scheduled work lives in a
per-instance sidecar, so it could not arbitrate between the rejected revision and
the one actually serving traffic. It was never designed to. Two processes, same
timers, same production data, in parallel.</p>

<h2 id="the-evidence">The evidence</h2>

<p>I want to be precise about how this was established, because “the tag was the
cause” is exactly the kind of claim that’s easy to assert and hard to prove.</p>

<p>It was a controlled comparison, not an inference. Four revisions of the same
production service, all with the same minimum-instance setting:</p>

<table>
  <thead>
    <tr>
      <th>Revision</th>
      <th>Traffic</th>
      <th>Tag</th>
      <th>Active</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>the serving revision</td>
      <td>100%</td>
      <td>—</td>
      <td>yes</td>
    </tr>
    <tr>
      <td>the failed candidate</td>
      <td>0%</td>
      <td><code class="language-plaintext highlighter-rouge">candidate</code></td>
      <td><strong>yes</strong></td>
    </tr>
    <tr>
      <td>an older revision</td>
      <td>0%</td>
      <td>—</td>
      <td>no</td>
    </tr>
    <tr>
      <td>an older revision</td>
      <td>0%</td>
      <td>—</td>
      <td>no</td>
    </tr>
  </tbody>
</table>

<p>Three revisions at zero traffic. Two inactive. One very much alive. The only
difference between them is the tag.</p>

<p>That table is the whole argument, and it took about four minutes to produce. It’s
worth the habit: when you think you understand a platform behaviour, find the case
that differs in exactly one variable before you write the fix.</p>

<h2 id="the-fix">The fix</h2>

<p>Drop the tag when a rollout is not promoted. The revision stops being addressable,
the platform deactivates it, the container goes away.</p>

<p>The interesting work was in the edges rather than the mechanism:</p>

<ul>
  <li><strong>Every non-promotion path</strong>, not just the obvious one. A failed health check, a
failed real-time smoke, an unresolvable candidate URL, an apply that fell over
<em>after</em> its traffic write landed, and a cancelled job. “Cancelled” is the one
people miss — someone hits stop, and the residue is identical.</li>
  <li><strong>Never after a successful promotion</strong>, where promotion collapses the tag
itself, and never for a service deploying without a tag at all.</li>
  <li><strong>Idempotent and fail-soft.</strong> Cleanup must not mask the smoke failure that got
us here. The job still ends red; that is the signal that matters.</li>
  <li><strong>A loud, actionable failure.</strong> If cleanup itself fails, the run emits the exact
copy-pasteable command and says plainly that the revision is still running
scheduled work. Not “cleanup failed” — the consequence, in words, so the person
reading at 11pm doesn’t have to reconstruct this post.</li>
</ul>

<p>Plus the one-off: an existing ghost revision that had been running for a day. Not
something a merge can fix — an operator action, with the command written into the
rollback documentation so the next person doesn’t have to derive it.</p>

<h2 id="the-lesson-which-i-have-now-learned-twice">The lesson, which I have now learned twice</h2>

<p><strong>“Not receiving traffic” is not “not running.”</strong></p>

<p>I had internalised the traffic split as the safety boundary. Zero percent means
harmless. It doesn’t. Zero percent means no <em>inbound requests</em> — and an inbound
request is only one of the ways a process does work. Timers, queue consumers,
change streams, cache warmers, replication clients: all of those start when the
container starts and run regardless of what the routing layer thinks.</p>

<p>The second time I learned it was two weeks earlier, in the same phase, from the
opposite direction: the entire dark stack — a full parallel copy of production
serving no customers — also had to have its scheduler explicitly disabled, for
precisely the same reason. Same insight, different corner of the system, and I
didn’t connect them until I’d been bitten by both.</p>

<p>There’s a design point underneath. A rollout gate is a state machine, and
<strong>rejection is a state, not the absence of one.</strong> We design the happy path
carefully — deploy, verify, promote — and treat failure as the thing that didn’t
happen. But failure isn’t an absence. It leaves residue: half-created resources,
warm containers, tags, locks, partial writes. Residue with a scheduler in it is an
outage sitting quietly in the diary, waiting for a slow week.</p>

<p>So when you build the gate, write down what the rejected branch <em>leaves behind</em>,
in the same sitting. Not later. Later is a day of duplicate cron runs against
production and a table you have to build to prove why.</p>

<p>What does your failed deploy leave behind?</p>]]></content><author><name></name></author><category term="articles" /><category term="cloud-run" /><category term="release-engineering" /><category term="blue-green" /><category term="incidents" /><category term="ci-cd" /><summary type="html"><![CDATA[A candidate revision failed its smoke test and never took traffic. It also never stopped — and it spent a day running scheduled jobs against the production database.]]></summary></entry><entry><title type="html">The Check That Validated Its Own Input</title><link href="/articles/2026/07/11/the-check-that-validated-its-own-input.html" rel="alternate" type="text/html" title="The Check That Validated Its Own Input" /><published>2026-07-11T00:00:00+00:00</published><updated>2026-07-11T00:00:00+00:00</updated><id>/articles/2026/07/11/the-check-that-validated-its-own-input</id><content type="html" xml:base="/articles/2026/07/11/the-check-that-validated-its-own-input.html"><![CDATA[<p>The deploy gate looked airtight when I described it to people.</p>

<p>A new revision comes up at zero traffic under a private tag. A smoke test hits
its health endpoint and asserts two things: the service reports healthy, <strong>and</strong>
the version it reports matches the commit we asked to deploy. Only then does a
second apply shift traffic to it.</p>

<p>That second assertion is the good bit. It doesn’t just prove something is
running, it proves the <em>right build</em> is running. Or so I told people.</p>

<p>It proved nothing at all.</p>

<h2 id="the-shape-of-the-bug">The shape of the bug</h2>

<p>Trace the value. The commit SHA enters the deploy workflow once, and then goes to
two places:</p>

<ul>
  <li>It is passed into the container as an environment variable, which the health
endpoint reads and reports as its <code class="language-plaintext highlighter-rouge">version</code>.</li>
  <li>It is passed to the smoke test as the <em>expected</em> value.</li>
</ul>

<p>One variable, stamped into the thing being measured and used as the yardstick.
The comparison can only fail if the wiring between those two lines is broken.</p>

<p>It is a tautology wearing a hard hat.</p>

<h2 id="the-fallback-that-made-it-harmful">The fallback that made it harmful</h2>

<p>On its own, a tautological check is merely useless. This one was worse, because
of a default.</p>

<p>The workflow resolved the commit as: the dispatched input, <strong>or</strong> the payload
value, <strong>or</strong> the CI runner’s own commit. That last fallback is the infrastructure
repository’s <code class="language-plaintext highlighter-rouge">HEAD</code> — a commit that has nothing to do with the application build
at all.</p>

<p>The automated path always supplied a real value, so this never bit. The manual
path declared the input optional.</p>

<p>Then two production deploys went out by hand, dispatched the minute an
infrastructure PR merged. Both application containers were stamped with the
<em>infrastructure repository’s merge commit</em> — a SHA that exists in neither
application repository. From the run log:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>smoke: healthy; version matches dispatched sha &lt;the infra repo’s merge commit&gt;
</code></pre></div></div>

<p>Green. Both times. Every health probe on production was reporting an
infrastructure commit as the application version, and the check that exists to
catch exactly that reported success.</p>

<p>Nothing was broken, to be clear. The right images were deployed. But for the
better part of a day, the system’s own answer to “what is running?” was a
confident lie, and the gate designed to detect confident lies had signed it off.</p>

<h2 id="the-fix-in-three-parts">The fix, in three parts</h2>

<p><strong>Make the input required, with no fallback.</strong> The commit is now mandatory, and
the deploy fails closed on a missing value, a malformed one, or one that belongs
to the infrastructure repository rather than an application. The dispatch path
that carries no input schema gets the same check at runtime, because a validation
that only exists in the form definition isn’t a validation.</p>

<p><strong>Give the comparison an independent second source.</strong> The commit is now verified
against the container image’s build provenance <em>before</em> anything is planned. That
value is produced by the build system, signed, and not restatable by the deploy
workflow. A plausible-looking wrong SHA now fails the deploy outright, rather than
mislabelling the build.</p>

<p><strong>Correct the documentation that oversold it.</strong> Two places described the assertion
as a stale-image guard. It never was one, and leaving that written down is how the
next person builds on a guarantee that doesn’t exist.</p>

<p>There’s a fourth part still open, and I’d rather say so than pretend the story
ends neatly: the version really wants to be <em>read out of the image</em> at build time,
which needs a change in the application repositories’ build. Until that lands, the
only fully honest answer to “what build is serving?” is the image digest on the
serving revision — the one value nothing in the pipeline can restate. That went in
the developer docs, with the health endpoint explicitly labelled as <em>not</em> build
evidence.</p>

<h2 id="the-generalisable-bit">The generalisable bit</h2>

<p>I’ve since started asking one question of every assertion I write:</p>

<blockquote>
  <p><strong>What would have to be broken for this to fail?</strong></p>
</blockquote>

<p>If the honest answer is “the wire between these two lines of my own code,” it is
not a gate. It is a self-consistency check, and self-consistency is the one
property a broken system retains most reliably.</p>

<p>A check is worth exactly as much as the <em>independence</em> of the two things it
compares. Same variable, no value. Same process, little value. Same team’s
assumptions, some value. A signed artefact from a system that has no idea your
check exists — that’s a gate.</p>

<p>This pattern is everywhere once you look for it. Tests that assert a function
returns what a fixture built from the same function says it should. Monitoring
that reads the deployment manifest to decide what version <em>should</em> be running.
Contract tests generated from the implementation. Every one of them will hold
green through the exact failure it was written to catch.</p>

<p>The tell is comfort. A check that has never once failed, in a system that has
definitely had problems, is not a check that’s protecting you. It’s a check that
isn’t looking.</p>

<p>What’s the most tautological green check you’ve found in your own pipeline?</p>]]></content><author><name></name></author><category term="articles" /><category term="release-engineering" /><category term="ci-cd" /><category term="testing" /><category term="supply-chain" /><category term="cloud-run" /><summary type="html"><![CDATA[A deploy gate asserted that the running build matched the commit being deployed. It passed every time, including the times it was wrong, because both sides of the comparison came from the same variable.]]></summary></entry><entry><title type="html">One Hostname, Two Services</title><link href="/articles/2026/07/04/one-hostname-two-services.html" rel="alternate" type="text/html" title="One Hostname, Two Services" /><published>2026-07-04T00:00:00+00:00</published><updated>2026-07-04T00:00:00+00:00</updated><id>/articles/2026/07/04/one-hostname-two-services</id><content type="html" xml:base="/articles/2026/07/04/one-hostname-two-services.html"><![CDATA[<p>The web app and the API had always been separate origins. Different hostnames,
one cookie shared across them, a real-time socket connection opening to the
second host, and CORS headers doing the heavy lifting in between.</p>

<p>It worked. It also meant every browser vendor’s next decision about cross-site
cookies was a scheduled incident on somebody’s calendar.</p>

<p>So the last piece of the migration was an edge: one global HTTPS load balancer,
<strong>one hostname</strong>, path-routed to two container services.</p>

<table>
  <thead>
    <tr>
      <th>Path</th>
      <th>Goes to</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">/api/*</code></td>
      <td>the API service</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">/socket.io/*</code></td>
      <td>the API service</td>
    </tr>
    <tr>
      <td>everything else</td>
      <td>the web app</td>
    </tr>
  </tbody>
</table>

<p>Same origin. No CORS. A first-party cookie. One certificate. The browser only
ever talks to one host, and it stops being a participant in your architecture.</p>

<p>That’s the whole benefit, and it’s a big one. The rest of this post is the price,
because nobody writes that part down.</p>

<h2 id="price-one-the-apis-entire-rest-surface-has-to-move">Price one: the API’s entire REST surface has to move</h2>

<p>If <code class="language-plaintext highlighter-rouge">/api/*</code> routes to the API service, then the API has to serve its routes under
<code class="language-plaintext highlighter-rouge">/api</code>. All of them.</p>

<p>We got lucky here — the application already supported a path prefix as a
configuration value, and every handler registered at <code class="language-plaintext highlighter-rouge">${PREFIX}/…</code>. So the change
was one environment variable per environment and no application code at all.</p>

<p>If your API doesn’t already have that seam, budget for it properly. Retrofitting
a prefix onto a router that hardcodes its paths is not a config change, it’s a
day of find-and-replace with a bad failure mode: the routes you miss return 404
through the load balancer and 200 when you test the service directly.</p>

<h2 id="price-two-the-health-check-must-not-move">Price two: the health check must <em>not</em> move</h2>

<blockquote>
  <p><strong>Update, September 2026.</strong> Half of the reasoning in this section was wrong.
When I went back to correct a config comment, I checked what actually calls
the health endpoint. The platform’s startup probe on this service is a plain
TCP check on the port, and there is no liveness probe, so the probe never
touched health and a prefix wouldn’t have broken it. The deploy smoke test
does call health directly, on the new revision’s own URL, so that half
stands. Health has since started answering on both the prefixed and
unprefixed paths. The general rule at the end of this section still holds.</p>
</blockquote>

<p>This is the one I’d want someone to tell me before I started.</p>

<p>Two things call the health endpoint, and neither of them goes through the load
balancer:</p>

<ol>
  <li>The container platform’s own startup and liveness probe, which hits the
service directly.</li>
  <li>The deploy smoke test, which brings a new revision up at zero traffic on a
private tagged URL and asserts it’s healthy before promoting it.</li>
</ol>

<p>Turn on a global <code class="language-plaintext highlighter-rouge">/api</code> prefix and both of those break at once — the probe fails,
so the revision never becomes ready, so the deploy that introduced the prefix
fails in a way that looks like the application is broken.</p>

<p>So health stays deliberately unprefixed, as an explicit carve-out, while every
other route moves. That is an inconsistency, and inconsistencies get tidied away
by well-meaning people six months later. It needs a comment at the definition
explaining what depends on it, not just a line in a design doc.</p>

<p>The general rule: <strong>before you move a path, enumerate everything that calls it
without going through your new edge.</strong> Probes, smoke tests, uptime monitors,
internal service-to-service calls, and the load balancer’s own health checks all
bypass the routing layer you’re about to change.</p>

<h2 id="price-three-root-path-collisions-are-the-actual-reason-for-the-prefix">Price three: root-path collisions are the actual reason for the prefix</h2>

<p>The prefix wasn’t chosen for tidiness. It was forced.</p>

<p>Both services independently owned routes at the same top-level paths — a file
route, a CSP-report sink, a health endpoint. Under two hostnames that’s fine;
they never meet. Under one hostname, exactly one of them can win.</p>

<p>In our case the file route belongs to the web app, which proxies object storage
server-side. The API’s same-named routes now live under the prefix. The CSP sink
is the web app’s; the API’s is under the prefix too.</p>

<p>This is the kind of conflict that is glaringly obvious in a routing table and
completely invisible in a code review of either repository. Neither diff is wrong.
The collision only exists in the space between them.</p>

<p>If you’re planning a same-origin edge, do this first: list every top-level path
each service registers, put them in one table, and look for the overlap. Ten
minutes, and it tells you whether you need a prefix and where.</p>

<h2 id="price-four-the-client-has-to-learn-that-its-bases-differ">Price four: the client has to learn that its bases differ</h2>

<p>The web app had a single base URL for everything — REST, socket, uploads.</p>

<p>Under the edge, they diverge. REST is the host plus the prefix. The socket base is
the bare host, because the socket path is carved out at the root of the URL map.
Uploads are the host plus their own path. One hostname, three different bases.</p>

<p>We split the REST base out as its own configuration value — and made it
<strong>optional, falling back to the existing socket base when unset</strong>. That detail did
more work than it looks like.</p>

<p>During a dark migration, the config change and the image build roll through two
environments on independent schedules. An optional value with a sane fallback
means the new configuration is <em>inert</em> on any image built before the split, and
the new image behaves exactly as it did before on any environment that hasn’t set
the value. Neither half of the change can break the other half’s environment.</p>

<p>That’s a cheap habit worth generalising: <strong>when a config change and a code change
have to meet, make the config optional so they can arrive in either order.</strong></p>

<h2 id="is-it-worth-it">Is it worth it?</h2>

<p>You are taking on real infrastructure: a URL map, two backend services, a managed
certificate with its own provisioning lifecycle, a WAF policy, and a set of
failure modes that live entirely at the edge and never reach your application
logs. (That last one has its own post in this series — it turns out we couldn’t
see any of them.)</p>

<p>In exchange you delete cross-origin cookies, CORS preflights, and an entire class
of “it works for me but not in Safari” from your future.</p>

<p>My rule of thumb: if you have session cookies and websockets, take the trade. If
you have a static front end talking to a public API with tokens, don’t bother —
you’re buying infrastructure to solve a problem you don’t have.</p>

<p>What forced your hand into a same-origin edge, if it did — cookies, or something
else?</p>]]></content><author><name></name></author><category term="articles" /><category term="load-balancing" /><category term="cloud-run" /><category term="gcp" /><category term="architecture" /><category term="cors" /><category term="websockets" /><summary type="html"><![CDATA[Putting a web app and its API behind a single same-origin load balancer deletes a whole category of browser problem. Here is what it costs, including the health check that must not move.]]></summary></entry><entry><title type="html">Build It Dark</title><link href="/articles/2026/06/27/build-it-dark.html" rel="alternate" type="text/html" title="Build It Dark" /><published>2026-06-27T00:00:00+00:00</published><updated>2026-06-27T00:00:00+00:00</updated><id>/articles/2026/06/27/build-it-dark</id><content type="html" xml:base="/articles/2026/06/27/build-it-dark.html"><![CDATA[<p>A client’s product ran on two long-lived virtual machines. One served the web
app, one served the API, both had been up for years, and both were the sort of
box where nobody was entirely sure what was installed on them. We were moving
the whole thing onto a managed container platform.</p>

<p>The two months before this went into the quality baseline — characterisation
tests, gates that could actually fail, configuration that stopped being baked into
the build. That was the <em>Earning the right to move</em> series. This is what it was
for.</p>

<p>The interesting question was never “can we build the new stack.” It was “how do
we get onto it without a cutover weekend.”</p>

<p>So we set one rule up front, and it has shaped every decision since:
<strong>everything net-new is additive and dark.</strong> Nothing new serves a real user until
a DNS record moves.</p>

<h2 id="what-dark-actually-means">What “dark” actually means</h2>

<p>Both environments — staging and production — are now stood up on the new
platform. Two services each, behind a same-origin HTTPS load balancer, with
managed certificates, a WAF policy, secrets, dedicated runtime identities, and a
deploy pipeline that gates every promotion behind a smoke test.</p>

<p>All of it reachable. None of it serving a customer.</p>

<p>Each environment got a second hostname — a parallel address that only the team
knew. The live hostnames kept pointing at the old VMs, which we did not touch at
all. Not one config change, not one restart.</p>

<p>The property that buys you is a rollback with no drama. If the new edge is wrong,
you delete a DNS record. If it’s badly wrong, you destroy the entire
infrastructure root — it’s an independently-applied unit with its own state, and
nothing live depends on it. There is no “restore the old config” step, because
the old config was never modified.</p>

<p>That is worth restating, because it’s the whole trick: <strong>the safest migration is
one where the old system never learns that a migration is happening.</strong></p>

<h2 id="dark-is-not-a-sandbox">Dark is not a sandbox</h2>

<p>Here’s the part that catches people, and it caught us enough that we put it in
the docs in bold.</p>

<p>The parallel production stack reads and writes the <em>real production database</em>.</p>

<p>That’s deliberate. The entire point of a dark stack is to validate against real
data, real volumes, real edge cases in your records — not against a seeded fixture
that agrees with your assumptions. But it means a hostname nobody has heard of,
with no traffic and no monitoring dashboard on the wall, is production.</p>

<p>We verified it rather than assumed it. A probe against the parallel production
host found a production-only user account and not the staging one; the parallel
staging host was the exact inverse. Both results written down, with the date.
Then a warning in the developer docs: treat anything you do on that host as done
to production, because it is. Use staging for anything destructive.</p>

<p>The failure mode we were heading off is obvious in hindsight and invisible in the
moment — an engineer treating an unfamiliar hostname as a scratch environment
because it feels like one.</p>

<h2 id="dark-also-means-the-background-work-has-to-be-off">Dark also means the background work has to be off</h2>

<p>This one I did not see coming.</p>

<p>The API service runs its scheduler <em>in-process</em>: a handful of timers started when
the process boots. There is no separate cron service. That’s fine when exactly one
copy of the application is running.</p>

<p>Stand up a dark production copy with a minimum instance count of one, and you now
have two processes running the same scheduled work against the same production
database and the same third-party CRM. Nobody is using the dark stack. Its
scheduler doesn’t care.</p>

<p>Worse, the application’s own coordination lock lives in a per-instance sidecar,
so it cannot arbitrate between the two stacks at all. The lock was never designed
to.</p>

<p>So the dark services ship with the scheduler explicitly disabled — and disabled
via a deliberately guarded variable, with a comment explaining exactly what turning
it on means, rather than a free tunable somebody flips while debugging.</p>

<p>The general shape: <strong>a dark copy of a service is only dark on the paths that
require a request.</strong> Anything the process does on its own initiative — timers,
queue consumers, change streams, warmers — is live the moment the container
starts. Enumerate those before you stand up the second copy, not after.</p>

<h2 id="who-is-allowed-to-apply-it">Who is allowed to apply it</h2>

<p>One more deliberate slowdown. The edge is not deployed by CI.</p>

<p>The deploy identity in this system is scoped tightly: it can update container
services and nothing else. Load balancers, networks, certificates and WAF policies
are outside its role on purpose, so a compromised or careless pipeline cannot
repoint traffic. The edge is applied by a human, by hand, following an ordered
runbook that lives next to the code.</p>

<p>That is slower, and it is the correct trade. Application deploys happen many
times a day and should be automated to the point of boredom. Edge changes happen
a handful of times a quarter, and each one can take the whole product offline.
Those two things do not want the same permissions or the same ceremony.</p>

<h2 id="what-it-costs">What it costs</h2>

<p>Being honest about the bill:</p>

<ul>
  <li><strong>You pay for two productions</strong> for the duration. Real money, for weeks.</li>
  <li><strong>You maintain two systems.</strong> Every application change during the migration has
to keep working on the old VMs <em>and</em> the new stack.</li>
  <li><strong>Nothing forces the last step.</strong> A dark stack can sit there indefinitely,
quietly accruing cost, because the thing that would create urgency — pain — is
exactly what you engineered away. That risk is real and it is managerial, not
technical.</li>
</ul>

<p>What you buy is a cutover that is a DNS change, reversible in minutes, rehearsed
against real data, with the old system still warm behind it.</p>

<p>I’ll take that trade every time. But name the cost out loud when you propose it,
because “build a second production and run it for a month” sounds extravagant
right up until you compare it to a Saturday-night migration with a rollback plan
nobody has ever executed.</p>

<h2 id="the-strange-definition-of-progress">The strange definition of progress</h2>

<p>So here is where it sits today: both environments fully served through the new
stack, on hostnames no customer uses, with the live traffic still running on the
machines we set out to replace.</p>

<p>That reads like a project that hasn’t got anywhere. In one narrow sense it
hasn’t — no DNS record has moved, and a sceptic would say nothing has actually
migrated. But the remaining risk is now one DNS record per environment, and every
other unknown is being resolved in daylight, on real data, with the old system
untouched behind it.</p>

<p>The interesting part is what that daylight keeps turning up. A deploy gate that
was validating its own input. A rejected deploy that never stopped running. A
credential quietly counting down to an expiry. An edge nobody could see. None of
those would have been visible before a cutover, and every one of them has been
cheap to fix precisely because nothing is cut over yet.</p>

<p>They’re the next five parts of this series.</p>

<p>Which is the argument for building it dark, better than anything I could say about
it in the abstract.</p>]]></content><author><name></name></author><category term="articles" /><category term="cloud-run" /><category term="gcp" /><category term="infrastructure" /><category term="opentofu" /><category term="release-engineering" /><category term="migration" /><summary type="html"><![CDATA[How to migrate a live product onto a new stack without a cutover weekend: build the whole new production alongside the old one, serving nobody, until the only remaining step is a DNS change.]]></summary></entry><entry><title type="html">You Can’t Fake a Chat Room</title><link href="/articles/2026/06/26/you-cant-fake-a-chat-room.html" rel="alternate" type="text/html" title="You Can’t Fake a Chat Room" /><published>2026-06-26T00:00:00+00:00</published><updated>2026-06-26T00:00:00+00:00</updated><id>/articles/2026/06/26/you-cant-fake-a-chat-room</id><content type="html" xml:base="/articles/2026/06/26/you-cant-fake-a-chat-room.html"><![CDATA[<p>A product I’ve been working with had a familiar setup: the business team
doubled as QA. Every release, they’d bang on the latest build, report what
broke, and only then would it reach real users.</p>

<p>The idea on the table was to formalise it. Give the business team their own
“latest, passed UAT” version of the app, leave everyone else on stable. Two
channels. It sounds reasonable. It’s the instinct most teams have.</p>

<p>It’s also the wrong mechanism for the right goal. Here’s the reasoning, because
the reasoning generalises well beyond this one product.</p>

<h2 id="staging-is-a-lie-and-chat-makes-the-lie-obvious">Staging is a lie, and chat makes the lie obvious</h2>

<p>The pitch for a separate “realer” testing version is always the same: staging
isn’t real enough, so let’s build something closer to production.</p>

<p>The trouble is that staging fidelity is a race you can’t win. You can always
make it <em>more</em> real, and it will never <em>be</em> real. There’s no real data graph, no
real concurrency, no real network conditions, no real spread of devices. For a
lot of CRUD apps you can get close enough and move on.</p>

<p>For chat you can’t.</p>

<p>Chat’s worst bugs are emergent. They only show up when real people are in real
rooms at real scale: two users typing at once, presence flapping on a flaky
mobile connection, a message broadcasting to the wrong room because of a race
nobody could trigger by hand. You don’t find those by seeding a test database
with three fake users. You find them when humans are actually talking to each
other.</p>

<p>So the more I looked at “build a realer staging version,” the more it read as
pouring effort into the wrong lever. You can polish staging forever and still
ship the bug.</p>

<h2 id="the-goal-was-right-the-mechanism-was-wrong">The goal was right; the mechanism was wrong</h2>

<p>Strip the idea back and the goal is sound: <em>let a small, trusted group use the
latest version against real data before everyone else gets it.</em></p>

<p>That’s a good goal. The problem was the mechanism. “A separate version” means
two builds of the app running at once, and the moment you have two server
versions you have to decide what they talk to.</p>

<p>Share one production database and you’ve signed up for both versions agreeing on
the data shape at all times — every migration backward-compatible, forever. Give
them separate databases and your testers aren’t on real data any more, which was
the entire point.</p>

<p>That’s the wall. And it’s a one-way door: get the migration discipline wrong on
a live database and you don’t get to undo it.</p>

<p>The way out is to stop thinking about versions at all.</p>

<h2 id="one-version-different-switches">One version, different switches</h2>

<p>The industry settled this a while ago, and the answer is feature flags.</p>

<p>A feature flag is just an on/off switch in the database that decides who can see
a feature, evaluated without a redeploy. The code ships to everyone. It stays
asleep until you flip the switch, and you choose who the switch is on for.</p>

<p>That dissolves the whole problem. There’s only one version of the app, so
there’s no two-versions-fighting-over-one-database. The test group is on the
real product, the real data, real chat with real users — they’re simply the only
ones who can see the new thing. When it’s solid, you widen the switch. When it
breaks, you flip it off. Nobody outside the group ever knew.</p>

<p>Take emoji reactions on chat messages as the worked example. New feature, you
want only the internal team to see it first.</p>

<p>The flag is one record:</p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{</span> <span class="nl">name</span><span class="p">:</span> <span class="dl">"</span><span class="s2">message_reactions</span><span class="dl">"</span><span class="p">,</span> <span class="nx">enabled</span><span class="p">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">role_whitelist</span><span class="p">:</span> <span class="p">[</span><span class="dl">"</span><span class="s2">staff</span><span class="dl">"</span><span class="p">]</span> <span class="p">}</span>
</code></pre></div></div>

<p>“Reactions are live, but only for staff.” The server is the part that actually
enforces it. When someone tries to react, the server asks the flag before doing
anything:</p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">async</span> <span class="kd">function</span> <span class="nx">add_reaction</span><span class="p">(</span><span class="nx">data</span><span class="p">,</span> <span class="nx">user</span><span class="p">,</span> <span class="nx">socket</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">isEnabled</span><span class="p">(</span><span class="dl">"</span><span class="s2">message_reactions</span><span class="dl">"</span><span class="p">,</span> <span class="nx">user</span><span class="p">))</span> <span class="p">{</span>
    <span class="k">return</span> <span class="nx">callback</span><span class="p">({</span> <span class="na">ok</span><span class="p">:</span> <span class="kc">false</span><span class="p">,</span> <span class="na">error</span><span class="p">:</span> <span class="dl">"</span><span class="s2">not_available</span><span class="dl">"</span> <span class="p">});</span>
  <span class="p">}</span>
  <span class="c1">// ...save the reaction, broadcast it to the room...</span>
<span class="p">}</span>
</code></pre></div></div>

<p>The client just hides the button when the flag is off. But the <em>server</em> is the
bouncer — otherwise a clever user could flip their own switch. The client is for
looks; the server decides.</p>

<h2 id="widening-without-breaking-anyone">Widening without breaking anyone</h2>

<p>The interesting part is the rollout. Once the internal team is happy, you want
to let in 10% of real users, then more. The naive version looks like this, and
it’s a trap:</p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">if</span> <span class="p">(</span><span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">()</span> <span class="o">*</span> <span class="mi">100</span> <span class="o">&lt;</span> <span class="nx">flag</span><span class="p">.</span><span class="nx">rollout_percentage</span><span class="p">)</span> <span class="p">{</span> <span class="p">...</span> <span class="p">}</span>  <span class="c1">// don't</span>
</code></pre></div></div>

<p>That re-rolls the dice on every check. A user at 10% would see reactions,
refresh, lose them, refresh, get them back. For a chat feature, getting kicked
out of a conversation mid-sentence is exactly the bug you can’t ship.</p>

<p>The fix is to give each user a permanent number for that flag and compare
against it:</p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">crypto</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="dl">"</span><span class="s2">crypto</span><span class="dl">"</span><span class="p">);</span>

<span class="kd">function</span> <span class="nx">inRolloutBucket</span><span class="p">(</span><span class="nx">flagName</span><span class="p">,</span> <span class="nx">user</span><span class="p">,</span> <span class="nx">percentage</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">if</span> <span class="p">(</span><span class="nx">percentage</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
  <span class="k">if</span> <span class="p">(</span><span class="nx">percentage</span> <span class="o">&gt;=</span> <span class="mi">100</span><span class="p">)</span> <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>

  <span class="kd">const</span> <span class="nx">hash</span> <span class="o">=</span> <span class="nx">crypto</span><span class="p">.</span><span class="nx">createHash</span><span class="p">(</span><span class="dl">"</span><span class="s2">sha256</span><span class="dl">"</span><span class="p">)</span>
    <span class="p">.</span><span class="nx">update</span><span class="p">(</span><span class="s2">`</span><span class="p">${</span><span class="nx">flagName</span><span class="p">}</span><span class="s2">:</span><span class="p">${</span><span class="nx">user</span><span class="p">.</span><span class="nx">id</span><span class="p">}</span><span class="s2">`</span><span class="p">)</span>
    <span class="p">.</span><span class="nx">digest</span><span class="p">(</span><span class="dl">"</span><span class="s2">hex</span><span class="dl">"</span><span class="p">);</span>

  <span class="kd">const</span> <span class="nx">bucket</span> <span class="o">=</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nx">hash</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">8</span><span class="p">),</span> <span class="mi">16</span><span class="p">)</span> <span class="o">%</span> <span class="mi">100</span><span class="p">;</span>  <span class="c1">// stable 0–99 for this user + flag</span>
  <span class="k">return</span> <span class="nx">bucket</span> <span class="o">&lt;</span> <span class="nx">percentage</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Same user, same flag, same answer every time. And because it’s a fixed number,
widening only ever <em>adds</em> people. Everyone in at 10% is still in at 25% — you
never yank the feature out from under someone who already has it. Putting the
flag name in the hash matters too: it means the same unlucky users aren’t the
guinea pigs for every feature you ship.</p>

<p>The full evaluation is small:</p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">function</span> <span class="nx">isEnabled</span><span class="p">(</span><span class="nx">flag</span><span class="p">,</span> <span class="nx">user</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">flag</span> <span class="o">||</span> <span class="o">!</span><span class="nx">flag</span><span class="p">.</span><span class="nx">enabled</span><span class="p">)</span> <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>                               <span class="c1">// kill switch wins</span>
  <span class="k">if</span> <span class="p">(</span><span class="nx">flag</span><span class="p">.</span><span class="nx">role_whitelist</span><span class="p">?.</span><span class="nx">some</span><span class="p">(</span><span class="nx">r</span> <span class="o">=&gt;</span> <span class="nx">user</span><span class="p">.</span><span class="nx">role</span><span class="p">.</span><span class="nx">includes</span><span class="p">(</span><span class="nx">r</span><span class="p">)))</span> <span class="k">return</span> <span class="kc">true</span><span class="p">;</span> <span class="c1">// the test group</span>
  <span class="k">return</span> <span class="nx">inRolloutBucket</span><span class="p">(</span><span class="nx">flag</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span> <span class="nx">user</span><span class="p">,</span> <span class="nx">flag</span><span class="p">.</span><span class="nx">rollout_percentage</span><span class="p">);</span>       <span class="c1">// everyone else</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Three behaviours, and they’re the three worth writing tests for. The kill switch
beats everything — flag off means off, even for staff, even at 100%. The
whitelist lets the test group in regardless of percentage. The rollout is stable
and only ever widens. Pin those three down and you can rewrite the hash later
without fear.</p>

<h2 id="the-principle">The principle</h2>

<p>Don’t try to make staging real. Make production reversible.</p>

<p>A more realistic test environment is a depreciating asset — it costs more every
year and never reaches the thing it’s imitating. A feature flag is a few days of
work and it changes the question you’re asking. Instead of “did we catch every
bug before release,” it’s “can we contain and undo a bug after release.” For
real-time features, where the worst bugs only exist in production anyway, that’s
the only question that was ever going to hold up.</p>

<p>The business team still tests the latest version against real data. They’re just
the people with the switch flipped on, not the people on a different island.</p>]]></content><author><name></name></author><category term="articles" /><category term="release-engineering" /><category term="feature-flags" /><category term="testing" /><summary type="html"><![CDATA[Why feature flags beat a more realistic staging environment when the risky feature is real-time chat.]]></summary></entry><entry><title type="html">Build Once, Run Anywhere</title><link href="/articles/2026/06/20/build-once-run-anywhere.html" rel="alternate" type="text/html" title="Build Once, Run Anywhere" /><published>2026-06-20T00:00:00+00:00</published><updated>2026-06-20T00:00:00+00:00</updated><id>/articles/2026/06/20/build-once-run-anywhere</id><content type="html" xml:base="/articles/2026/06/20/build-once-run-anywhere.html"><![CDATA[<p>The last stretch of baseline work was the least interesting to describe and the
most load-bearing: a handful of changes that had to exist before the migration
could start at all.</p>

<p>The clearest one was configuration.</p>

<h2 id="the-build-was-baking-the-environment-in">The build was baking the environment in</h2>

<p>The web app read twelve public configuration values — API URLs, upload targets,
authentication client settings — through the build tool’s compile-time
environment. Which means the bundler <em>inlines</em> them. They stop being
configuration the moment the build finishes; they’re constants in the artefact.</p>

<p>That is completely fine right up until you want a deploy pipeline that builds once
and promotes the same artefact through environments.</p>

<p>And you do want that. It’s the single property that makes a promotion meaningful:
the thing running in production is byte-identical to the thing that passed in
staging. Rebuild per environment and you’ve thrown that away — you’re now
promoting a <em>recipe</em>, and hoping it produces the same result twice, on a different
day, with a fresh dependency resolution.</p>

<p>With build-time inlining, the pipeline I wanted was not merely awkward. It was
impossible. A promotion would have meant a rebuild, and a rebuild is a new
artefact.</p>

<p>So the values moved to runtime resolution — read from the process environment when
the server starts, rather than substituted when the bundle is built. The app runs
on a Node adapter, so this was available; it just hadn’t been used.</p>

<p>The test that proves it is the one I’d insist on: <strong>a clean production build with
none of the configuration set at all.</strong> If the build succeeds with an empty
environment, nothing is baked in. That’s a far better assertion than any test of
what the values resolve to.</p>

<h2 id="fail-loud-at-boot-not-quietly-per-request">Fail loud at boot, not quietly per request</h2>

<p>The obvious way to do runtime config is to read the variable where you need it.
Then a missing value gives you <code class="language-plaintext highlighter-rouge">undefined</code> interpolated into a URL, and a request
that fails at 3am with a stack trace pointing at a fetch call.</p>

<p>Instead: one module resolves every value once, and a server startup hook validates
the required ones. On a deployed artefact, a missing required key <strong>throws at
boot</strong> — the server refuses to start. Locally and in tests it warns.</p>

<p>This is the same instinct as failing closed in a security gate, applied to
configuration. A misconfigured service that starts is worse than one that doesn’t,
because it will serve wrong behaviour for hours before anyone connects the
symptoms to a deploy. A service that refuses to boot tells you within seconds,
with the key name.</p>

<p>Two details worth stealing:</p>

<p><strong>Empty string normalises to undefined.</strong> Otherwise validation and consumption
disagree — the key is “present” so validation passes, and then something
interpolates an empty string into a URL. Same class of bug, one layer along.</p>

<p><strong>Detect “am I a deployed artefact” from a build-time flag, not the environment
name.</strong> The obvious check is whether the environment variable says production. But
that variable isn’t guaranteed to be set on a container platform, so the check
silently degrades to the lenient branch in exactly the place you wanted it strict.
A flag baked in by the build tool is a reliable “this is a built artefact” signal
because nothing at runtime can be missing it.</p>

<p>That’s a general trap: <strong>any strictness that keys off an environment variable can
be disabled by that variable being absent.</strong> If the strict mode matters, key it off
something that cannot go missing.</p>

<h2 id="the-other-two">The other two</h2>

<p>Two smaller changes landed in the same stretch, both of which looked pointless at
the time.</p>

<p><strong>A health endpoint in each service.</strong> Nothing needed one yet. Weeks later, the
container platform’s readiness probe and the deploy pipeline’s smoke test both
depended on it entirely — and, as it turned out, the deploy gate’s correctness
depended on exactly what it reported. Adding it early meant the migration never
had to introduce a new endpoint and a new deploy mechanism in the same change.</p>

<p><strong>Pinning the runtime version.</strong> One file naming the version, the package manifest
declaring the range, and CI deriving its version from that file rather than
hardcoding it. Trivial. It means the container base image, the CI runner and every
developer’s machine are provably the same major version — so “works locally,
fails in the container” stops being on the list of things a migration failure
could be.</p>

<p>Both are examples of the same move: <strong>reduce the number of variables that change
at once.</strong> A migration is a large change to the environment. Every unrelated
difference you can eliminate beforehand is a hypothesis you don’t have to test
during a cutover.</p>

<h2 id="what-the-baseline-was-for">What the baseline was for</h2>

<p>That’s the end of the baseline, and the migration starts.</p>

<p>Runtime config is what makes build-once-promote-the-digest possible, which is the
model the deploy pipeline gets built around. The health endpoints become the smoke
test the deploy gate depends on — and, as it turns out, the place I’d later find
the most embarrassing bug of the whole project. The frozen tests are how we’ll
know the behaviour hasn’t shifted. The gates are what make every infrastructure
pull request produce a real signal.</p>

<p>None of it was visible to a user. All of it was load-bearing.</p>

<p>The one-line version, if you want it: <strong>the work that makes a migration boring
happens before the migration, and it mostly consists of building instruments that
can tell the difference between working and merely quiet.</strong></p>

<p>What happened next has its own series.</p>

<p>If you’re staring down a platform move: what in your build is environment-specific
right now, and could you promote an artefact from staging to production without
rebuilding it?</p>]]></content><author><name></name></author><category term="articles" /><category term="twelve-factor" /><category term="release-engineering" /><category term="ci-cd" /><category term="configuration" /><category term="migration" /><summary type="html"><![CDATA[Twelve config values inlined at build time made every image environment-specific — which quietly makes 'promote the exact artefact you tested' impossible. The unglamorous changes that had to land before a migration could start.]]></summary></entry><entry><title type="html">The Flaky Test Was Telling the Truth</title><link href="/articles/2026/06/13/the-flaky-test-was-telling-the-truth.html" rel="alternate" type="text/html" title="The Flaky Test Was Telling the Truth" /><published>2026-06-13T00:00:00+00:00</published><updated>2026-06-13T00:00:00+00:00</updated><id>/articles/2026/06/13/the-flaky-test-was-telling-the-truth</id><content type="html" xml:base="/articles/2026/06/13/the-flaky-test-was-telling-the-truth.html"><![CDATA[<p>We added an end-to-end login test to the mobile app — a real emulator, a real
install, a deep link back into the app, all the way to the authenticated screen.</p>

<p>It was intermittently red. Worse, it was red on pull requests that had nothing to
do with it, including one that only touched CI configuration and merely inherited
the workflow.</p>

<p>That’s the moment the team’s patience runs out, and the pressure to quarantine it
becomes very reasonable-sounding. Mark it non-blocking, move on, revisit later.</p>

<p>We didn’t, and it took two fixes, and both of them were real bugs.</p>

<h2 id="bug-one-a-race-that-real-users-mostly-dodged">Bug one: a race that real users mostly dodged</h2>

<p>The deep-link login callback did something that looks entirely sensible: before
navigating into the app, check that we’re currently on the login screen.</p>

<p>On a cold start, the app’s initialisation finds no token and redirects to the
login screen — <strong>asynchronously</strong>. Meanwhile the deep link fires almost
immediately, stores the token, and connects. When the callback’s continuation ran
before the redirect had settled, the path check was false, navigation never
happened, and the app sat on the unauthenticated screen holding a perfectly valid
session.</p>

<p>Real users rarely hit it. They tap through a web login, spend a few seconds there,
and come back to an app that has long since settled on the login screen. The
window is small.</p>

<p>The test hit it constantly, because clearing all state and immediately opening the
link compresses exactly the timing that real usage spreads out.</p>

<p>The fix removed the assumption rather than the race: a login-callback deep link
exists <em>only</em> to complete a login, so it now always navigates on success. No
dependence on where the app happened to be.</p>

<p><strong>That is a genuine defect that users would hit occasionally and never report
reproducibly.</strong> “It said I was logged in but showed me the login page — I just
restarted it.” Nobody files that ticket. It would have lived in the app
indefinitely, because the only thing capable of reporting it reliably was the test
everyone wanted to disable.</p>

<h2 id="bug-two-wed-given-the-machine-too-much">Bug two: we’d given the machine too much</h2>

<p>With the race fixed, the test failed again — earlier, at step one, before the deep
link was even involved.</p>

<p>The failure screenshot showed the device launcher with a system dialog: <em>process
system isn’t responding</em>. Not our app. The operating system.</p>

<p>The boot log had been saying so all along: the emulator was configured with more
virtual CPUs than the nested virtualisation on the CI runner can actually
schedule. Cold boot plus install plus web-view launch created enough contention
to make the OS itself unresponsive, which backgrounded the app, so the login
screen never painted.</p>

<p>The fix was to give it <strong>fewer</strong> cores, not more, plus extra RAM headroom the
runner had spare.</p>

<p>I want to dwell on that for a second, because the instinct — mine included — is
that a resource-starved test needs more resources. Here, overcommitting the CPU
<em>was</em> the starvation. More cores would have made it worse, and it’s the kind of
change that looks so obviously correct in review that nobody questions it.</p>

<p>So the comment in the config records the actual failure mode, in words, so the
next person to see a slow emulator doesn’t cheerfully bump the cores back up.
<strong>Write the cause into the config, not just the value.</strong> A bare number invites
someone to tune it; a number with a one-line explanation of what breaks invites
them to think.</p>

<p>There was a second-order fix too. The flow dismissed the startup dialog once, up
front. The observed failure had a <em>second</em> dialog appear during the subsequent
wait, which nothing was watching for. Wrapping dismiss-and-wait in a retry handles
a recurring dialog instead of assuming one is all you get.</p>

<h2 id="what-i-take-from-it">What I take from it</h2>

<p><strong>“Flaky” describes your response, not the test.</strong> It’s a label we apply when a
failure isn’t reproducible on demand, and it does something quietly corrosive: it
reclassifies a signal as noise, and once something is noise you stop reading it.</p>

<p>Nearly every flake I’ve chased has turned out to be a real race, a real resource
limit, or a real ordering assumption. The test isn’t unreliable. The system is
non-deterministic in a way you haven’t characterised yet, and the test is the only
thing that noticed.</p>

<p>That said, a flaky test genuinely is worse than no test while it’s flaky — not
because it’s wrong, but because it trains the team to re-run rather than read. Two
red-then-green cycles and the reflex is set. So it does have to be fixed
<em>urgently</em>. The mistake is fixing it by making it quieter instead of by finding
out what it’s saying.</p>

<p>One honest caveat: a single green run doesn’t prove a flake is gone. That needs
several consecutive clean runs on the main branch, which is an observation you
schedule rather than something a merge can deliver. We tracked that separately and
left the box unticked, because ticking it would have been a lie.</p>

<p>Also worth saying: this one didn’t reproduce on any developer machine. It was a
nested-virtualisation cold-boot problem specific to the CI runner. The evidence
was a screenshot and a boot log — which is a good argument for capturing both from
every failed end-to-end run, because for an entire category of failure they’re the
only evidence you will ever get.</p>

<p>What’s the last test your team quarantined, and does anyone remember why?</p>]]></content><author><name></name></author><category term="articles" /><category term="testing" /><category term="e2e" /><category term="mobile" /><category term="ci-cd" /><category term="flaky-tests" /><summary type="html"><![CDATA[An intermittent mobile login test was going red on unrelated pull requests. Underneath it were two genuine defects — a navigation race in the app, and a CI machine we'd overprovisioned into failure.]]></summary></entry></feed>