<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Circuit-Breaker on words on sand</title><link>https://drone-ah.com/tags/circuit-breaker/</link><description>Recent content in Circuit-Breaker on words on sand</description><generator>Hugo</generator><language>en</language><lastBuildDate>Wed, 06 May 2026 15:22:52 +0100</lastBuildDate><atom:link href="https://drone-ah.com/tags/circuit-breaker/index.xml" rel="self" type="application/rss+xml"/><item><title>What's Circuit Breaker?</title><link>https://drone-ah.com/2026/05/06/whats-circuit-breaker/</link><pubDate>Wed, 06 May 2026 10:53:27 +0100</pubDate><guid>https://drone-ah.com/2026/05/06/whats-circuit-breaker/</guid><description>&lt;p>I&amp;rsquo;d not been interviewed very often. For my first job, sure, I sent around my CV
to a bunch of places and did a bunch of interviews.&lt;/p>
&lt;p>I then started my own company and ran that for nearly two decades, everything
largely self-taught. After that, because of the peculiar shape of my CV, and
&amp;ldquo;falling between a lot of stools&amp;rdquo; as a friend pointed out, interviews were&amp;hellip;
tricky!&lt;/p>
&lt;p>I remember one such interview a few years ago. He was good at diffusing any
anxiety and it was a pretty relaxed interview. He wanted to know if I knew
architectural design patterns - a term I hadn&amp;rsquo;t heard before. He gave me
examples, circuit breaker, pub / sub and a third one I can&amp;rsquo;t remember anymore. I
recognised pub / sub and the other one I think - but was not aware of circuit
breaker. He explained it to me - something about reducing the risk of a
downstream service failing.&lt;/p></description><content:encoded><![CDATA[<p>I&rsquo;d not been interviewed very often. For my first job, sure, I sent around my CV
to a bunch of places and did a bunch of interviews.</p>
<p>I then started my own company and ran that for nearly two decades, everything
largely self-taught. After that, because of the peculiar shape of my CV, and
&ldquo;falling between a lot of stools&rdquo; as a friend pointed out, interviews were&hellip;
tricky!</p>
<p>I remember one such interview a few years ago. He was good at diffusing any
anxiety and it was a pretty relaxed interview. He wanted to know if I knew
architectural design patterns - a term I hadn&rsquo;t heard before. He gave me
examples, circuit breaker, pub / sub and a third one I can&rsquo;t remember anymore. I
recognised pub / sub and the other one I think - but was not aware of circuit
breaker. He explained it to me - something about reducing the risk of a
downstream service failing.</p>
<p>It made sense - but I couldn&rsquo;t remember any instance where I&rsquo;d done that and I
said as much.</p>
<p>No big deal! We moved on.</p>
<p>As you may have noticed from my recent flurry of posts, I&rsquo;ve been going through
a bit of an excavation of all things kraya, and discovering little nuggets that
I&rsquo;d forgotten all about.</p>
<p>Claude code went through all of my emails, all the code repositories and put
together interesting things I had done. The purpose was mainly to pick out
things that could be good blog posts, stories, or just reminders.</p>
<p>Claude had found two circuit breakers.</p>
<p>The first one was built by the seat of my pants in 2004. There was an active
marketing campaign on megabus and the system was struggling. I&rsquo;d plumbed the
depths of the tech stack - the web servers, the database server to get every
last ounce of performance out of the system.</p>
<p>What I really needed was to slow down the deluge of people coming into the
site - just a little bit. I needed to prevent the snowball effect, and I tried a
simple way to achieve it. I wrote the following around my 23rd birthday.</p>
```php
$timestamp = time() - 120;
$sTimestamp = date("d-F-Y H:i");
$sql = "SELECT count(*) FROM tSearches WHERE Script_Start > '$sTimestamp' AND Script_End IS NULL;";

$numSearches = $dbh->getOne($sql);
if ($numSearches > 10)
    sleep(5);

$numSearches = $dbh->getOne($sql);
if ($numSearches > 10)
    sleep(5);

$numSearches = $dbh->getOne($sql);
if ($numSearches > 10)
    sleep(5);
```
<p>(The eagle eyed among you might notice a bug in the above code. It wasn&rsquo;t
resolved for years. Coding live on a production system tends to create bugs. See
if you can find it before reading on.)</p>
<p>(Regular readers may also remember a part of this story from
<a href="https://drone-ah.com/simple-wins.md">I Know People Like You</a>)</p>
<p>The system already tracked searches - so I just needed to check it.</p>
<p>This bit of code checks to see how many of the searches that started in the last
two minutes were incomplete. Except that&rsquo;s not what it did - I forgot to
actually use <code>$timestamp</code> so it only checked the current minute&rsquo;s worth.</p>
<p>I considered failing and letting the user retry manually - but I didn&rsquo;t want to
force the user to take action unless absolutely necessary. This one waited up to
15 seconds and then let the search happen anyway.</p>
<p>If the user was still waiting after 15 seconds, might as well try and do a
search and see what happens. In hindsight, it might have been better to fail at
that point. If there were too many searches after 15 seconds, the database
server was likely already snowballing.</p>
<p>This bit of code survived through to the end of the PHP codebase apart from
minor tweaks. The Java version had layers of circuit breakers. Session limits,
rate limiters and threadpool configuration for scaling up. None of it though,
was called a circuit breaker - not by me or by the team.</p>
<p>So, have I built a circuit breaker? Thinking back, what threw me off was the
wording. I had the feeling that the circuit breaker would &ldquo;protect&rdquo; another
service.</p>
<p>In my mind, the database wasn&rsquo;t another service - it was a part of the same
service.</p>
]]></content:encoded></item></channel></rss>