<?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: Félix</title>
    <description>The latest articles on DEV Community by Félix (@fmunoz).</description>
    <link>https://dev.to/fmunoz</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%2F4124648%2F51184518-4593-41c7-aa86-8592fa91d0c4.png</url>
      <title>DEV Community: Félix</title>
      <link>https://dev.to/fmunoz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fmunoz"/>
    <language>en</language>
    <item>
      <title>Where 28 seconds go</title>
      <dc:creator>Félix</dc:creator>
      <pubDate>Wed, 25 Nov 2026 10:55:47 +0000</pubDate>
      <link>https://dev.to/monei/where-28-seconds-go-320</link>
      <guid>https://dev.to/monei/where-28-seconds-go-320</guid>
      <description>&lt;p&gt;Our median CI job runs for about a minute, and before it runs it waits 28 seconds for a machine that did not exist when the job was queued. That wait is a third of what the developer sees.&lt;/p&gt;

&lt;p&gt;This is the last of five posts about running each GitHub Actions job on its own EC2 spot instance. The &lt;a href="https://dev.to/monei/one-job-one-instance-ephemeral-ec2-runners-for-github-actions-4no9"&gt;first post&lt;/a&gt; covers the design. This one is about the boot: what it was, what it is, what we refused to pay to make it shorter, and what the machine is worth once it is up.&lt;/p&gt;

&lt;h2&gt;
  
  
  The version that booted in a minute
&lt;/h2&gt;

&lt;p&gt;The first runner image was stock Ubuntu. The boot script installed everything on every boot: packages, the GitHub runner, its dependencies. It worked on day one, and from queue to start it took 63 to 68 seconds:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Phase&lt;/th&gt;
&lt;th&gt;Seconds&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;webhook to &lt;code&gt;RunInstances&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;EC2 starts the instance&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;OS boot and cloud-init&lt;/td&gt;
&lt;td&gt;15–20&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;apt-get install&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;runner download and its dependencies&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;runner connects, GitHub assigns&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;More than half of that was downloading the same things again. For a job that runs 51 seconds, the machine took longer to arrive than to do the work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bake it once
&lt;/h2&gt;

&lt;p&gt;The fix is the obvious one: build an image with everything already on it. A pipeline rebuilds it every week from a shell script in the repository and publishes the new image ID to a parameter that the launch template reads at each launch. A rebuild rolls out with no deploy, and a bad image is rolled back by rewriting one parameter.&lt;/p&gt;

&lt;p&gt;What goes in the image came from reading the step times of real jobs, one item at a time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The runner, at its latest version.&lt;/strong&gt; A runner that is behind updates itself at start.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Node, in the runner's tool cache and on the &lt;code&gt;PATH&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;actions/setup-node&lt;/code&gt; finds it and skips its download.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The package manager, in corepack's cache.&lt;/strong&gt; &lt;code&gt;corepack enable&lt;/code&gt; needs no network.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The system libraries a headless browser needs.&lt;/strong&gt; Installing them with apt took about 20 seconds in every browser job; the step went from 41 seconds to 21.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The actions themselves.&lt;/strong&gt; Every job downloads the same few actions from GitHub. The runner has a little-known setting for a local archive directory:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;ACTIONS_CACHE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/opt/ci-runner/actions
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="nb"&gt;read&lt;/span&gt; -r REPO SHA&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="nv"&gt;DIR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$ACTIONS_CACHE/$(echo "&lt;/span&gt;&lt;span class="nv"&gt;$REPO&lt;/span&gt;&lt;span class="s2"&gt;" | tr / _)"&lt;/span&gt;
  mkdir -p &lt;span class="s2"&gt;"$DIR"&lt;/span&gt;
  curl -fsSL --proto &lt;span class="s1"&gt;'=https'&lt;/span&gt; -o &lt;span class="s2"&gt;"$DIR/$SHA.tar.gz"&lt;/span&gt; &lt;span class="s2"&gt;"https://github.com/$REPO/archive/$SHA.tar.gz"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'ACTIONS'&lt;/span&gt;
actions/checkout &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;commit sha&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
actions/setup-node &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;commit sha&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
actions/upload-artifact &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;commit sha&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
ACTIONS
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE=$ACTIONS_CACHE"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; /home/runner/actions-runner/.env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A workflow that pins one of those commits gets it from disk. Any other version downloads as usual.&lt;/p&gt;

&lt;p&gt;The build also switches off what a fresh Ubuntu does on its own at boot: the apt timers, unattended upgrades, snapd. Each held a lock or burned CPU in the first seconds.&lt;/p&gt;

&lt;p&gt;One thing went the other way. On GitHub's runners a dependency cache saves time. On ours a cold install is as fast as a cache restore, and saving the cache afterwards uploads slowly from AWS to GitHub. We removed the cache step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the 28 seconds go
&lt;/h2&gt;

&lt;p&gt;We wanted to know what was left, so the image now reports it. A hook that runs at the start of every job prints the boot milestones into the job log, in seconds since the kernel started:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Boot timings (seconds since kernel boot):
  cloud-init local: +5 s
  network online:   +9 s
  cloud-config:     +10 s
  boot script:      +10 s
  runner started:   +12 s
  runner connected: +15 s
  job received:     +16 s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We read 22 recent jobs and joined them with the launch time the control plane records. Three of them ran on an instance that was already booting for another job, so they have no boot of their own to measure. The other 19 give this:&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%2F8946refq9ceh71wwfc56.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%2F8946refq9ceh71wwfc56.png" alt="Queue to start, 27 s at the median of 19 jobs: 8 s control plane, 5 s EC2 start, 8 s kernel and cloud-init until the network is up, 2 s boot script, 3 s runner connect, 1 s job assignment" width="800" height="268"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The sample's median is 27 seconds, one under the week's 28.&lt;/p&gt;

&lt;p&gt;Three things surprised us.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Eight seconds pass before EC2 hears about the job.&lt;/strong&gt; The webhook, an asynchronous hand-off to the worker, a call to GitHub for the runner registration, then &lt;code&gt;RunInstances&lt;/code&gt;. It is the largest piece we fully control, and we had never looked at it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The operating system is the biggest piece: eight seconds from kernel to network.&lt;/strong&gt; Most of it is cloud-init waiting for the network. Nothing we baked into the image touches it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The runner itself is quick.&lt;/strong&gt; Two seconds to start, three to connect, one for GitHub to hand it a job. Six seconds for everything GitHub-specific.&lt;/p&gt;

&lt;p&gt;So the image work took the boot from 65 seconds to 28, and none of what remains is downloading. Whole-second timestamps mean each phase can be off by one, and 19 jobs is a small sample. It is enough to say where not to look.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we refused to pay for
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A warm pool.&lt;/strong&gt; One idle instance per pool would start the first job of a burst in 2 to 5 seconds. The second job of the same push would still boot its own. The idle hours cost about as much per month as eight thousand of our jobs, for a saving nobody has asked for.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fast snapshot restore.&lt;/strong&gt; A new instance reads its disk lazily from snapshot storage. AWS sells a way to skip that, priced per hour per zone, at a monthly cost many times what the runners themselves cost.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An image per repository.&lt;/strong&gt; Baking each repository's dependencies would skip its install step, 5 to 10 seconds of a 45 second job. It would also mean an image, a launch template and a pool per repository, and a bigger image loads more slowly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Launching ahead.&lt;/strong&gt; A job that depends on others could have its machine started early. We designed it and then found that GitHub does not create such a job until the jobs it depends on have finished. There is no job to launch for until it is already waiting.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What the machine is worth
&lt;/h2&gt;

&lt;p&gt;The point of owning the boot was to choose the machine. Same commit, median of two runs:&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%2Fvbv7sx482apn4s038ygl.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%2Fvbv7sx482apn4s038ygl.png" alt="Job seconds on GitHub ubuntu-latest and on our 2, 4 and 8 vCPU runners, for five test suites" width="799" height="423"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our 2 vCPU runner is about as fast as GitHub's. Eight vCPUs make the same suites 3 to 5 times faster, because the work was parallel and had been waiting for cores.&lt;/p&gt;

&lt;p&gt;That raised a question we had answered before by habit: do we still need to shard? We measured it. On the same instance type, running a suite as one job instead of three shards used 7 instances instead of 11 and cost less per run, and it ended the pull request 75 seconds later. We kept the shards. A minute of every developer's wait is worth more than a cent and a half.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it does not do
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;It does not start in two seconds.&lt;/strong&gt; GitHub's hosted runners do. Jobs of a few seconds stayed there.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It does not shrink the eight seconds of OS boot.&lt;/strong&gt; A lighter base image is the untried lever.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The profile is a snapshot.&lt;/strong&gt; Nineteen jobs on one day, on the newest image. The hook keeps printing, so the next reading is one script away.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What we took from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Profile the boot before buying your way around it.&lt;/strong&gt; Baking the image was worth 37 seconds and cost nothing to run. The next few seconds are priced in idle machines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Put the measurement in the product.&lt;/strong&gt; The timings are in every job log, so nobody has to set up a benchmark to see a regression.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measure the habit too.&lt;/strong&gt; Sharding was the right call on 2 vCPUs and is still the right call on 8, and now we know why.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>ec2</category>
      <category>githubactions</category>
      <category>performance</category>
    </item>
    <item>
      <title>A spot instance can vanish mid-job</title>
      <dc:creator>Félix</dc:creator>
      <pubDate>Wed, 25 Nov 2026 10:55:33 +0000</pubDate>
      <link>https://dev.to/monei/a-spot-instance-can-vanish-mid-job-9ml</link>
      <guid>https://dev.to/monei/a-spot-instance-can-vanish-mid-job-9ml</guid>
      <description>&lt;p&gt;We wrote the code that re-runs a CI job when AWS takes its spot instance away, and set up a test to interrupt one on purpose. AWS interrupted the test job for real before we could, and the re-run did not happen.&lt;/p&gt;

&lt;p&gt;This is the fourth of five posts about running each GitHub Actions job on its own EC2 spot instance. The &lt;a href="https://dev.to/monei/one-job-one-instance-ephemeral-ec2-runners-for-github-actions-4no9"&gt;first post&lt;/a&gt; covers the design. Spot instances are why a job costs a fraction of a cent, and the price is that AWS can reclaim one with two minutes' warning. This post is about making that invisible to the person waiting for a green check. It took three attempts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Attempt one: mark it, then re-run it
&lt;/h2&gt;

&lt;p&gt;The plan was simple, and half of it worked.&lt;/p&gt;

&lt;p&gt;AWS publishes the warning as an event. We route it to the worker, which finds the job running on that instance and marks it as interrupted. Two minutes later the instance is gone and the job fails. GitHub sends its &lt;code&gt;completed&lt;/code&gt; event, the worker sees a failed job with the mark, and asks GitHub to re-run it. One re-run only: the re-run is a second attempt, and an interrupted second attempt stays failed.&lt;/p&gt;

&lt;p&gt;We could not ask GitHub for the re-run at the moment of the warning, because GitHub refuses to re-run a job that is still running. So everything hung on the job failing promptly.&lt;/p&gt;

&lt;h2&gt;
  
  
  What actually happened
&lt;/h2&gt;

&lt;p&gt;To test it we pushed a job that sleeps for six minutes, meaning to send it a fake interruption with AWS Fault Injection Service. Two minutes after the instance launched, AWS reclaimed it for real.&lt;/p&gt;

&lt;p&gt;The first half worked: the warning arrived and the job was marked. Then:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;13:13 UTC: the warning.&lt;/li&gt;
&lt;li&gt;13:15: the instance is terminated.&lt;/li&gt;
&lt;li&gt;13:26: GitHub ends the job as &lt;code&gt;cancelled&lt;/code&gt;, with "The job has exceeded the maximum execution time of 10m0s".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For eleven minutes after the machine had ceased to exist, GitHub showed the job as in progress. It ended only because our test job had a ten minute timeout. Our real jobs use GitHub's default, which is six hours.&lt;/p&gt;

&lt;p&gt;Two things were wrong. The runner process died with the instance and never told GitHub anything, and GitHub does not notice a silent runner on any timescale that matters. And when the job did end, it ended as &lt;code&gt;cancelled&lt;/code&gt;, not &lt;code&gt;failure&lt;/code&gt;, so our re-run condition did not match.&lt;/p&gt;

&lt;p&gt;A spot interruption on a real pull request would have left a job spinning until someone cancelled it by hand.&lt;/p&gt;

&lt;h2&gt;
  
  
  Attempt two: tell the runner
&lt;/h2&gt;

&lt;p&gt;The two minute warning is the only window in which anything on the instance can act, and nothing on our image used it. So the image got a small service that polls the instance metadata for the interruption notice and stops the runner:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# IMDS holds the URL of the EC2 instance metadata service, set earlier in the script.&lt;/span&gt;
&lt;span class="nv"&gt;NOTICED&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; -z &lt;span class="s2"&gt;"$NOTICED"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="nv"&gt;TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;curl -fsS -m 2 -X PUT -H &lt;span class="s1"&gt;'X-aws-ec2-metadata-token-ttl-seconds: 60'&lt;/span&gt; &lt;span class="s2"&gt;"$IMDS/api/token"&lt;/span&gt; 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; -n &lt;span class="s2"&gt;"$TOKEN"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; curl -fsS -m 2 -o /dev/null -H &lt;span class="s2"&gt;"X-aws-ec2-metadata-token: $TOKEN"&lt;/span&gt; &lt;span class="s2"&gt;"$IMDS/meta-data/spot/instance-action"&lt;/span&gt; 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
      &lt;span class="nv"&gt;NOTICED&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
      &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"spot interruption notice: stopping the runner in 30 s"&lt;/span&gt;
      sleep 30
    &lt;span class="k"&gt;fi&lt;/span&gt;
  &lt;span class="k"&gt;fi&lt;/span&gt;
  &lt;span class="c"&gt;# No listener yet (the notice came during boot): keep trying until one exists to stop.&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; -n &lt;span class="s2"&gt;"$NOTICED"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; pkill -INT -f Runner.Listener&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"runner stopped"&lt;/span&gt;
    &lt;span class="nb"&gt;exit&lt;/span&gt; 0
  &lt;span class="k"&gt;fi&lt;/span&gt;
  sleep 5
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An interrupt makes the runner fail its job at once and report it. GitHub records a failure while the instance is still alive to send it.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;sleep 30&lt;/code&gt; came from review, and it matters. The watcher and the worker react to the same notice through different paths. If the watcher stopped the runner immediately, GitHub's &lt;code&gt;completed&lt;/code&gt; event could reach the worker before AWS's warning did, and land on a job not yet marked as interrupted: a plain failure, no re-run. Thirty seconds makes that unlikely, since the warning normally arrives in a few, and still leaves ninety for the runner to report. It narrows the race; it does not close it. We also made the worker re-run an interrupted job that ends as &lt;code&gt;cancelled&lt;/code&gt;, for the case where the signal comes too late.&lt;/p&gt;

&lt;p&gt;This time the fault injector got there first:&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%2Flofcbb7lpumb4nv09zj7.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%2Flofcbb7lpumb4nv09zj7.png" alt="A spot interruption before and after the fix: before, the runner dies silently and the job hangs until its timeout; after, the watcher stops the runner at 30 s, the job fails at 72 s and the re-run is running at 119 s" width="800" height="285"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Job failed 72 seconds after the warning, re-run queued at 94, running on a new instance at 119. We called it done.&lt;/p&gt;

&lt;h2&gt;
  
  
  Attempt three: the test had one job
&lt;/h2&gt;

&lt;p&gt;Six days later, over one busy afternoon, AWS reclaimed several instances with jobs on them. Five jobs failed. Three of them, all from our largest repository, were not re-run. A colleague re-ran them by hand a few minutes later.&lt;/p&gt;

&lt;p&gt;The worker had asked. GitHub had said no. GitHub refuses to re-run a job while its workflow run is in progress, and those jobs had a dozen siblings still running: the other test shards, the coverage job, the gate. Our test run had contained exactly one job, so its run finished the moment its job failed.&lt;/p&gt;

&lt;p&gt;The re-run now waits for the run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;rerunInterrupted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;repo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;jobId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;runId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getRun&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;repo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;runId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run_attempt&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'rerun-superseded'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// someone re-ran it already&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'completed'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tries&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;MAX_RERUN_TRIES&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'rerun-given-up'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 15 checks, 30 minutes&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;scheduleRerun&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="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tries&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;tries&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&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;// a one-shot schedule, 2 minutes from now&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'rerun-scheduled'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;rerunJob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;repo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;jobId&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="s1"&gt;'rerun'&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The schedule is a one-shot EventBridge Scheduler entry that invokes the same worker and deletes itself. Its name is the job plus the check number, so a duplicate &lt;code&gt;completed&lt;/code&gt; event that arrives while the entry exists collides with it and schedules nothing. One that arrives later starts a second chain of checks, which is harmless: whichever chain comes second finds the run already at its second attempt and stops.&lt;/p&gt;

&lt;p&gt;This time the test had two jobs, four minutes and nine, and we interrupted the short 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%2F0vi46n57895ppooopw2c.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%2F0vi46n57895ppooopw2c.png" alt="An interrupted job in a two-job run: the short job fails at 61 s, the worker checks four times while the long job runs, the run completes at 500 s and the re-run is accepted at 609 s" width="800" height="311"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Four checks found the run still in progress. The fifth, 109 seconds after the run completed, was accepted.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it does not do
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;It does not save the work.&lt;/strong&gt; The job starts again from the beginning. Checkpointing a test run across machines is a different project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It tries once.&lt;/strong&gt; An interrupted re-run stays failed, and a person re-runs it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It gives up after 30 minutes.&lt;/strong&gt; If a job's siblings are still running half an hour after it failed, nobody re-runs it automatically.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The re-run waits for the slowest sibling.&lt;/strong&gt; That is GitHub's rule, not ours. The pull request goes red first and green later. Polling every two minutes adds up to two minutes on top.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Most interruptions need none of this.&lt;/strong&gt; In the week we looked at, twelve interruptions hit a running job, and seven of those jobs finished inside the warning.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What we took from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;"The platform will notice" is a hypothesis.&lt;/strong&gt; GitHub did not notice a dead runner for eleven minutes and would not have for six hours. Use the warning you are given.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test with the shape of production.&lt;/strong&gt; A one-job run and a twelve-job run are different systems to GitHub. Our first test passed for a reason that did not hold anywhere else.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A fault injector is cheap.&lt;/strong&gt; Each experiment cost a few cents and failed one job on purpose. The alternative was waiting for AWS to run the test for us, which it did, twice.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>ec2</category>
      <category>githubactions</category>
      <category>ci</category>
    </item>
    <item>
      <title>EC2 says no in four ways</title>
      <dc:creator>Félix</dc:creator>
      <pubDate>Wed, 25 Nov 2026 10:55:19 +0000</pubDate>
      <link>https://dev.to/monei/ec2-says-no-in-four-ways-3nb9</link>
      <guid>https://dev.to/monei/ec2-says-no-in-four-ways-3nb9</guid>
      <description>&lt;p&gt;One afternoon ten CI jobs queued within a second of each other, and four of them started three minutes late. EC2 had capacity for all ten the whole time.&lt;/p&gt;

&lt;p&gt;This is the third of five posts about running each GitHub Actions job on its own EC2 spot instance. The &lt;a href="https://dev.to/monei/one-job-one-instance-ephemeral-ec2-runners-for-github-actions-4no9"&gt;first post&lt;/a&gt; covers the design. This one is about the single API call the whole system depends on, &lt;code&gt;RunInstances&lt;/code&gt;, and the two bugs that taught us where a retry belongs.&lt;/p&gt;

&lt;h2&gt;
  
  
  The version that almost worked
&lt;/h2&gt;

&lt;p&gt;A job chooses a pool with a label, and a pool is a list of three instance types, newest generation first. To launch, we try each type in each of three availability zones on the spot market, then the same nine combinations on demand. Eighteen tries at most, and most of the time the first one succeeds.&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%2Fknq3rh768rsry0xbgzb1.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%2Fknq3rh768rsry0xbgzb1.png" alt="Launch order for one job: nine spot tries across three instance types and three zones, then the same nine on demand; a capacity error moves to the next cell, an account-wide spot limit skips to on-demand, a throttled call repeats the same cell under a 40 s budget, any other error stops" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A pull request on our largest repository queues ten or more jobs at once. Ten workers call &lt;code&gt;RunInstances&lt;/code&gt; in the same second, and EC2 throttles the API past a few calls per second. The AWS SDK retries a throttled call by itself, three attempts by default, and gives up after about 160 milliseconds. That was not enough, so we did the obvious thing and raised it to eight attempts, which back off for up to 25 seconds.&lt;/p&gt;

&lt;p&gt;That change is where both bugs come from.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bug 1: the retry we did not know we had
&lt;/h2&gt;

&lt;p&gt;The next burst arrived when the newest instance type had no spot capacity. Half the workers ran for 60 seconds, hit the Lambda timeout, and launched nothing. Their jobs waited five to ten minutes for the reaper, the scheduled function that sweeps up stuck jobs.&lt;/p&gt;

&lt;p&gt;The walk should have handled it: no capacity here, try the next cell, a second at most. CloudTrail said otherwise. For 30 tries made by our code, EC2 had logged 144 &lt;code&gt;InsufficientInstanceCapacity&lt;/code&gt; errors.&lt;/p&gt;

&lt;p&gt;EC2 returns that error with HTTP status 500. To the SDK, a 500 is a transient server fault, and transient faults get retried. Every cell our loop tried once, the SDK tried eight times with backoff, 15 to 30 seconds per cell. Three cells without capacity used up the whole minute.&lt;/p&gt;

&lt;p&gt;The timeout made it worse. A worker claims a job before it launches and releases the claim if the launch fails. A Lambda that times out runs no cleanup, so the claim stayed. Lambda retried the event twice, and both retries found the job already claimed and did nothing.&lt;/p&gt;

&lt;p&gt;The fix was to tell the SDK what we meant:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ThrottlingOnlyRetryStrategy&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;StandardRetryStrategy&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;override&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;refreshRetryTokenForRetry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;StandardRetryToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;errorInfo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;RetryErrorInfo&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;StandardRetryToken&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;errorInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;errorType&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'THROTTLING'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ServiceUnavailable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Not retried'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;errorType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;errorInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;errorType&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;return&lt;/span&gt; &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;refreshRetryTokenForRetry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;errorInfo&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The SDK retries throttling and nothing else. For a capacity error, the next cell is the retry.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bug 2: the retry we gave up on
&lt;/h2&gt;

&lt;p&gt;We deployed that and watched the next burst. This is the one from the opening: ten jobs, four of them late by two and a half to four minutes. CloudTrail for those six minutes showed 60 launch calls: 16 succeeded, 24 failed on capacity, 20 were throttled.&lt;/p&gt;

&lt;p&gt;Capacity was not the problem this time. One zone had room, and every worker that reached it launched. The problem was the 20 throttles. A call that was still throttled after the SDK's eight attempts came back to our loop as an error, and our loop knew two kinds of error: "no capacity, try the next cell" and "anything else, give up". Throttling was anything else.&lt;/p&gt;

&lt;p&gt;Giving up was handled correctly, which is what made it slow. The worker released the claim and threw. Lambda retries a failed asynchronous event after about one minute, then after two. So a job that lost the throttling lottery started one to three minutes late, by design of the retry schedule of a system that did not know what it was retrying.&lt;/p&gt;

&lt;p&gt;The loop now owns the throttle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;throttleDeadline&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="no"&gt;THROTTLE_BUDGET_MS&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 40 s&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;market&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'spot'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'on-demand'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;tries&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;instanceType&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;instanceTypes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;subnet&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nf"&gt;runnerConfig&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="n"&gt;subnets&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;for&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;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;runOnce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;instanceType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subnet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;market&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tags&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;InstanceId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;instanceType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;market&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;errorCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="no"&gt;THROTTLE_ERROR&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;throttleDeadline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;throttlePause&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;// 1 to 2 s, with jitter&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// the same cell again&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
          &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;market&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'spot'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="no"&gt;SPOT_LIMIT_ERROR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt; &lt;span class="n"&gt;tries&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="no"&gt;NEXT_TRY_ERRORS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&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;throw&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// the next cell&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A throttled cell is tried again after a short pause, until 40 seconds have passed since the walk began. The SDK's own attempts went back down to three. Past the budget the error is thrown as before, and the claim is released. The budget is a cutoff for starting another try, not a hard limit: a call that begins just before it can run a few seconds past. That is why it is 40 seconds and not 55. The function times out at 60, and a timeout is the one exit that skips the release.&lt;/p&gt;

&lt;h2&gt;
  
  
  The four answers
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;EC2 says&lt;/th&gt;
&lt;th&gt;It means&lt;/th&gt;
&lt;th&gt;The walk does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;InsufficientInstanceCapacity&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;no spot of this type in this zone&lt;/td&gt;
&lt;td&gt;the next cell&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MaxSpotInstanceCountExceeded&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;the account's spot limit&lt;/td&gt;
&lt;td&gt;skip to on demand&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;RequestLimitExceeded&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;too many API calls right now&lt;/td&gt;
&lt;td&gt;the same cell again, within 40 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;anything else&lt;/td&gt;
&lt;td&gt;a real error, such as a vCPU quota&lt;/td&gt;
&lt;td&gt;stop, release the claim, throw&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each row is a different decision about the next try. That is why the SDK could not make it for us: it sees a status code, and only the loop knows that the right answer to "no capacity" is a different zone and the right answer to "slow down" is the same call a second later.&lt;/p&gt;

&lt;p&gt;The walk got a real test the same afternoon. Eighteen minutes after the first fix was deployed, the newest instance type ran out of spot capacity, and every launch for the rest of the day fell back to the previous generation. No job was late for it. We noticed only because a benchmark we were running came out about 15 % slower, and the job logs showed the older instance type.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it does not do
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;It waits throttling out. It does not avoid it.&lt;/strong&gt; Ten workers still call EC2 in the same second. A stagger across workers, or one launcher that batches, would reduce the throttling itself. We have not built either, because the wait is now bounded and short.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It does not go down a size.&lt;/strong&gt; When a pool has no capacity on any type, the job goes on demand at the size its author asked for. Running it on a smaller machine would be faster to start and slower to finish, and hard to explain in a job log.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It does not predict.&lt;/strong&gt; We do not track capacity or pick zones by recent success. The error from the next call is the signal, and it is exact.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What we took from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Retries belong in one place, with one time budget.&lt;/strong&gt; A retry inside a library spends the budget of the loop above it, and the loop cannot see it happen. We turned the SDK's retries down, not up.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read what your error codes mean to the layer below.&lt;/strong&gt; A capacity error that is a 500 is a transient fault to an SDK and a routing decision to us.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Know which exit skips your cleanup.&lt;/strong&gt; For a Lambda it is the timeout, so every budget has to end before it.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>ec2</category>
      <category>githubactions</category>
      <category>ci</category>
    </item>
    <item>
      <title>GitHub sends events late, twice, or never</title>
      <dc:creator>Félix</dc:creator>
      <pubDate>Wed, 25 Nov 2026 10:55:00 +0000</pubDate>
      <link>https://dev.to/monei/github-sends-events-late-twice-or-never-4h7</link>
      <guid>https://dev.to/monei/github-sends-events-late-twice-or-never-4h7</guid>
      <description>&lt;p&gt;On 10 November 2026, during a GitHub incident, our runner control plane refused 17 CI jobs in 13 minutes. It logged no error, because from where it stood nothing had failed.&lt;/p&gt;

&lt;p&gt;This is the second of five posts about running each GitHub Actions job on its own EC2 instance. The &lt;a href="https://dev.to/monei/one-job-one-instance-ephemeral-ec2-runners-for-github-actions-4no9"&gt;first post&lt;/a&gt; covers the design. This one is about the only input the system has, GitHub's &lt;code&gt;workflow_job&lt;/code&gt; webhook, and what it takes to build on an input you cannot trust.&lt;/p&gt;

&lt;h2&gt;
  
  
  The version that fits on a napkin
&lt;/h2&gt;

&lt;p&gt;The design looks like two event handlers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;on &lt;code&gt;queued&lt;/code&gt;: launch an instance for the job;&lt;/li&gt;
&lt;li&gt;on &lt;code&gt;completed&lt;/code&gt;: record the result.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It ran its first jobs on the first day. Then the event stream showed us three ways it was wrong.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A delivery arrives twice.&lt;/strong&gt; GitHub can deliver the same event more than once. Two copies of one &lt;code&gt;queued&lt;/code&gt; event, milliseconds apart, launched two instances. One ran the job. The other sat idle until something noticed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An event arrives late.&lt;/strong&gt; The webhook hands each event to a worker through an asynchronous queue, and that queue keeps no order. A &lt;code&gt;queued&lt;/code&gt; event processed after its own &lt;code&gt;completed&lt;/code&gt; put a finished job back in the waiting list, and we launched for a job that no longer existed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An event never arrives.&lt;/strong&gt; GitHub does not retry a delivery that failed. A job whose &lt;code&gt;queued&lt;/code&gt; event was lost waited for a runner that nobody was going to start. GitHub lets a job wait like that for 24 hours before it gives up.&lt;/p&gt;

&lt;p&gt;None of these is a bug in GitHub. It is what a webhook is. The napkin design assumed a log; what we had was a rumour.&lt;/p&gt;

&lt;h2&gt;
  
  
  Every write is conditional
&lt;/h2&gt;

&lt;p&gt;The fix is one rule: a handler never assumes what came before it. Each job has one item in a DynamoDB table, and every write to it carries a condition.&lt;/p&gt;

&lt;h3&gt;
  
  
  A status only moves forward
&lt;/h3&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%2F0kkrx7h25b9rkz6xkk9l.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%2F0kkrx7h25b9rkz6xkk9l.png" alt="Job status state diagram: no item to queued to in_progress to completed; queued may also go to completed or rejected; a first event may create the item in any status; a late queued or in_progress write on a completed job is refused" width="799" height="346"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A status write says, in its condition, "the item has no status yet, or its status is one that may move to this one". A late &lt;code&gt;queued&lt;/code&gt; on a completed job fails that condition and changes nothing. An event that arrives first, with no item at all, creates one in whatever status it reports.&lt;/p&gt;

&lt;p&gt;A write that loses its condition returns &lt;code&gt;false&lt;/code&gt;. It does not throw. Losing is the normal case for a duplicate, and an exception there would send every duplicate to the dead-letter queue.&lt;/p&gt;

&lt;h3&gt;
  
  
  One launch per job
&lt;/h3&gt;

&lt;p&gt;The launch is guarded by a claim, written in the same conditional update that records the job:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;claimLaunch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;JobRef&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;PoolName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;jobId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;set&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="nf"&gt;queuedFields&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;launchClaimedAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;dynamoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Condition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'launchClaimedAt'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="ow"&gt;not&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="nf"&gt;exists&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="ow"&gt;and&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="nf"&gt;parenthesis&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'status'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="ow"&gt;not&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="nf"&gt;exists&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="ow"&gt;or&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="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'status'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'queued'&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two deliveries race for it and DynamoDB picks one. The loser stops before it calls GitHub or EC2. We tried the obvious alternative first, a check for an existing instance tagged with the job. Two workers can both look, both see nothing, and both launch. A read followed by a write is not a lock.&lt;/p&gt;

&lt;p&gt;If the launch fails after the claim, the claim is released, so a retry can take it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Count runners, do not match them
&lt;/h3&gt;

&lt;p&gt;This is the rule that took us longest to accept. A just-in-time runner is registered with labels, not with a job. When it connects, GitHub gives it the oldest queued job those labels satisfy.&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%2Flguczgg7n9jeg46mlx9j.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%2Flguczgg7n9jeg46mlx9j.png" alt="Two instances tagged for jobs A and B; GitHub gives job B to the first free runner and job A to the second" width="799" height="345"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So the instance we launched for job A often runs job B. The tag on the instance says A. Nothing is wrong: two jobs were queued and two runners exist. But any code that asks "does job A have a runner?" by looking for A's instance gets the wrong answer.&lt;/p&gt;

&lt;p&gt;The reaper, which runs every 5 minutes, therefore works by count. Per pool, it takes the jobs that have waited more than 3 minutes, subtracts the instances that are free or still booting, and launches the difference. It never asks which runner belongs to which job.&lt;/p&gt;

&lt;p&gt;The same fact decides how a cancelled job is cleaned up. Its instance may have just taken another job. Checking whether the runner is busy and then terminating has a gap between the two calls. So we delete the runner first. GitHub refuses to delete a busy runner, and only when the delete succeeds is the instance safe to terminate.&lt;/p&gt;

&lt;h2&gt;
  
  
  The event that did arrive, and lied
&lt;/h2&gt;

&lt;p&gt;Back to 10 November. Before it launches, the worker checks that the job's repository is in our runner group. We added that check on purpose: a repository outside the group can never get one of our runners, and its job would wait a day in silence. Rejecting it at once, with a metric, made a typo in a workflow file visible in a minute.&lt;/p&gt;

&lt;p&gt;The list of repositories comes from GitHub's API, and we cached it for 5 minutes.&lt;/p&gt;

&lt;p&gt;During the incident that endpoint answered &lt;code&gt;200 OK&lt;/code&gt; with a short list. Not an error, not a timeout: a valid response with some of the repositories missing. We cached it. For the next 13 minutes, every job from a missing repository was rejected, and a rejection is final by design, so those 17 jobs waited until a person re-ran them.&lt;/p&gt;

&lt;p&gt;A guard written to make one failure loud had made a different failure silent.&lt;/p&gt;

&lt;p&gt;The response carried its own evidence. It reports a &lt;code&gt;total_count&lt;/code&gt;, and the items did not add up to it. We now refuse any list that does not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pageItems&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;PER_PAGE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;complete&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;total_count&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ServiceUnavailable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'GitHub list incomplete'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;listed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;total_count&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;return&lt;/span&gt; &lt;span class="n"&gt;items&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;A short list is never cached. And before the worker rejects a job, it reads the list again, fresh. If that read fails, the worker throws, the event is retried, and the job is not rejected. The rule we took from it: a final decision needs better evidence than a cached one.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it does not do
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No ordering.&lt;/strong&gt; We never reconstruct the order of events. The conditions make order irrelevant for the state we keep, and we keep very little.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No exactly-once.&lt;/strong&gt; The claim stops duplicate deliveries, not every extra instance. When a job waits more than 3 minutes, because a boot was slow or GitHub was slow to assign it, the reaper may launch a second runner for it. We accept an idle instance over a lost job; it is removed after 15 minutes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A lost event still costs time.&lt;/strong&gt; The reaper asks GitHub to redeliver failed deliveries every 5 minutes, and a second scheduled function lists, every 30 minutes, the queued jobs we have never heard of. A job whose event vanished starts minutes late. It does not start on time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Re-drives are capped at two per job.&lt;/strong&gt; GitHub has reported jobs as queued after a runner took them, and without a cap each pass would launch another idle instance. A job that truly needs a third try waits for a person.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What we took from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Treat a webhook as a hint, not a log.&lt;/strong&gt; Write handlers that are correct in any order and at any multiplicity, and add a slow loop that asks the source directly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A &lt;code&gt;200&lt;/code&gt; is not proof.&lt;/strong&gt; When a response states its own size, check it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make final decisions on fresh evidence.&lt;/strong&gt; Caches are for the path you can retry.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>githubactions</category>
      <category>aws</category>
      <category>distributedsystems</category>
      <category>ci</category>
    </item>
    <item>
      <title>One job, one instance: ephemeral EC2 runners for GitHub Actions</title>
      <dc:creator>Félix</dc:creator>
      <pubDate>Wed, 25 Nov 2026 10:23:09 +0000</pubDate>
      <link>https://dev.to/monei/one-job-one-instance-ephemeral-ec2-runners-for-github-actions-4no9</link>
      <guid>https://dev.to/monei/one-job-one-instance-ephemeral-ec2-runners-for-github-actions-4no9</guid>
      <description>&lt;p&gt;Our median CI job runs for 51 seconds. GitHub billed each one as a full minute, on a 2-core machine that our test suites could not outgrow.&lt;/p&gt;

&lt;p&gt;This is the first of five posts about what we built instead: every job gets its own EC2 instance, which boots, runs that one job, and terminates. This post covers the idea, the alternatives, and the numbers. The others cover what it took to keep it true in production.&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%2Flyk78go0wxky3m0c9aug.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%2Flyk78go0wxky3m0c9aug.png" alt="Timeline of one job: 28 s from queue to start, 60 s of job, then shutdown and terminate" width="799" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What we tried first
&lt;/h2&gt;

&lt;p&gt;We run about 32,000 CI jobs a month across some 80 private repositories. More than half finish in under a minute. &lt;a href="https://docs.github.com/en/billing/reference/actions-runner-pricing" rel="noopener noreferrer"&gt;GitHub's pricing page&lt;/a&gt; says it plainly: "GitHub rounds the minutes and partial minutes each job uses up to the nearest whole minute." A 51 second job and a 9 second job cost the same.&lt;/p&gt;

&lt;p&gt;So we did what everyone does. We sharded the big suites, added path filters so a pull request ran only the jobs it touched, and merged tiny jobs that spent more time on setup than on work. The bill went down. No job got faster.&lt;/p&gt;

&lt;p&gt;That was the moment the approach broke. Our largest suites are import-bound: a few seconds to load and transform each test file, times a few hundred files. On 2 vCPUs the test runner uses one worker. Sharding spreads that work over more machines, and each new machine pays for checkout and install again. The machine was the limit, and we could not change the machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why not buy it
&lt;/h2&gt;

&lt;p&gt;Per-minute list prices for a Linux runner, November 2026:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;2 vCPU&lt;/th&gt;
&lt;th&gt;4 vCPU&lt;/th&gt;
&lt;th&gt;8 vCPU&lt;/th&gt;
&lt;th&gt;Billing unit&lt;/th&gt;
&lt;th&gt;Code runs in&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;GitHub-hosted, x64&lt;/td&gt;
&lt;td&gt;$0.006&lt;/td&gt;
&lt;td&gt;$0.012&lt;/td&gt;
&lt;td&gt;$0.022&lt;/td&gt;
&lt;td&gt;whole minute, rounded up&lt;/td&gt;
&lt;td&gt;GitHub&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GitHub-hosted, arm64&lt;/td&gt;
&lt;td&gt;$0.005&lt;/td&gt;
&lt;td&gt;$0.008&lt;/td&gt;
&lt;td&gt;$0.014&lt;/td&gt;
&lt;td&gt;whole minute, rounded up&lt;/td&gt;
&lt;td&gt;GitHub&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A managed runner SaaS&lt;/td&gt;
&lt;td&gt;$0.0025&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;whole minute, rounded up&lt;/td&gt;
&lt;td&gt;the vendor&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Ours: EC2 Graviton spot&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;$0.0007&lt;/td&gt;
&lt;td&gt;$0.0016&lt;/td&gt;
&lt;td&gt;$0.0031&lt;/td&gt;
&lt;td&gt;per second, plus a boot&lt;/td&gt;
&lt;td&gt;our account&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%2F9bucwf26by8709e81cu9.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%2F9bucwf26by8709e81cu9.png" alt="Price per minute of a 2, 4 and 8 vCPU runner: GitHub x64, GitHub arm64, a managed SaaS and our spot Graviton" width="799" height="423"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A rate hides the run time, so here is one real job, one of our larger test suites. The rows marked "est." assume the run time we measured on our own Graviton of the same size. We did not buy larger GitHub runners to test them.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Runner&lt;/th&gt;
&lt;th&gt;Run time&lt;/th&gt;
&lt;th&gt;Billed as&lt;/th&gt;
&lt;th&gt;Cost per job&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;GitHub x64, 2 vCPU&lt;/td&gt;
&lt;td&gt;484 s&lt;/td&gt;
&lt;td&gt;9 min&lt;/td&gt;
&lt;td&gt;$0.054&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GitHub arm64, 2 vCPU (est.)&lt;/td&gt;
&lt;td&gt;~343 s&lt;/td&gt;
&lt;td&gt;6 min&lt;/td&gt;
&lt;td&gt;$0.030&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GitHub arm64, 8 vCPU (est.)&lt;/td&gt;
&lt;td&gt;~86 s&lt;/td&gt;
&lt;td&gt;2 min&lt;/td&gt;
&lt;td&gt;$0.028&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Ours, 8 vCPU spot&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;86 s&lt;/td&gt;
&lt;td&gt;114 s&lt;/td&gt;
&lt;td&gt;$0.0059&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;GitHub's larger runner would be as fast as ours and five times the price. The managed services we looked at were good products. They lost on two things we cared about: billing still rounded per job, and our code would run in someone else's account, with a vendor holding a key that can register runners for the whole organisation.&lt;/p&gt;

&lt;h2&gt;
  
  
  One job, one instance
&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%2Fa7p65ut84ctdtj3dl82m.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%2Fa7p65ut84ctdtj3dl82m.png" alt="Architecture: GitHub webhook to Lambda, worker launches EC2 from a JIT config, reaper and reconcile close the loop" width="800" height="474"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The control plane is four Lambda functions and one DynamoDB table, in TypeScript, deployed the same way as every other backend service we run. That was the point of the choice: no new deploy pipeline, no new monitoring, nothing new to be on call for.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;webhook&lt;/strong&gt; receives GitHub's &lt;code&gt;workflow_job&lt;/code&gt; events and checks their signature.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;worker&lt;/strong&gt; handles each event. For a queued job it asks GitHub for a just-in-time runner registration and launches one spot instance with it.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;reaper&lt;/strong&gt; runs every 5 minutes and a &lt;strong&gt;reconcile&lt;/strong&gt; every 30. They exist because GitHub's events arrive late, twice, or never. Most of the code lives here, and most of this series is about it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The instance boots from an image that already holds the runner and every tool. The whole boot script is this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; -euo pipefail
shutdown -h +375                       &lt;span class="c"&gt;# hard stop above the 360 min job timeout&lt;/span&gt;
&lt;span class="nb"&gt;trap&lt;/span&gt; &lt;span class="s1"&gt;'shutdown -h now'&lt;/span&gt; EXIT
&lt;span class="nb"&gt;cd&lt;/span&gt; /home/runner/actions-runner
sudo -u runner ./run.sh --jitconfig &lt;span class="s2"&gt;"&amp;lt;jit config from the worker&amp;gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The runner takes one job and exits. The trap runs &lt;code&gt;shutdown&lt;/code&gt;, and the launch template turns a shutdown into a termination. There is no agent on the instance and no idle timer.&lt;/p&gt;

&lt;p&gt;A job picks its machine with a label: &lt;code&gt;[self-hosted, linux, arm64]&lt;/code&gt; for 2 vCPUs, &lt;code&gt;arm64-4vcpu&lt;/code&gt;, &lt;code&gt;arm64-8vcpu&lt;/code&gt;. The size labels never include plain &lt;code&gt;arm64&lt;/code&gt;, because of the one fact that shaped everything else:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub does the matching, not us.&lt;/strong&gt; When a runner connects, GitHub hands it the oldest queued job whose labels it satisfies. The instance we launched for job A often runs job B. We do not route jobs. We only make sure the number of runners follows the number of queued jobs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Does it work
&lt;/h2&gt;

&lt;p&gt;The last seven days, to 25 November 2026, from the table where the worker records every job:&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;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;repositories using the runners&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;jobs&lt;/td&gt;
&lt;td&gt;2,348&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;cost on EC2 (spot price × billed seconds)&lt;/td&gt;
&lt;td&gt;$13.39&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;same jobs on same-size GitHub runners&lt;/td&gt;
&lt;td&gt;$63.73&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;queue to start, median&lt;/td&gt;
&lt;td&gt;28 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;jobs that lost their spot instance mid-run&lt;/td&gt;
&lt;td&gt;24&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;share launched on demand instead of spot&lt;/td&gt;
&lt;td&gt;0 %&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The GitHub figure prices each job at GitHub's list rate for a runner of the same size, rounded up to the minute. It is an estimate of a bill we no longer get, not a bill.&lt;/p&gt;

&lt;p&gt;Speed matters more to us than the cost. Going from 2 to 8 vCPUs made every suite we measured 3 to 5 times faster, on the same commit, median of two runs. The unit-test stage of our largest repository went from about 8 minutes to about 1.5.&lt;/p&gt;

&lt;p&gt;The job log tells you where a job ran, since nobody can log in to a machine that no longer exists:&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%2Fmmjcvj9wa06miuz3plil.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%2Fmmjcvj9wa06miuz3plil.png" alt="The &amp;quot;Set up runner&amp;quot; step of a job log: instance type, spot, vCPU and memory" width="800" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Security, briefly
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Private repositories only. A fork pull request on a public repository runs any code it likes, so three independent checks refuse public repositories.&lt;/li&gt;
&lt;li&gt;Instances have no IAM role. Jobs that need AWS use OIDC, as they did on GitHub's runners.&lt;/li&gt;
&lt;li&gt;The runners live in an AWS account separate from production, in their own VPC.&lt;/li&gt;
&lt;li&gt;The just-in-time config is a credential. It travels in user data and is never logged.&lt;/li&gt;
&lt;li&gt;The control plane can only launch and terminate instances that carry the runner tag.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What it does not do
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;It is slower to start.&lt;/strong&gt; GitHub starts a hosted job in about 2 seconds. Ours waits 28. A 5 second lint job is worse off here, and we left those on GitHub.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No warm pool.&lt;/strong&gt; An idle instance would hide the boot for the first job of a burst only. Nobody has asked for it yet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;arm64 first.&lt;/strong&gt; There is an x64 pool at 2 vCPUs and no larger x64 sizes, because nothing needed one. A repository has to pass on arm64 before it moves.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CI only.&lt;/strong&gt; Deploys still run where they ran before.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A spot instance can be taken away mid-job.&lt;/strong&gt; It happens a few times a day. What we do about it took three attempts and has its own post.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What we took from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Per-second billing changes the question.&lt;/strong&gt; Once the rounding is gone, a bigger machine costs about the same per job whenever the speed-up matches the price step, and the boot is a cost you can see. Eight vCPUs cost 4.4 times two; our suites ran 3 to 5 times faster on them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measure a suite at three sizes before sharding it further.&lt;/strong&gt; Ours were parallel work starved of cores.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The launch path is the easy part.&lt;/strong&gt; It took two days. The next three weeks went into the ways a job can get lost between GitHub and EC2.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>githubactions</category>
      <category>aws</category>
      <category>ci</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
