<?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: Remdore</title>
    <description>The latest articles on DEV Community by Remdore (@remdore).</description>
    <link>https://dev.to/remdore</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%2F374495%2F8514d87d-49b5-4b8f-865f-f24a5cc1c29c.png</url>
      <title>DEV Community: Remdore</title>
      <link>https://dev.to/remdore</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/remdore"/>
    <language>en</language>
    <item>
      <title>Watching App Platform autoscale a small Flask app</title>
      <dc:creator>Remdore</dc:creator>
      <pubDate>Wed, 25 Nov 2026 17:16:13 +0000</pubDate>
      <link>https://dev.to/remdore/watching-app-platform-autoscale-a-small-flask-app-1ag2</link>
      <guid>https://dev.to/remdore/watching-app-platform-autoscale-a-small-flask-app-1ag2</guid>
      <description>&lt;p&gt;App Platform can add instances to a service on its own, based on CPU or on requests per second. I wanted to see what that looks like from the client side: how long a spike goes unanswered before a new instance shows up, what the requests see in the meantime, and how long the extra instances stay around afterwards. So I pointed some uploads at &lt;a href="https://github.com/oceanforge/spaces-gallery" rel="noopener noreferrer"&gt;spaces-gallery&lt;/a&gt;, the small Flask app from my &lt;a href="https://dev.to/remdore/uploading-straight-from-the-browser-to-digitalocean-spaces-4dlj"&gt;browser uploads post&lt;/a&gt;, and ran it twice with a different scaling metric each time.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;The app was deployed unchanged from the repo: Flask under gunicorn with its default single sync worker. Each upload is checked with Pillow, written to a Spaces bucket, then shrunk to a 400 px thumbnail that's written to the bucket too. I uploaded a 5000 x 5000 PNG of about 100 KB, so each request is cheap to send but has 25 million pixels to decode.&lt;/p&gt;

&lt;p&gt;The service ran on &lt;code&gt;apps-d-1vcpu-0.5gb&lt;/code&gt; in NYC with this autoscaling block:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;autoscaling&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;min_instance_count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="na"&gt;max_instance_count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
  &lt;span class="na"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;cpu&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;percent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the second run I replaced &lt;code&gt;cpu&lt;/code&gt; with &lt;code&gt;requests_per_second: { per_instance: 1 }&lt;/code&gt; and changed nothing else.&lt;/p&gt;

&lt;p&gt;The load came from my laptop at a fixed rate, without waiting for earlier requests to finish: 0.5 uploads a second for 3 minutes, then 2 a second for 12 minutes, then nothing for another 10 to 15 minutes. A single upload took about 0.8 s end to end, network included. Every 5 seconds a script recorded &lt;code&gt;doctl apps list-instances&lt;/code&gt; and any new entries in &lt;code&gt;doctl apps list-events&lt;/code&gt;, which is where App Platform logs each scaling decision along with the metric that triggered it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What happened
&lt;/h2&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;CPU at 50%&lt;/th&gt;
&lt;th&gt;1 request/s per instance&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Step to 2/s until first scale-out logged&lt;/td&gt;
&lt;td&gt;about 105 s&lt;/td&gt;
&lt;td&gt;about 133 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;New instance listed after that&lt;/td&gt;
&lt;td&gt;9 s&lt;/td&gt;
&lt;td&gt;20 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Upload latency on one instance, p50 / max&lt;/td&gt;
&lt;td&gt;17.0 s / 32.7 s&lt;/td&gt;
&lt;td&gt;6.3 s / 15.5 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;504 responses&lt;/td&gt;
&lt;td&gt;60 of 1,530&lt;/td&gt;
&lt;td&gt;38 of 1,530&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Step to 2/s until scale-out to 3 logged&lt;/td&gt;
&lt;td&gt;about 6.4 min&lt;/td&gt;
&lt;td&gt;about 5.7 min&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;p50 / p95 on 3 instances&lt;/td&gt;
&lt;td&gt;0.86 s / 1.31 s&lt;/td&gt;
&lt;td&gt;0.84 s / 1.26 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Load stopped until 3 to 2&lt;/td&gt;
&lt;td&gt;6.4 min&lt;/td&gt;
&lt;td&gt;3.5 min&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Load stopped until 2 to 1&lt;/td&gt;
&lt;td&gt;8.3 min&lt;/td&gt;
&lt;td&gt;7.5 min&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The part worth paying attention to is the first two minutes. One instance with one sync worker couldn't keep up with 2 uploads a second, so the queue grew straight away. Latency went past 5 seconds within 15 to 26 seconds of the step and kept climbing until the second instance arrived. In both runs a burst of 504s started at about 270 s, ninety seconds into the overload. Every one of them came back in under half a second, so something in front of the app was turning requests away rather than letting them time out. Nothing failed after that burst, in either run.&lt;/p&gt;

&lt;p&gt;Once the second instance was listed, the queue drained within about a minute. On two instances p95 was under 2 seconds, with the odd slower upload, and on three it was back where it had been before the spike. Each scaling event moved through &lt;code&gt;PENDING&lt;/code&gt; to &lt;code&gt;SUCCEEDED&lt;/code&gt;, and the scale-out events name their metric: &lt;code&gt;"triggering_metric": "cpu"&lt;/code&gt; in the first run, &lt;code&gt;"requests_per_second"&lt;/code&gt; in the second. The scale-down events don't name one.&lt;/p&gt;

&lt;p&gt;Scaling back down was gradual, one instance at a time, a few minutes apart. Billing is per second, so the extra two instances cost cents here.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong
&lt;/h2&gt;

&lt;p&gt;I planned the request-based run on the $5 shared plan, because I'd assumed only CPU-based autoscaling needed dedicated CPUs. The spec validator refused it with &lt;code&gt;must not exceed 1 instance for instance_size_slug apps-s-1vcpu-0.5gb&lt;/code&gt;, and &lt;code&gt;doctl apps tier instance-size list&lt;/code&gt; marks every shared size as not scalable. The smallest size that autoscales at all is &lt;code&gt;apps-d-1vcpu-0.5gb&lt;/code&gt; at $29 a month. Both runs used it, which at least made them comparable.&lt;/p&gt;

&lt;p&gt;I also expected CPU scaling to struggle with this app. A single sync worker spends part of each request waiting on two writes to Spaces, so I thought the instance could be full while its CPU looked moderate. That's not what happened. CPU scaled out about half a minute sooner than the request metric did. The monitoring API reports CPU in 2 minute samples, which is too coarse to see what the one instance was doing just before the first decision.&lt;/p&gt;

&lt;p&gt;And I expected the request-based run to stop at two instances. With a target of 1 request a second per instance and 2 uploads a second arriving, two should have been exactly enough. It went to three. I don't know whether it counts the target as a ceiling to stay under or counts some requests I don't see.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats
&lt;/h2&gt;

&lt;p&gt;One run per metric, one app, one region, one load shape. The load came from a single laptop across an ocean. gunicorn kept its default of one worker, and more workers per instance would change every number above. I didn't test &lt;code&gt;min_instance_count: 2&lt;/code&gt;, the p95 latency metric, or a spike that arrives faster than this one.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd take from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;With &lt;code&gt;min_instance_count: 1&lt;/code&gt;, the first one to two minutes of a spike land on a single instance. Here that meant uploads taking up to 15 seconds in one run and 33 in the other, plus a few dozen 504s. If spikes matter, start from two instances.&lt;/li&gt;
&lt;li&gt;Both metrics did the job. CPU reacted a bit faster on this app, and the request-based run gave its instances back sooner.&lt;/li&gt;
&lt;li&gt;The event log is the easiest way to see what the autoscaler decided and why. &lt;code&gt;doctl apps list-events &amp;lt;app id&amp;gt; -o json&lt;/code&gt; has the metric, the instance counts, and the time of each decision.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The whole experiment, two deploys, about an hour of instances and a Spaces bucket, came to roughly ten cents.&lt;/p&gt;

</description>
      <category>digitalocean</category>
      <category>devops</category>
      <category>python</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Adding a column while another transaction is open</title>
      <dc:creator>Remdore</dc:creator>
      <pubDate>Wed, 25 Nov 2026 07:46:49 +0000</pubDate>
      <link>https://dev.to/remdore/adding-a-column-while-another-transaction-is-open-42po</link>
      <guid>https://dev.to/remdore/adding-a-column-while-another-transaction-is-open-42po</guid>
      <description>&lt;p&gt;&lt;em&gt;I wrote about the Postgres side of this in September, in &lt;a href="https://dev.to/remdore/one-long-select-one-alter-table-and-every-query-behind-them-3l6i"&gt;One long SELECT, one ALTER TABLE, and every query behind them&lt;/a&gt;. This one adds MySQL 8.4 and measures what a lock timeout with retries costs the other clients.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Adding a nullable column is one of the cheapest schema changes there is. In Postgres 18 it only touches the catalog, and in MySQL 8.4 you can ask for &lt;code&gt;ALGORITHM=INSTANT&lt;/code&gt;. On an idle table both took a few milliseconds in my tests. What I wanted to know is what happens to everyone else when the table isn't idle, specifically when some other session has an open transaction that read from it and hasn't committed yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;Postgres 18.6 and MySQL 8.4.13 in two throwaway Docker containers on a Mac laptop. Each had one table, &lt;code&gt;items&lt;/code&gt;, with 200,000 rows. Three clients ran for 32 seconds:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a writer doing single-row &lt;code&gt;INSERT&lt;/code&gt;s in autocommit, about 80 a second&lt;/li&gt;
&lt;li&gt;a reader doing primary-key &lt;code&gt;SELECT&lt;/code&gt;s, at the same rate&lt;/li&gt;
&lt;li&gt;a session that opened a transaction at 3 s, ran &lt;code&gt;SELECT count(*) FROM items&lt;/code&gt;, then sat idle until it committed at 23 s&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At 6 s a fourth session ran the migration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Postgres&lt;/span&gt;
&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="n"&gt;note&lt;/span&gt; &lt;span class="kt"&gt;text&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;-- MySQL&lt;/span&gt;
&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="n"&gt;note&lt;/span&gt; &lt;span class="kt"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;ALGORITHM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;INSTANT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every query's start time and duration was logged. I ran each case three times per engine. The durations below varied by 30 ms at most between runs, so I'm quoting run one.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the clients saw
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Case&lt;/th&gt;
&lt;th&gt;Engine&lt;/th&gt;
&lt;th&gt;ALTER took&lt;/th&gt;
&lt;th&gt;Longest INSERT&lt;/th&gt;
&lt;th&gt;Longest SELECT&lt;/th&gt;
&lt;th&gt;INSERTs started between 6 s and 23 s&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;no open transaction&lt;/td&gt;
&lt;td&gt;Postgres&lt;/td&gt;
&lt;td&gt;1 ms&lt;/td&gt;
&lt;td&gt;0.01 s&lt;/td&gt;
&lt;td&gt;0.01 s&lt;/td&gt;
&lt;td&gt;1,376&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;no open transaction&lt;/td&gt;
&lt;td&gt;MySQL&lt;/td&gt;
&lt;td&gt;4 ms&lt;/td&gt;
&lt;td&gt;0.01 s&lt;/td&gt;
&lt;td&gt;0.01 s&lt;/td&gt;
&lt;td&gt;1,347&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;open transaction&lt;/td&gt;
&lt;td&gt;Postgres&lt;/td&gt;
&lt;td&gt;17.0 s&lt;/td&gt;
&lt;td&gt;17.0 s&lt;/td&gt;
&lt;td&gt;17.0 s&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;open transaction&lt;/td&gt;
&lt;td&gt;MySQL&lt;/td&gt;
&lt;td&gt;17.0 s&lt;/td&gt;
&lt;td&gt;17.0 s&lt;/td&gt;
&lt;td&gt;17.0 s&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;With the open transaction, the ALTER waited the full 17 seconds until the other session committed. That part I expected. What matters is that every INSERT and every SELECT that arrived after the ALTER waited behind it, for those same 17 seconds. One insert started in that window, and it was the one that hung. The plain primary-key read, which has nothing to do with the new column, hung too.&lt;/p&gt;

&lt;p&gt;Neither engine returned an error to the clients. They just stopped.&lt;/p&gt;

&lt;p&gt;The reason is the same in both. The ALTER needs an exclusive lock on the table, which in MySQL is the metadata lock. It can't get one while the idle transaction still holds its shared lock from the &lt;code&gt;count(*)&lt;/code&gt;. And once an exclusive request is waiting, new requests for the shared lock queue behind it instead of slipping past. So one idle session plus one cheap migration takes the whole table offline, and the cost of the migration itself has nothing to do with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it looks like while it's happening
&lt;/h2&gt;

&lt;p&gt;I took a snapshot of each engine's session list a moment into the stall. In Postgres, from &lt;code&gt;pg_stat_activity&lt;/code&gt; with &lt;code&gt;pg_blocking_pids()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pid  state                wait_event  query                                    blocked by
148  active               relation    INSERT INTO items (v, payload) VALUES …  {151}
149  active               relation    SELECT payload FROM items WHERE id = …   {151}
150  idle in transaction  ClientRead  SELECT count(*) FROM items               {}
151  active               relation    ALTER TABLE items ADD COLUMN note text    {150}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The INSERT and the SELECT both name the ALTER as the thing blocking them, not the idle transaction. If you only follow the first hop, the migration looks like the culprit. The session actually holding things up is listed as idle, and its &lt;code&gt;query&lt;/code&gt; column shows the last thing it ran, which can be minutes old in a real app.&lt;/p&gt;

&lt;p&gt;MySQL's &lt;code&gt;processlist&lt;/code&gt; is less helpful:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;id  command  state                            info
51  Query    Waiting for table metadata lock  ALTER TABLE items ADD COLUMN note text, ALGORITHM=INSTANT
52  Query    Waiting for table metadata lock  SELECT payload FROM items WHERE id = 126667
53  Sleep                                     NULL
54  Query    Waiting for table metadata lock  INSERT INTO items (v, payload) VALUES (1, 'x')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The session holding the lock shows up as &lt;code&gt;Sleep&lt;/code&gt; with no query at all. Nothing on that line says it's the one with the open transaction. You need &lt;code&gt;performance_schema.metadata_locks&lt;/code&gt; or &lt;code&gt;sys.schema_table_lock_waits&lt;/code&gt; to connect it.&lt;/p&gt;

&lt;h2&gt;
  
  
  A lock timeout on the migration
&lt;/h2&gt;

&lt;p&gt;The usual advice is to give the migration a short lock timeout and retry. I set &lt;code&gt;lock_timeout = '2s'&lt;/code&gt; in Postgres and &lt;code&gt;lock_wait_timeout = 2&lt;/code&gt; in MySQL on the migration's session, then retried every 3 seconds until it worked.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Engine&lt;/th&gt;
&lt;th&gt;Attempts&lt;/th&gt;
&lt;th&gt;Error on each failed attempt&lt;/th&gt;
&lt;th&gt;Longest INSERT&lt;/th&gt;
&lt;th&gt;Stalls over 0.5 s&lt;/th&gt;
&lt;th&gt;INSERTs started between 6 s and 23 s&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Postgres&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;&lt;code&gt;canceling statement due to lock timeout&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;2.0 s&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;734&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MySQL&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;&lt;code&gt;1205 Lock wait timeout exceeded; try restarting transaction&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;2.0 s&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;711&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;It works in the sense that no request waited longer than 2 seconds. But each attempt froze the table for its full 2 seconds before giving up, and there were four of them, at 6, 11, 16 and 21 seconds. The clients spent 8 of those 17 seconds stuck, and the writer got through about half as many inserts as it did with no migration running. The fourth attempt went through when the idle transaction committed at 23 s.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong
&lt;/h2&gt;

&lt;p&gt;I treated the lock timeout as the fix. It turns one 17 second outage into four 2 second ones. Whether that's better depends on what your clients' own timeouts are, and with a 3 second retry the table was blocked almost half the time until the real problem went away. A shorter timeout, or a longer gap between retries, would trade those two against each other, but I only tried one setting.&lt;/p&gt;

&lt;p&gt;My clients had no query timeouts of their own, so each stall shows up as one slow call. In an app with a 5 second request timeout, the no-timeout case would have been a pile of errors, not one slow insert.&lt;/p&gt;

&lt;p&gt;And I'd have read the Postgres snapshot wrong if I'd stopped at the first column. The obvious reading is "the ALTER is blocking everything". It is, but only because something else is blocking it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats
&lt;/h2&gt;

&lt;p&gt;One table, one laptop, Docker, two clients plus the idle session. I didn't test &lt;code&gt;ADD COLUMN&lt;/code&gt; with a volatile default, index builds, &lt;code&gt;CREATE INDEX CONCURRENTLY&lt;/code&gt;, or what happens when the open transaction belongs to a connection pooler. In every run the idle transaction committed on its own at 23 s. In real life it might be a forgotten psql session that never does.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd take from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Before a migration, look for sessions that are &lt;code&gt;idle in transaction&lt;/code&gt; (Postgres) or have open transactions in &lt;code&gt;information_schema.innodb_trx&lt;/code&gt; (MySQL). The cheapest ALTER is only cheap if nothing is holding the table.&lt;/li&gt;
&lt;li&gt;Set a lock timeout on the migration anyway, but count on it costing one full timeout of blocked traffic per attempt.&lt;/li&gt;
&lt;li&gt;Postgres has &lt;code&gt;idle_in_transaction_session_timeout&lt;/code&gt; for the other side of the problem. It ends the session that's holding things up instead of the migration.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>postgres</category>
      <category>mysql</category>
      <category>database</category>
      <category>sql</category>
    </item>
    <item>
      <title>Notes on making an AI agent ask before it pushes</title>
      <dc:creator>Remdore</dc:creator>
      <pubDate>Sun, 22 Nov 2026 08:16:56 +0000</pubDate>
      <link>https://dev.to/remdore/notes-on-making-an-ai-agent-ask-before-it-pushes-2lf7</link>
      <guid>https://dev.to/remdore/notes-on-making-an-ai-agent-ask-before-it-pushes-2lf7</guid>
      <description>&lt;p&gt;I wanted an AI coding agent to do the work by itself and stop only before anything left its sandbox: pushing a branch, opening a pull request, commenting on one. DigitalOcean's Managed Agents let you write that into the session spec as permission rules. You allow everything by default and set a few commands to "ask". I ran two sessions against a small public repo of mine to see how it holds up. The first set of rules didn't fire once.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;Each session was a Harness Runtime session with the claude-code harness, Claude Sonnet 5.5 through DigitalOcean's inference, the &lt;code&gt;mars-2vcpu-4gb&lt;/code&gt; size, and GitHub access through an OAuth connection. The permission part of the spec looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;allow&lt;/span&gt;
  &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;tool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;bash&lt;/span&gt;
      &lt;span class="na"&gt;match&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;command:&lt;/span&gt; &lt;span class="s2"&gt;"git push *"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ask&lt;/span&gt;
      &lt;span class="na"&gt;enforcement&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;strict&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;tool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;bash&lt;/span&gt;
      &lt;span class="na"&gt;match&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;command:&lt;/span&gt; &lt;span class="s2"&gt;"gh pr create *"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ask&lt;/span&gt;
      &lt;span class="na"&gt;enforcement&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;strict&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The task was a real issue on the repo: write pytest tests for &lt;code&gt;decode()&lt;/code&gt; and &lt;code&gt;trial()&lt;/code&gt; in &lt;code&gt;flip.py&lt;/code&gt;, push a branch and open a pull request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run one: no approval requests at all
&lt;/h2&gt;

&lt;p&gt;The run took 54 seconds and 10 tool calls. It wrote 12 tests, got them passing, pushed the branch and opened PR #10. It never asked me anything about the push. This was its last command:&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="nb"&gt;cd&lt;/span&gt; /workspace/bitrot-demo &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git -c credential.helper=&lt;span class="s1"&gt;'!gh auth git-credential'&lt;/span&gt; push -u origin tests-for-flip 2&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;1 &lt;span class="o"&gt;|&lt;/span&gt; tail -3 &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; gh pr create --title &lt;span class="s2"&gt;"..."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The docs say rules match the command literally, and that's exactly what happened. &lt;code&gt;git push *&lt;/code&gt; only matches a command that starts with &lt;code&gt;git push&lt;/code&gt;. This one starts with &lt;code&gt;cd&lt;/code&gt;, has &lt;code&gt;-c credential.helper=...&lt;/code&gt; between &lt;code&gt;git&lt;/code&gt; and &lt;code&gt;push&lt;/code&gt;, and puts &lt;code&gt;gh pr create&lt;/code&gt; at the end of a chain. Neither rule matched, and both things happened.&lt;/p&gt;

&lt;p&gt;None of that was the agent being sneaky. Plain git had no credential helper in the sandbox, so it used the &lt;code&gt;gh&lt;/code&gt; login as a one-off helper for that one command, and it chained the PR onto the push because that's how people write it in a terminal. The problem is that what people normally type doesn't look like &lt;code&gt;git push *&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;One more thing in that run surprised me. The commit failed at first because git had no author set, and the agent asked me which name to use. The question came back as "The user did not answer the questions" in 7 ms, and the agent picked a neutral identity and carried on. I wasn't attached to the session, so nobody could have answered. But it didn't hold the run the way an approval does.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run two: wildcards on both sides
&lt;/h2&gt;

&lt;p&gt;For the second session I changed the patterns to &lt;code&gt;*git*push*&lt;/code&gt; and &lt;code&gt;*gh pr *&lt;/code&gt;. The task was a small follow-up on the same branch: add a &lt;code&gt;.gitignore&lt;/code&gt;, push it and leave a comment on the PR. I also told it to run the push and the comment as separate commands.&lt;/p&gt;

&lt;p&gt;This time every gated command stopped and waited:&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;Command&lt;/th&gt;
&lt;th&gt;Asked&lt;/th&gt;
&lt;th&gt;Answered&lt;/th&gt;
&lt;th&gt;Waited&lt;/th&gt;
&lt;th&gt;Answer&lt;/th&gt;
&lt;th&gt;What happened&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git push origin tests-for-flip&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;08:07:49&lt;/td&gt;
&lt;td&gt;08:11:13&lt;/td&gt;
&lt;td&gt;3 min 24 s&lt;/td&gt;
&lt;td&gt;approve&lt;/td&gt;
&lt;td&gt;failed, no git credentials&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git -c credential.helper=... push origin tests-for-flip&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;08:11:19&lt;/td&gt;
&lt;td&gt;08:11:31&lt;/td&gt;
&lt;td&gt;12 s&lt;/td&gt;
&lt;td&gt;approve&lt;/td&gt;
&lt;td&gt;pushed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;&lt;code&gt;gh pr comment 10 --body "..."&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;08:11:33&lt;/td&gt;
&lt;td&gt;08:11:46&lt;/td&gt;
&lt;td&gt;13 s&lt;/td&gt;
&lt;td&gt;reject&lt;/td&gt;
&lt;td&gt;not posted&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Request 1 sat for more than three minutes and nothing timed out. The run simply waited.&lt;/p&gt;

&lt;p&gt;I approved a push that then failed, and the retry needed its own approval. An approval covers one exact command string, not "push this branch". If an agent tends to retry with small changes, you answer once per variant.&lt;/p&gt;

&lt;p&gt;The reject went the way I'd want. The tool call came back as "denied". The agent didn't retry or look for another way to post the comment. It finished, said the comment wasn't posted, and printed the &lt;code&gt;gh pr comment&lt;/code&gt; command for me to run myself. The whole run took 4 minutes 10 seconds, most of it waiting on me.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the wildcards cost
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;*git*push*&lt;/code&gt; also matches &lt;code&gt;git log | grep push&lt;/code&gt;, and &lt;code&gt;*gh pr *&lt;/code&gt; also matches &lt;code&gt;gh pr view&lt;/code&gt;. Neither came up in these two runs. None of the other five bash commands in run two matched by accident. But the wider the pattern, the more often it asks.&lt;/p&gt;

&lt;p&gt;It's still string matching. A script file that runs &lt;code&gt;git push&lt;/code&gt;, a shell alias, or a Python &lt;code&gt;subprocess&lt;/code&gt; call doesn't have those characters in the command the agent sends. I didn't test any of those, but going by literal matching I'd expect them to go straight through.&lt;/p&gt;

&lt;p&gt;So I'd treat these rules as a way to get asked, not as a wall. What actually limits the agent is the token in the session. The GitHub connection's default scopes include full &lt;code&gt;repo&lt;/code&gt;. When I asked for only &lt;code&gt;public_repo&lt;/code&gt;, the connection was refused with "requested scopes exceed provider maximum".&lt;/p&gt;

&lt;p&gt;For comparison, 8 of the 10 tool calls in run one were bash commands. With &lt;code&gt;default: ask&lt;/code&gt;, each of those would have needed an answer too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the phone came in, or didn't
&lt;/h2&gt;

&lt;p&gt;The reason I tried this at all is that DigitalOcean has an iPhone app for Managed Agents, Cuttlefish, which is meant for approving an agent's next step from your phone. I answered all three requests from a laptop with &lt;code&gt;doctl hr approve &amp;lt;session&amp;gt; &amp;lt;request-id&amp;gt; approve|reject&lt;/code&gt;, because I hadn't installed the app before the first request arrived. The 12 and 13 second waits are me at a terminal. I can't tell you what the phone flow is like.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong
&lt;/h2&gt;

&lt;p&gt;I wrote the rules as if a person types one command at a time. Agents chain commands, prepend &lt;code&gt;cd&lt;/code&gt; and add &lt;code&gt;-c&lt;/code&gt; flags.&lt;/p&gt;

&lt;p&gt;I thought approving the push meant approving the push. It meant approving that one string, and the retry asked again.&lt;/p&gt;

&lt;p&gt;I planned to approve from my phone and didn't install the app first. That's why request 1 waited three and a half minutes.&lt;/p&gt;

&lt;p&gt;In run two I told the agent to run the push and the comment separately. That makes the wildcard result look better than it would have if the agent had chained them again. Run two doesn't show the wildcards catching a chained command, only that they caught the commands it ran.&lt;/p&gt;

&lt;p&gt;And the GitHub connection link expired twice before I finished authorizing it. It's the last browser step, on GitHub's page, and it doesn't wait for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats
&lt;/h2&gt;

&lt;p&gt;Two runs, one harness, one model, one small Python repo. I didn't test other harnesses, &lt;code&gt;best-effort&lt;/code&gt; enforcement, deny rules, or what the agent does when a request is deferred. The model tokens cost $0.13 for the first run and $0.05 for the second, plus a few cents of compute.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd take from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Run the session once and read &lt;code&gt;doctl hr logs&lt;/code&gt; for &lt;code&gt;human_input_requested&lt;/code&gt; before you trust a rule. Zero requests is a result, not a pass.&lt;/li&gt;
&lt;li&gt;Put wildcards on both sides of the pattern, and expect a few false alarms.&lt;/li&gt;
&lt;li&gt;Say in the prompt that gated commands should run on their own, not in a chain.&lt;/li&gt;
&lt;li&gt;Limit what the session's token can do. The rule gets you asked; the token decides what's possible.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>git</category>
      <category>devops</category>
      <category>security</category>
    </item>
    <item>
      <title>How long a DigitalOcean Cloud Firewall change takes to apply</title>
      <dc:creator>Remdore</dc:creator>
      <pubDate>Thu, 19 Nov 2026 14:29:03 +0000</pubDate>
      <link>https://dev.to/remdore/how-long-a-digitalocean-cloud-firewall-change-takes-to-apply-kkb</link>
      <guid>https://dev.to/remdore/how-long-a-digitalocean-cloud-firewall-change-takes-to-apply-kkb</guid>
      <description>&lt;p&gt;DigitalOcean's Cloud Firewalls sit outside the Droplet, so there's nothing to install and nothing on the server to get wrong. What I didn't know is how long a change takes to reach the traffic, whether the API tells you when it has, and what happens to connections that are already open when you take a rule away. So I measured it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;Two &lt;code&gt;s-1vcpu-1gb&lt;/code&gt; Droplets in fra1 running Ubuntu 24.04. Droplet A ran a small TCP echo server on port 8080. Droplet B probed it two ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A new TCP connection to port 8080 every 50 ms, each with a 1 second timeout, logging when it started and whether it connected.&lt;/li&gt;
&lt;li&gt;One long-lived connection that sent a number every 100 ms and logged each echo, so I could see what a firewall change does to a connection that's already open.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The firewall always allowed SSH in and everything out. The only thing I changed was whether port 8080 was reachable from B. I timed six kinds of change through the API, from my laptop:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;adding an allow rule for port 8080 from B, and removing it again (5 times each)&lt;/li&gt;
&lt;li&gt;attaching the firewall to Droplet A, and detaching it (5 times each)&lt;/li&gt;
&lt;li&gt;adding and removing a tag on A, with a second firewall that targeted that tag (3 times each)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then I compared each API request with B's probe log. The two clocks were matched over SSH, which leaves about 0.3 seconds of uncertainty in every number below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two to five seconds, and a clean switch
&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%2F8li7ofxwrosjt78ah9fq.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%2F8li7ofxwrosjt78ah9fq.png" alt="Each change, in seconds after the API request: when traffic from the other Droplet changed, and when the firewall's status first read 'succeeded'" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Every change reached the traffic in 1.3 to 5 seconds, except one detach that took 8.2. The medians:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Change&lt;/th&gt;
&lt;th&gt;Median&lt;/th&gt;
&lt;th&gt;Range&lt;/th&gt;
&lt;th&gt;Trials&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Add an allow rule&lt;/td&gt;
&lt;td&gt;2.0 s&lt;/td&gt;
&lt;td&gt;1.3–4.2 s&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Remove the rule&lt;/td&gt;
&lt;td&gt;2.1 s&lt;/td&gt;
&lt;td&gt;1.8–5.0 s&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Attach the firewall to the Droplet&lt;/td&gt;
&lt;td&gt;2.5 s&lt;/td&gt;
&lt;td&gt;2.0–3.5 s&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Detach it&lt;/td&gt;
&lt;td&gt;2.5 s&lt;/td&gt;
&lt;td&gt;2.1–8.2 s&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Add the tag the firewall targets&lt;/td&gt;
&lt;td&gt;3.2 s&lt;/td&gt;
&lt;td&gt;2.8–3.3 s&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Remove the tag&lt;/td&gt;
&lt;td&gt;2.9 s&lt;/td&gt;
&lt;td&gt;2.8–3.1 s&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The switch was clean every time. Once the first probe saw the new state, every probe after it saw the same thing. Nothing flapped between allowed and blocked while the change spread.&lt;/p&gt;

&lt;p&gt;Blocked traffic is dropped, not refused. Every probe that didn't connect timed out after its full second. None got a connection reset. From the outside, a closed port looks the same as a dead server.&lt;/p&gt;

&lt;h2&gt;
  
  
  The status doesn't tell you when it's done
&lt;/h2&gt;

&lt;p&gt;A firewall has a &lt;code&gt;status&lt;/code&gt; field that goes from &lt;code&gt;waiting&lt;/code&gt; to &lt;code&gt;succeeded&lt;/code&gt;. I polled it about once a second during every change.&lt;/p&gt;

&lt;p&gt;For rule changes and attach or detach, the status turned &lt;code&gt;succeeded&lt;/code&gt; 2.5 to 10.6 seconds after the request. By then the traffic had already changed, 1.0 to 3.1 seconds earlier. So waiting for the status is safe, just a bit slow.&lt;/p&gt;

&lt;p&gt;For tag changes, it's no use at all. The status already read &lt;code&gt;succeeded&lt;/code&gt; at my first check, 0.5 to 0.7 seconds after the request, and the traffic changed 2.1 to 2.7 seconds after that. Tagging a Droplet doesn't change anything on the firewall object, so there's nothing for the status to report. If a script tags a Droplet and then trusts the firewall status, it's about three seconds early.&lt;/p&gt;

&lt;h2&gt;
  
  
  Removing a rule doesn't close connections that are already open
&lt;/h2&gt;

&lt;p&gt;This was the part I got wrong. Cloud Firewalls are stateful: a reply to a connection you allowed gets back through without a matching rule. I expected that removing the allow rule would also cut the connections it had let in. It didn't.&lt;/p&gt;

&lt;p&gt;The long-lived connection was opened while the rule existed. Then I removed the rule five times, detached the firewall four times and reattached it three, and added and removed the tag on the second firewall three times. New connections were blocked within seconds every time. The open connection kept echoing through all of it, more than 6,000 echoes without a single gap.&lt;/p&gt;

&lt;p&gt;If you remove a rule to lock someone out, anyone already connected stays connected. I didn't test what does cut them off.&lt;/p&gt;

&lt;h2&gt;
  
  
  A connection opened with no firewall gets frozen, not closed
&lt;/h2&gt;

&lt;p&gt;The other direction behaved differently. The very first firewall I attached went onto a Droplet that already had the long-lived connection open, and that connection stopped getting echoes 4.5 seconds later.&lt;/p&gt;

&lt;p&gt;To check this wasn't something about the first firewall ever attached, I did it again at the end. I detached the firewall, opened a fresh long-lived connection while A had none, and attached the firewall again. That connection went silent 3.5 seconds after the attach and came back 4.8 seconds after I detached it.&lt;/p&gt;

&lt;p&gt;It looks like the firewall only lets through connections it saw being opened. A connection that started while no firewall was attached isn't one of them, so once a firewall is attached, its packets are dropped like any other unsolicited traffic.&lt;/p&gt;

&lt;p&gt;Neither connection was closed. The socket stayed open, the sender kept retrying, and nothing on either end got an error. To the application, it looks like the other side stopped answering. When I added the allow rule after the first freeze, new connections got through 1.3 seconds later, but the frozen one took 9.3 seconds, because TCP had been waiting longer and longer between retries.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong
&lt;/h2&gt;

&lt;p&gt;I expected removing an allow rule to cut the connections it had let in. It doesn't, and I only noticed because the long-lived connection was there for a different reason.&lt;/p&gt;

&lt;p&gt;I expected the firewall status to be a reliable "done" signal. For rule and attach changes it is, just late. For tag changes it means nothing.&lt;/p&gt;

&lt;p&gt;My first run crashed halfway. You can't create a firewall that targets a tag that doesn't exist yet: the API returns 422 "tag fwt does not exist". I created the tag first and ran the tag tests on their own.&lt;/p&gt;

&lt;p&gt;And my clock matching is rough. I measured the offset between my laptop and Droplet B over SSH with a 0.5 second round trip, so anything below about half a second in this post is noise.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats
&lt;/h2&gt;

&lt;p&gt;One region, two of the smallest Droplets, one port, TCP only. Five trials for each rule and attach change, three for each tag change, and one 8.2 second outlier I can't explain. I polled the firewall status about once a second, so the status times are only accurate to about a second. All of it was IPv4. The Droplets ran for about 18 minutes and cost under a cent. Cloud Firewalls themselves are free.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd take from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Expect a firewall change to apply in two to five seconds, and test it with real traffic rather than trusting the status, especially for tag-based firewalls.&lt;/li&gt;
&lt;li&gt;Removing a rule stops new connections only. Connections already open stay open.&lt;/li&gt;
&lt;li&gt;Attaching a firewall to a Droplet with connections already open freezes them without an error. Do it before traffic starts, or expect clients to hang.&lt;/li&gt;
&lt;li&gt;A blocked port times out instead of refusing, so a client that's being blocked waits for its full timeout.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>digitalocean</category>
      <category>networking</category>
      <category>security</category>
      <category>devops</category>
    </item>
    <item>
      <title>A DigitalOcean volume next to the Droplet's own disk</title>
      <dc:creator>Remdore</dc:creator>
      <pubDate>Thu, 19 Nov 2026 07:31:58 +0000</pubDate>
      <link>https://dev.to/remdore/a-digitalocean-volume-next-to-the-droplets-own-disk-51nb</link>
      <guid>https://dev.to/remdore/a-digitalocean-volume-next-to-the-droplets-own-disk-51nb</guid>
      <description>&lt;p&gt;Every Droplet comes with its own SSD, and DigitalOcean also sells Volumes, network block storage you attach to a Droplet and can move to another one. I'd only ever used volumes for "more space", and never checked what they cost in speed or what moving one actually looks like. So I put a volume and a Droplet's own disk through the same tests, then moved the volume between two Droplets, once properly and once by detaching it while Postgres was writing to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;Two &lt;code&gt;s-2vcpu-4gb&lt;/code&gt; Droplets in fra1, which is the shared-CPU plan at $24 a month, running Ubuntu 24.04, and a 100 GiB volume at $10 a month. I let DigitalOcean format the volume as ext4 on creation. It doesn't add an fstab line; it writes a systemd mount unit, &lt;code&gt;mnt-vt.mount&lt;/code&gt;, with &lt;code&gt;defaults,nofail,discard,noatime&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;DigitalOcean documents the limits for volumes, and they depend on the Droplet. On a shared-CPU Droplet a volume gets 7,500 IOPS and 300 MB/s, and can burst to 10,000 IOPS and 450 MB/s "for up to 60 seconds". The docs say nothing about latency.&lt;/p&gt;

&lt;p&gt;I ran fio 3.36 with direct I/O on an 8 GiB file on each disk, local first, then the volume, with a 120 second pause before every volume run so its burst could reset. Then pgbench against two Postgres 16 instances with identical settings, one with its data directory on each disk.&lt;/p&gt;

&lt;h2&gt;
  
  
  The burst is exactly as documented
&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%2Fsyjjduj9u4hga33vqyzh.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%2Fsyjjduj9u4hga33vqyzh.png" alt="The volume's throughput over time: sequential reads at 450 MiB/s for about a minute, then 300; random writes at 10,000 IOPS for about 80 seconds, then 7,500" width="800" height="304"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sequential reads in 1 MiB blocks ran at 450 MiB/s for 62 seconds and then dropped to a flat 300. Sequential writes did the same, within a second. Random 4 KiB writes with 32 in flight held 10,000 IOPS for about 80 seconds and then sat on 7,500. These are hard limits, not rough ones. The line is almost perfectly straight once it drops.&lt;/p&gt;

&lt;p&gt;The Droplet's own disk did 4,102 MB/s sequential reads and 1,206 MB/s writes over the same runs, and 39,703 random write IOPS. It wasn't close on throughput, and nobody should expect it to be.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Test&lt;/th&gt;
&lt;th&gt;Droplet's disk&lt;/th&gt;
&lt;th&gt;Volume&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Sequential read, 1 MiB, 150 s&lt;/td&gt;
&lt;td&gt;4,102 MB/s&lt;/td&gt;
&lt;td&gt;378 MB/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sequential write, 1 MiB, 150 s&lt;/td&gt;
&lt;td&gt;1,206 MB/s&lt;/td&gt;
&lt;td&gt;378 MB/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Random read, 4 KiB, 32 in flight&lt;/td&gt;
&lt;td&gt;75,274 IOPS&lt;/td&gt;
&lt;td&gt;7,162 IOPS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Random write, 4 KiB, 32 in flight&lt;/td&gt;
&lt;td&gt;39,703 IOPS&lt;/td&gt;
&lt;td&gt;8,833 IOPS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Random read, 4 KiB, one at a time&lt;/td&gt;
&lt;td&gt;4,391 IOPS&lt;/td&gt;
&lt;td&gt;1,006 IOPS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Random write, 4 KiB, one at a time&lt;/td&gt;
&lt;td&gt;2,575 IOPS&lt;/td&gt;
&lt;td&gt;3,432 IOPS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4 KiB write + fdatasync, one at a time&lt;/td&gt;
&lt;td&gt;2,133/s&lt;/td&gt;
&lt;td&gt;838/s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The volume's 378 MB/s averages are the 450 burst and the 300 after it, blended over 150 seconds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Latency is where it shows up
&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%2F7rsxqavm74g2i7zjeidi.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%2F7rsxqavm74g2i7zjeidi.png" alt="Median latency with one operation in flight: random read 146 µs local vs 700 µs on the volume; random write 272 vs 169; fdatasync 358 vs 922" width="800" height="288"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With one request at a time, which is how a lot of code reads, the limits don't matter. Latency does. A random 4 KiB read took a median of 146 µs on the local disk and 700 µs on the volume, and at the 99th percentile, 0.95 ms against 5.7 ms. Every read is a trip over the network.&lt;/p&gt;

&lt;p&gt;Writes went the other way. A 4 KiB write took 169 µs on the volume and 272 µs locally. The kernel reports a write cache on the volume's disk, so the write may be acknowledged before it's stored anywhere permanent. The flush shows the real cost: &lt;code&gt;fdatasync&lt;/code&gt; after a write took a median of 922 µs on the volume and 358 µs locally.&lt;/p&gt;

&lt;p&gt;Random reads with 32 in flight never settled on the volume. Second by second they swung between 2,552 and 10,809 IOPS, averaging 7,162, under the limit rather than pinned to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Postgres
&lt;/h2&gt;

&lt;p&gt;pgbench at scale 100, about 1.5 GB, with 8 clients for 120 seconds, three runs on each disk, alternating:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Run&lt;/th&gt;
&lt;th&gt;Droplet's disk&lt;/th&gt;
&lt;th&gt;Volume&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1,324 tps&lt;/td&gt;
&lt;td&gt;908 tps&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1,585 tps&lt;/td&gt;
&lt;td&gt;866 tps&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;1,671 tps&lt;/td&gt;
&lt;td&gt;1,070 tps&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The volume was about a third slower, with average latency of 7.5 to 9.2 ms against 4.8 to 6.0 ms. The database fits in memory here, so I think this is mostly the cost of flushing the WAL on every commit, the same &lt;code&gt;fdatasync&lt;/code&gt; from the table above. Loading the data and building the indexes took 37.0 seconds on the volume and 22.9 locally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Moving the volume properly
&lt;/h2&gt;

&lt;p&gt;This is the part a local disk can't do. I ran two writers on the volume on the first Droplet: one appending a numbered line to a file and fsyncing after each, one inserting rows into Postgres. Each logged what it had been told was saved, on the Droplet's own disk. Then I stopped them, stopped Postgres, unmounted, and moved the volume.&lt;/p&gt;

&lt;p&gt;The detach took 8.2 seconds from API request to completed, and the attach 7.2. The disk appeared on the second Droplet 3.4 seconds after the attach request, almost four seconds before the API said it was done. Mounting took 0.6 seconds, and Postgres started with "database system was shut down", no recovery needed. From the detach request to Postgres accepting connections on the other Droplet took 16.8 seconds.&lt;/p&gt;

&lt;p&gt;Nothing was missing. The second Droplet had 8,424 rows and 5,790 lines, one more of each than the writers had logged as saved. That last write landed, but the writer was killed before it could log it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Detaching it while Postgres was writing
&lt;/h2&gt;

&lt;p&gt;Next I skipped the unmount. With both writers running and Postgres up, I asked the API to detach the volume. I expected it to refuse, since the volume was mounted and busy. It accepted.&lt;/p&gt;

&lt;p&gt;About three seconds after the request (2.7 and 3.3 seconds in two runs), the writes started failing with &lt;code&gt;Input/output error&lt;/code&gt;. The kernel logged "device offline error", ext4 shut the filesystem down, and Postgres stopped with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PANIC:  could not fdatasync file "000000010000000100000008": Input/output error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The filesystem still showed as mounted. The API reported the detach complete four to five seconds after the errors began.&lt;/p&gt;

&lt;p&gt;Then I attached the volume to the other Droplet. ext4 replayed its journal on mount ("recovery complete"), and Postgres ran crash recovery, which took 0.08 seconds of redo. Postgres had confirmed 16,800 inserts before the error, and all 16,800 rows were there. The file writer had fsynced 11,686 lines, and all 11,686 were there.&lt;/p&gt;

&lt;p&gt;In the first forced run, the volume had one line more than the writer had confirmed. The last write was on disk even though its fsync had returned an error, which is the uncomfortable direction for an application that retries on errors.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong
&lt;/h2&gt;

&lt;p&gt;I expected the volume to lose every test. It was faster for single 4 KiB writes, and I can only point at the write cache as the likely reason. I didn't prove it.&lt;/p&gt;

&lt;p&gt;I expected the API to refuse to detach a mounted volume that was being written to. It doesn't check, and from the Droplet's side the disk simply disappears.&lt;/p&gt;

&lt;p&gt;I expected the 32-in-flight random reads to sit on the documented 10,000 IOPS burst like the writes did. They never got there for long.&lt;/p&gt;

&lt;p&gt;My Postgres writer broke on the first forced run. The table already existed, &lt;code&gt;CREATE TABLE IF NOT EXISTS&lt;/code&gt; printed a notice, and my script read the notice as the answer to the next query and stopped after one row. I fixed it and ran the forced test again in the other direction, which is where the 16,800 rows come from.&lt;/p&gt;

&lt;p&gt;And I stopped the writers with &lt;code&gt;pkill -f writer.py&lt;/code&gt;, which matched the SSH command that ran it and killed my own session. It's an old trap, and I still walked into it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats
&lt;/h2&gt;

&lt;p&gt;One Droplet size with a shared CPU, one region, one volume. Each fio test ran once, pgbench three times. The local disk's 4.1 GB/s reads may come partly from a cache on the host, which I can't see from inside the Droplet. The volume limits are higher on dedicated-CPU Droplets, 10,000 IOPS and 450 MB/s before any burst, and I didn't test those. The forced detach ran twice. The whole experiment ran for 70 minutes and cost about 7 cents.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd take from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Put data on a volume because it has to outlive the Droplet or move between Droplets, not for speed. On a shared-CPU Droplet the volume is capped at 300 MB/s and 7,500 IOPS, and a burst lasts about a minute.&lt;/li&gt;
&lt;li&gt;Expect single reads around 0.7 ms instead of 0.15, and flushes around 0.9 ms. A database that commits often will feel the flush.&lt;/li&gt;
&lt;li&gt;Moving a volume properly took 17 seconds end to end, most of it the API's own detach and attach.&lt;/li&gt;
&lt;li&gt;Unmount before you detach. DigitalOcean won't stop you, and the Droplet gets I/O errors three seconds later. In my runs nothing that had been confirmed was lost, but the application on that Droplet crashes.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>digitalocean</category>
      <category>linux</category>
      <category>postgres</category>
      <category>devops</category>
    </item>
    <item>
      <title>Searching my own posts with DigitalOcean Inference</title>
      <dc:creator>Remdore</dc:creator>
      <pubDate>Tue, 17 Nov 2026 13:59:46 +0000</pubDate>
      <link>https://dev.to/remdore/searching-my-own-posts-with-digitalocean-inference-2cio</link>
      <guid>https://dev.to/remdore/searching-my-own-posts-with-digitalocean-inference-2cio</guid>
      <description>&lt;p&gt;I've written 76 posts here, and I can no longer remember which one has the number I'm looking for. So I built a small tool that answers questions from them, with a link to the section each answer came from. Everything model-related runs on DigitalOcean Inference: the embeddings, a reranker and the model that writes the answer. The code is in &lt;a href="https://github.com/oceanforge/post-search" rel="noopener noreferrer"&gt;oceanforge/post-search&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The tool was the easy part. What I wanted to know was how much each piece earns its place, starting with whether embeddings beat plain keyword search on a collection this size.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;The tool downloads every post through the dev.to API and splits each one at its &lt;code&gt;##&lt;/code&gt; headings, which gives 664 sections. Each section is embedded together with its post title and heading.&lt;/p&gt;

&lt;p&gt;A question goes through three steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Embed the question and take the 20 nearest sections.&lt;/li&gt;
&lt;li&gt;Reorder those 20 with the &lt;code&gt;bge-reranker-v2-m3&lt;/code&gt; reranker.&lt;/li&gt;
&lt;li&gt;Give the top 5 to Claude Haiku 5.5, which answers from them only and cites them by number.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It runs from the command line, and there's a one-page web UI on top for trying questions:&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%2Fzsgx90k6472w3f3psgaa.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%2Fzsgx90k6472w3f3psgaa.png" alt="post-search answering a question about Kafka, with the section it used linked underneath" width="800" height="529"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There's no vector database. 664 vectors fit in memory, and a matrix product plus a sort finds the nearest ones in about 16 microseconds on my laptop. Embedding the whole collection took about 180,000 tokens and cost under a cent with either model.&lt;/p&gt;

&lt;h2&gt;
  
  
  The test
&lt;/h2&gt;

&lt;p&gt;To measure retrieval, I needed questions with known answers. I picked 60 sections at random and had Sonnet 5.5 write one question for each, phrased the way someone who hadn't read the post would ask it, without reusing the section's distinctive words. That second rule matters. A question that copies the post's wording makes keyword search look better than it is.&lt;/p&gt;

&lt;p&gt;I added 8 real questions that readers had left in the comments, the ones that make sense on their own. For each question, I checked whether the post it came from was the first result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keyword search was nearly as good
&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%2Fw811lou2f44gedgxp92k.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%2Fw811lou2f44gedgxp92k.png" alt="Bar chart: how often each search method put the right post first, and in the top 5, for 60 questions" width="800" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Plain BM25, with no model at all, put the right post first for 50 of 60 questions. Both embedding models got 55. On a few hundred sections about distinct topics, most questions share enough words with the right post for keyword search to find it.&lt;/p&gt;

&lt;p&gt;The two embedding models tied, even though &lt;code&gt;qwen3-embedding-0.6b&lt;/code&gt; costs twice as much per token. The reranker helped most where the first pass was weakest. It lifted BM25 from 50 to 56, nearly level with the best combination, while &lt;code&gt;bge-m3&lt;/code&gt; stayed at 55 with or without it. The best setup, &lt;code&gt;qwen3-embedding-0.6b&lt;/code&gt; plus the reranker, got 57 first and all 60 in the top 5.&lt;/p&gt;

&lt;p&gt;Combining BM25 with embeddings, which is the usual advice, didn't improve the first result. It did get every right post into the top 5, which is what the answering step needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the methods differed
&lt;/h2&gt;

&lt;p&gt;The reader questions were where embeddings showed what they're for. One reader asked, under a post about zero-downtime deploys, "what about when I am using LB controller instead, does draining happens there?". BM25 ranked the right post 15th. The question leans on "LB controller", and the post never says "controller" and says "LB" only twice. Every embedding model put it first.&lt;/p&gt;

&lt;p&gt;Some "misses" weren't really misses. One generated question asked why &lt;code&gt;pkill -f&lt;/code&gt; kills the shell it runs from. I've made that same mistake, and written it up, in four different posts, so a method that returned one of the other three wasn't wrong. It just didn't match my answer key. A collection by one author repeats itself more than I'd assumed.&lt;/p&gt;

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

&lt;p&gt;With the best retrieval in front of it, Haiku 5.5 cited the post each question came from in 58 of 60 answers. When the sections didn't contain the answer, it said so. One reader asked how long a Redis &lt;code&gt;BGSAVE&lt;/code&gt; takes on a realistic dataset, and the post never covers that. The answer said the sections don't mention it and stopped.&lt;/p&gt;

&lt;p&gt;The failure worth knowing about came from questions addressed to me. A reader had asked under the Droplet snapshot post, "Did you try one where Postgres had synchronous_commit = off?". The answer began "Yes", and went on to describe a different post, the one comparing Postgres and MongoDB, where the managed Postgres did have &lt;code&gt;synchronous_commit&lt;/code&gt; off. Every sentence in it was true. The answer to the reader's actual question was no. A question in the second person, "did you", gets matched to any post where I did something similar.&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%2Fe91r0n8pkxbu1aye3dpm.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%2Fe91r0n8pkxbu1aye3dpm.png" alt="The web UI answering &amp;quot;Did you try one where Postgres had synchronous_commit = off?&amp;quot; with &amp;quot;Yes&amp;quot;, citing the Postgres and MongoDB post" width="800" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Answering all 68 questions cost $0.037, about $0.0005 each. Finding the sections took a median of 1.4 seconds, most of it two network calls, the query embedding and the rerank. Writing the answer took a median of 4.2 seconds.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it cost
&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%2Fgadoawa9wpjgapgefz49.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%2Fgadoawa9wpjgapgefz49.png" alt="Bar chart of what the project's inference cost, by step" width="800" height="294"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All the inference for this project, including every test run, came to about 16 cents. More than half of that was Sonnet 5.5 writing the 60 test questions. The tool itself costs almost nothing to run. Embedding everything again costs under a cent, and a question costs about $0.0005.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong
&lt;/h2&gt;

&lt;p&gt;I expected the combined BM25 and embedding search to come out on top. It had the best top 5, but it put the right post first no more often than either embedding model alone.&lt;/p&gt;

&lt;p&gt;My first download stopped halfway with a JSON error. dev.to had rate-limited me, and my code tried to read the refusal as JSON. The fetcher now backs off and retries.&lt;/p&gt;

&lt;p&gt;The first answer I tried ended in the middle of a word. I raised the token limit and ran the same question again, and it finished normally. I couldn't make it happen again in 68 more answers, so I can't say what caused it.&lt;/p&gt;

&lt;p&gt;And the first CI run of the repository failed on my own quoting in the workflow file, before it got as far as the tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats
&lt;/h2&gt;

&lt;p&gt;This is one author's 76 posts, each about a fairly distinct topic, which is an easy case for search. The 60 test questions were written by a model from the very sections they're scored against, and some kept a product name like Temporal where no plainer word existed, which helps keyword search. Eight reader questions are too few to rank methods on. Each method ran once.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd take from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Try BM25 before embeddings on a small collection. Here it found the right post first five times out of six.&lt;/li&gt;
&lt;li&gt;If you add one model, add a reranker. It closed most of the gap for keyword search, at about three thousandths of a cent per question.&lt;/li&gt;
&lt;li&gt;The cheaper embedding model, &lt;code&gt;bge-m3&lt;/code&gt;, did as well as the one that costs twice as much.&lt;/li&gt;
&lt;li&gt;Watch questions that say "you". They ask about a specific post, and similar work in another post will be offered as the answer.&lt;/li&gt;
&lt;li&gt;Under a thousand sections doesn't need a vector database. A NumPy array in memory was enough.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>digitalocean</category>
      <category>ai</category>
      <category>python</category>
      <category>rag</category>
    </item>
    <item>
      <title>Uploading straight from the browser to DigitalOcean Spaces</title>
      <dc:creator>Remdore</dc:creator>
      <pubDate>Mon, 16 Nov 2026 14:47:04 +0000</pubDate>
      <link>https://dev.to/remdore/uploading-straight-from-the-browser-to-digitalocean-spaces-4dlj</link>
      <guid>https://dev.to/remdore/uploading-straight-from-the-browser-to-digitalocean-spaces-4dlj</guid>
      <description>&lt;p&gt;&lt;a href="https://github.com/oceanforge/spaces-gallery" rel="noopener noreferrer"&gt;Spaces Gallery&lt;/a&gt; is a small Flask app I maintain that uploads images to DigitalOcean Spaces and shows them in a gallery. Right now every upload goes through the app. The browser sends the file to Flask, Flask checks it, makes a thumbnail and writes both to Spaces.&lt;/p&gt;

&lt;p&gt;The usual advice is to skip that middle step. The app hands the browser a presigned POST, a short-lived signed form, and the browser sends the file straight to Spaces. I built that into the gallery and measured what it changes, using the app's own code and deployment setup.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;The app ran under gunicorn exactly as its &lt;code&gt;Procfile&lt;/code&gt; starts it, which means one sync worker, on a 1 GB Droplet in Frankfurt. The Spaces bucket was in Frankfurt too. My laptop played the browser, uploading noise PNGs of 1, 4 and 8 MB that can't be compressed. On the Droplet, a sampler recorded the app's CPU time, memory and network traffic four times a second.&lt;/p&gt;

&lt;p&gt;The direct path has three steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The page asks the app for a presigned POST. The policy pins the object key, the content type and the ACL, and caps the size at 8 MB.&lt;/li&gt;
&lt;li&gt;The browser posts the file to Spaces.&lt;/li&gt;
&lt;li&gt;The page tells the app it's done. The app downloads the file, checks that it really is an image, makes the thumbnail and sets the cache header.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That last step exists because a policy can limit a file's size and declared type, but it can't look inside it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Spaces enforces the policy
&lt;/h2&gt;

&lt;p&gt;Before any timing, I checked that Spaces actually holds the line:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A file sent with &lt;code&gt;Content-Type: text/html&lt;/code&gt; against a policy that says &lt;code&gt;image/png&lt;/code&gt; got a 403.&lt;/li&gt;
&lt;li&gt;A 9 MB file against the 8 MB limit got a 400.&lt;/li&gt;
&lt;li&gt;A five-byte file called &lt;code&gt;fake.png&lt;/code&gt; was accepted, since the policy can't tell. The app's check then found it wasn't an image and deleted it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the size and type limits move from the app to Spaces, and the "is this really an image" check stays in the app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cache-Control is checked and then thrown away
&lt;/h2&gt;

&lt;p&gt;The gallery gives every upload &lt;code&gt;Cache-Control: public, max-age=31536000, immutable&lt;/code&gt;, so the CDN and browsers keep images for a year. I put that header in the presigned policy like the others. The upload worked, and the stored object had no &lt;code&gt;Cache-Control&lt;/code&gt; at all.&lt;/p&gt;

&lt;p&gt;Spaces does read the condition. Leaving the field out or sending a different value got a 403. But with the right value, the object was stored without the header. The lowercase field name behaved the same. The thumbnail, written by the app through the normal API, had the header as expected.&lt;/p&gt;

&lt;p&gt;The fix is a copy of the object onto itself, with the metadata replaced, in the finish step. That's one request, and no file data passes through the app for it. After it, the public URL returned the one-year cache header.&lt;/p&gt;

&lt;h2&gt;
  
  
  For one upload, it wasn't faster
&lt;/h2&gt;

&lt;p&gt;I expected the direct path to win easily. Over five runs of each size, the medians were:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;File&lt;/th&gt;
&lt;th&gt;Through the app&lt;/th&gt;
&lt;th&gt;Direct&lt;/th&gt;
&lt;th&gt;Direct, sending to Spaces only&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1 MB&lt;/td&gt;
&lt;td&gt;0.73 s&lt;/td&gt;
&lt;td&gt;1.15 s&lt;/td&gt;
&lt;td&gt;0.08 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4 MB&lt;/td&gt;
&lt;td&gt;0.86 s&lt;/td&gt;
&lt;td&gt;0.87 s&lt;/td&gt;
&lt;td&gt;0.16 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8 MB&lt;/td&gt;
&lt;td&gt;1.04 s&lt;/td&gt;
&lt;td&gt;1.05 s&lt;/td&gt;
&lt;td&gt;0.26 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The transfer to Spaces was quick. My connection is fast, and 8 MB took a quarter of a second. But the direct path adds two calls to the app around it. For the 8 MB file, the presign took 0.21 s and the finish step 0.57 s. Those two together cost as much as the transfer saved, and for small files they cost more.&lt;/p&gt;

&lt;h2&gt;
  
  
  The app still touched every byte
&lt;/h2&gt;

&lt;p&gt;The sampler first said that the proxied upload received 8 MB and sent almost nothing to Spaces. That couldn't be right. The traffic to Spaces in the same region was going over the Droplet's second network interface, &lt;code&gt;eth1&lt;/code&gt;, which I hadn't been counting. With both interfaces counted, an 8 MB upload looked like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Through the app:&lt;/strong&gt; 8.3 MB in from the client and 8.4 MB out to Spaces, the file plus its thumbnail.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Direct:&lt;/strong&gt; nothing from the client, but 8.0 MB in from Spaces during the finish step, which downloads the file to check it, and 0.4 MB out for the thumbnail.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;CPU time was about the same either way, 0.53 to 0.6 seconds per upload, almost all of it Pillow decoding the image and making the thumbnail. The direct path moved the upload off the app, but the finish step brings the file straight back.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ten at once
&lt;/h2&gt;

&lt;p&gt;With ten 8 MB uploads started together at full speed, the single worker handled them one at a time either way. Through the app, they finished about 0.9 seconds apart, the last after 9.0 seconds. A health check sent during the batch waited 8.8 seconds for an answer.&lt;/p&gt;

&lt;p&gt;Direct, all ten finished in 7.6 seconds and the health check waited up to 4.3. Better, because the transfers themselves ran in parallel, but the finish steps still queued behind each other on the one worker.&lt;/p&gt;

&lt;h2&gt;
  
  
  Slow clients are where it matters
&lt;/h2&gt;

&lt;p&gt;A laptop on a fast connection is the best case for proxying. So I throttled three clients to 1 MB per second and had each upload 8 MB, while a health check ran every half second.&lt;/p&gt;

&lt;p&gt;Every upload took between 8.6 and 10.4 seconds either way, since the connection set the pace. The difference was everyone else. Through the app, one health check took 10.1 seconds, the whole length of the batch. The worker was busy reading slow request bodies and nothing else got in. Direct, the slowest of 25 health checks took 0.87 seconds. The app only saw the quick presign and finish calls, and the slow part happened between the browser and Spaces.&lt;/p&gt;

&lt;p&gt;That's the real argument for direct uploads with a single small worker. They don't make one upload faster, they stop slow uploads from freezing the app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Without CORS, uploads fail and succeed at the same time
&lt;/h2&gt;

&lt;p&gt;A browser will only let the page post to Spaces if the bucket allows the app's origin. I tried it first without a CORS rule. The page's &lt;code&gt;fetch&lt;/code&gt; threw "Failed to fetch", so it showed an error and never called the finish step.&lt;/p&gt;

&lt;p&gt;The file was in the bucket anyway. A plain form POST doesn't need the browser to ask permission first. It sends the request and then refuses to let the page read the response. So Spaces stored the upload, and the page believed it had failed. Two test images ended up in the gallery with no thumbnail, no cache header and no image check.&lt;/p&gt;

&lt;p&gt;Adding a CORS rule for the app's origin, allowing &lt;code&gt;POST&lt;/code&gt;, fixed the browser side. I also changed the page so that a network error still goes on to the finish step, which either finds the file and completes it or reports it missing. With the rule removed again, an upload from Chrome then finished normally, thumbnail and all.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong
&lt;/h2&gt;

&lt;p&gt;I expected the direct path to be faster per upload. On a fast connection it wasn't, and for a 1 MB file it was slower, because two extra calls to the app cost more than the transfer.&lt;/p&gt;

&lt;p&gt;My first traffic numbers were wrong, because the sampler only counted &lt;code&gt;eth0&lt;/code&gt;. They made it look as though the proxied upload never reached Spaces.&lt;/p&gt;

&lt;p&gt;I assumed a &lt;code&gt;Cache-Control&lt;/code&gt; field in the policy would set the header, since Spaces checks it. It doesn't, and I'd have shipped uploads without their year-long cache header if I hadn't looked at the stored object.&lt;/p&gt;

&lt;p&gt;And I took "Failed to fetch" to mean the upload had failed. It meant the browser wouldn't show the page the answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats
&lt;/h2&gt;

&lt;p&gt;This is one Droplet size, with the single worker the &lt;code&gt;Procfile&lt;/code&gt; gives, and one region, with my laptop as the client. The slow clients were throttled in software. The single-upload timings are five runs each, and the concurrent and slow tests ran once. I ran the app on a Droplet so I could watch its processes. On App Platform, the load balancer in front of the app might buffer request bodies, which would change the slow-client result, and I didn't test that. The bucket and the Droplet existed for about 15 minutes, which cost well under a cent.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd take from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use presigned POSTs to protect the app from slow uploads, not to make uploads faster. On a fast connection they were no quicker.&lt;/li&gt;
&lt;li&gt;Put the size and type limits in the policy, because Spaces enforces them, and keep a server-side check for what a policy can't see.&lt;/li&gt;
&lt;li&gt;Don't rely on the policy for &lt;code&gt;Cache-Control&lt;/code&gt;. Set it afterwards with a copy onto the same key.&lt;/li&gt;
&lt;li&gt;Add the CORS rule before switching the page over, and treat a network error from the upload as "unknown", not "failed".&lt;/li&gt;
&lt;li&gt;If the server still downloads every file to check it, the bytes come back anyway. The thumbnail step is the next thing to move.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>digitalocean</category>
      <category>python</category>
      <category>webdev</category>
      <category>flask</category>
    </item>
    <item>
      <title>Deploying new Temporal workflow code while workflows are running</title>
      <dc:creator>Remdore</dc:creator>
      <pubDate>Mon, 16 Nov 2026 14:13:41 +0000</pubDate>
      <link>https://dev.to/remdore/deploying-new-temporal-workflow-code-while-workflows-are-running-4150</link>
      <guid>https://dev.to/remdore/deploying-new-temporal-workflow-code-while-workflows-are-running-4150</guid>
      <description>&lt;p&gt;A Temporal workflow can run for minutes, days or months, and the code behind it will change while it runs. Temporal's answer is that workflow code must be deterministic: whenever a worker picks a workflow up, it replays the code against the recorded history, and the code has to make the same decisions it made the first time. In &lt;a href="https://dev.to/remdore/temporal-finished-my-workflow-exactly-once-and-ran-its-first-step-four-times-59dh"&gt;an earlier post&lt;/a&gt; I replayed one saved history against edited versions of a workflow to see what that check accepts.&lt;/p&gt;

&lt;p&gt;This time I wanted the operational version of the question. If you deploy new workflow code while a hundred workflows are halfway through, which ones break, when do you find out, what does a broken workflow look like, and which of the usual fixes actually fixes it?&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;Everything ran locally on the Temporal CLI's development server, version 1.10.1 with Server 1.32.2, and the Python SDK 1.36.1.&lt;/p&gt;

&lt;p&gt;The workflow has eight steps. Each step is an activity, and after each one the workflow sleeps for 15 seconds, so a single run takes about two minutes. Every activity appends a line to a log file before returning, which stands in for a real side effect and lets me count exactly what ran.&lt;/p&gt;

&lt;p&gt;The new version adds one thing, an &lt;code&gt;audit&lt;/code&gt; activity right after step 4:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;STEPS&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="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;4&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;audit&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="n"&gt;workflow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;NAP&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's a common kind of change: a new call in the middle of an existing flow. For each scenario I started 100 workflows over 60 seconds, so they were spread across every stage, then changed the workers 70 seconds after the first start. Afterwards I read every workflow's history and its side effects.&lt;/p&gt;

&lt;h2&gt;
  
  
  A plain restart broke everything past the change
&lt;/h2&gt;

&lt;p&gt;Stopping the old worker and starting the new one split the workflows cleanly by how far they'd got:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;58 hadn't reached step 4 yet. They carried on with the new code, ran the audit once and completed.&lt;/li&gt;
&lt;li&gt;42 had already finished step 4. Every one of them broke.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The error was the same for all 42:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[TMPRL1100] Nondeterminism error: Activity machine does not handle this event: HistoryEvent(id: 44, TimerStarted)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The history says that after step 4 the workflow started a timer. The new code, replaying that history, wanted to schedule the audit activity instead. The two can't be reconciled, so the worker refuses to continue.&lt;/p&gt;

&lt;p&gt;None of this happened at the moment of the deploy. Each workflow failed when its next timer fired and the new worker had to replay it, between 0.2 and 14.6 seconds after the switch.&lt;/p&gt;

&lt;h2&gt;
  
  
  A broken workflow doesn't look broken
&lt;/h2&gt;

&lt;p&gt;I expected these workflows to fail. They didn't. All 42 stayed in the Running state for the rest of the run, about six minutes, and would have stayed there. Temporal treats a nondeterminism error as a failed workflow task, not a failed workflow, and keeps retrying the task in case a fixed worker turns up. By the end each one was on its 9th or 10th attempt.&lt;/p&gt;

&lt;p&gt;The history doesn't make it obvious either. Each broken workflow had exactly one &lt;code&gt;WorkflowTaskFailed&lt;/code&gt; event, however many retries followed. The retries showed up only in the attempt count of the pending task and as warnings in the worker's log. A dashboard that counts failed workflows would have shown zero.&lt;/p&gt;

&lt;h2&gt;
  
  
  A rolling deploy was worse
&lt;/h2&gt;

&lt;p&gt;Next I ran the old and new workers side by side for a minute before stopping the old one, the way a rolling deploy would. I expected the new worker to take over gradually. It ran nothing at all, not one workflow task and not one activity.&lt;/p&gt;

&lt;p&gt;Workflows stay on the worker that already has them in memory, so the old worker kept running all of them, on the old code, straight past step 4. When it stopped, the new worker had to replay every workflow that was still running, and 83 of them broke, between 60 and 75 seconds after the new worker had started. Only the 17 that finished during the overlap completed.&lt;/p&gt;

&lt;p&gt;So the overlap didn't soften anything. It just let more workflows get past the point where the new code differs.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;patched()&lt;/code&gt; is what works
&lt;/h2&gt;

&lt;p&gt;The fix Temporal documents is to guard the change:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;workflow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;patched&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"audit-after-4"&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;audit&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;When a workflow runs that code for the first time, &lt;code&gt;patched()&lt;/code&gt; returns true and records a marker in the history. When a worker replays a history that has no marker, it returns false, and the workflow follows the old path.&lt;/p&gt;

&lt;p&gt;With the same restart, all 100 completed. The 58 that hadn't reached step 4 ran the audit. The 42 that had passed it skipped it, as their history said they should. No workflow task failed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rolling back made a different set stuck
&lt;/h2&gt;

&lt;p&gt;Suppose you shipped the unpatched version anyway, saw the errors and rolled back. I tried that, going back to the old code 80 seconds after the bad deploy.&lt;/p&gt;

&lt;p&gt;The 42 stuck workflows recovered. Their histories matched the old code again, and they completed. But by then 58 workflows had run the new audit step, and 8 of those had finished. The other 50 now had an audit in their history that the old code didn't expect, and they broke instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[TMPRL1100] Nondeterminism error: Timer machine does not handle this event: HistoryEvent(id: 44, ActivityTaskScheduled)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Across the deploy and the rollback, 92 of the 100 workflows hit a nondeterminism error at some point.&lt;/p&gt;

&lt;h2&gt;
  
  
  Patching after the fact didn't save them either
&lt;/h2&gt;

&lt;p&gt;The obvious next move is to fix forward: deploy the patched version on top of the broken one. I ran the same bad deploy and replaced it with the patched code 80 seconds later.&lt;/p&gt;

&lt;p&gt;The result matched the rollback, number for number. The 42 old-shaped workflows had no marker, so &lt;code&gt;patched()&lt;/code&gt; sent them down the old path and they completed. The 50 that had run the unpatched audit also had no marker, because the unpatched code never wrote one. So &lt;code&gt;patched()&lt;/code&gt; returned false for them as well, the code skipped an audit their history said had happened, and they broke.&lt;/p&gt;

&lt;p&gt;There's no version of the code that can satisfy both groups. Neither history says which code produced it, and &lt;code&gt;patched()&lt;/code&gt; only knows about markers that patched code wrote.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resetting gets them out, and runs things twice
&lt;/h2&gt;

&lt;p&gt;The way out for those 50 is a reset. Temporal can rewind a workflow to an earlier workflow task, throw away everything after it and run the rest again with the current code. I reset each one to the task that had scheduled the unpatched audit, with the patched worker running.&lt;/p&gt;

&lt;p&gt;All 50 completed within 80 seconds. But a reset means re-running, and the log showed it: the 50 audits ran a second time, and the steps after step 4 ran again too. 175 step executions were duplicates of ones that had already happened. A reset is only safe if everything after the reset point can run twice.&lt;/p&gt;

&lt;p&gt;In every other scenario, nothing ran twice. A stuck workflow simply stopped, which is the one comforting part of all this.&lt;/p&gt;

&lt;h2&gt;
  
  
  The numbers in one place
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Completed&lt;/th&gt;
&lt;th&gt;Stuck at the end&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Restart onto unpatched code&lt;/td&gt;
&lt;td&gt;58&lt;/td&gt;
&lt;td&gt;42&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Old and new workers overlapping for 60 s&lt;/td&gt;
&lt;td&gt;17&lt;/td&gt;
&lt;td&gt;83&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Restart onto &lt;code&gt;patched()&lt;/code&gt; code&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Unpatched deploy, then rollback&lt;/td&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Unpatched deploy, then patched code&lt;/td&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;...then a reset of the 50&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;0, with 225 side effects repeated&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  What I got wrong
&lt;/h2&gt;

&lt;p&gt;I expected the rolling deploy to be the gentle option, with the new worker picking up work bit by bit while the old one was still around. The new worker didn't run a single task or activity during the overlap. I didn't dig into why the activities stayed on the old worker too.&lt;/p&gt;

&lt;p&gt;I also assumed a rollback was the safe undo. It is only if nothing ran on the new code in between, and with timers firing every 15 seconds, plenty did within 80 seconds.&lt;/p&gt;

&lt;p&gt;And my first analysis reported that the workflows had failed two hours before the deploy. I'd converted the event timestamps with a function that treats them as local time, and my laptop is two hours ahead of UTC. Reading the raw seconds fixed it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats
&lt;/h2&gt;

&lt;p&gt;This is the Python SDK on a local dev server, with one kind of change: an activity added in the middle. Removing a step would break in its own way, and the earlier post showed that reordering activities or changing a timeout doesn't trip the check at all. Each scenario ran once. I didn't try Temporal's worker versioning, which pins running workflows to the build they started on and is meant for exactly this problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd take from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Every change to a workflow's sequence of steps needs &lt;code&gt;workflow.patched()&lt;/code&gt; from the first deploy. It's the only option here that lost nothing and repeated nothing.&lt;/li&gt;
&lt;li&gt;Don't rely on a rollback or a later patch to undo an unpatched deploy. Both rescue one group of workflows by breaking another.&lt;/li&gt;
&lt;li&gt;Alert on workflow task failures or nondeterminism warnings, not on failed workflows. Broken workflows stay "Running".&lt;/li&gt;
&lt;li&gt;Running old and new workers side by side doesn't move workflows to the new code. It moves them further down the old path.&lt;/li&gt;
&lt;li&gt;If you need a reset, assume everything after the reset point runs again.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>distributedsystems</category>
      <category>backend</category>
      <category>devops</category>
    </item>
    <item>
      <title>Snapshotting a DigitalOcean Droplet while it's running</title>
      <dc:creator>Remdore</dc:creator>
      <pubDate>Sat, 14 Nov 2026 07:10:41 +0000</pubDate>
      <link>https://dev.to/remdore/snapshotting-a-digitalocean-droplet-while-its-running-4m3c</link>
      <guid>https://dev.to/remdore/snapshotting-a-digitalocean-droplet-while-its-running-4m3c</guid>
      <description>&lt;p&gt;DigitalOcean lets you snapshot a Droplet while it's running, and its docs are careful about it. They say a live snapshot "may result in performance degradation and compromise data consistency", and that many databases only guarantee a consistent disk if you stop them or power the Droplet off first. That's sensible advice. I wanted to know what it means in practice: what a snapshot of a busy Droplet contains when you restore it, whether the Droplet slows down while it's taken, and what powering off first actually costs you.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;One Droplet in Frankfurt, the 2 GB / 1 vCPU size with a 50 GB disk, running Ubuntu 24.04 and Postgres 16 with its default settings. On it, two writers ran the whole time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Postgres.&lt;/strong&gt; One numbered row per transaction, about 100 a second. Every insert logged when it was sent and how long the commit took.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Files.&lt;/strong&gt; The same fixed-width numbered line, about 100 a second, appended to two files. One file got an &lt;code&gt;fsync&lt;/code&gt; after every line. The other was only written, so its lines sat in the page cache until Linux decided to flush them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then I took snapshots through the API, timed them by polling the action, restored each one to a new Droplet and looked at what was on the disk. Each restored copy was destroyed as soon as I had checked it, and each snapshot deleted.&lt;/p&gt;

&lt;p&gt;I did six live snapshots: three with about 2.3 GB on the disk, one at 13 GB, one at 29 GB, and one after deleting the extra data again. I filled the disk with random data so nothing could compress it. Then there was one snapshot with the Droplet powered off, for comparison.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Droplet didn't notice
&lt;/h2&gt;

&lt;p&gt;I half expected writes to slow down while the snapshot was being taken. They didn't. During the 13 to 184 seconds each snapshot took, the 99th percentile of Postgres commit times stayed between 2.8 and 5.7 ms, no higher than the 5.5 to 6.5 ms of the rest of the run. The longest gap between two consecutive writes during any snapshot was 38 ms, and outside the snapshots it went up to 42 ms.&lt;/p&gt;

&lt;p&gt;So on this Droplet, at this write rate, the "performance degradation" the docs mention didn't show up at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  The disk is frozen three seconds after you ask
&lt;/h2&gt;

&lt;p&gt;Every live snapshot captured the disk at a single moment, between 3.0 and 3.25 seconds after I sent the request. I can see that moment precisely because both writers stamp their lines with the time: in the restored copy, the last row in Postgres and the last line in the fsynced file were always within 7 milliseconds of each other. Everything written after that moment was missing, and nothing written before it was.&lt;/p&gt;

&lt;p&gt;That makes a live snapshot the same as pulling the power cable at that instant. Which is a case Postgres is built for.&lt;/p&gt;

&lt;h2&gt;
  
  
  Postgres was fine every time
&lt;/h2&gt;

&lt;p&gt;Every restored copy came up with Postgres saying "database system was not properly shut down; automatic recovery in progress". It replayed its write-ahead log for 0.13 to 0.64 seconds and started. The table was complete in all six: no gaps in the numbering, every row up to the moment of the freeze, nothing half-written. The fsynced file was the same. Not one torn or damaged line in six snapshots.&lt;/p&gt;

&lt;p&gt;So the docs' warning about databases is worth taking seriously, but for Postgres with its default &lt;code&gt;fsync&lt;/code&gt; and &lt;code&gt;full_page_writes&lt;/code&gt; on, a live snapshot is a crash it knows how to recover from. A database or an app that doesn't flush its writes is a different story, which the other file showed.&lt;/p&gt;

&lt;h2&gt;
  
  
  The file without fsync was up to 26 seconds behind
&lt;/h2&gt;

&lt;p&gt;The file that was never fsynced was behind in every live snapshot, by between 0.7 and 26.4 seconds. And it didn't just stop early. Each one ended with a run of zero bytes, between 704 and 3,392 of them, where lines should have been. The file's size had already been saved, always on a 4 KB boundary, but the last stretch of its contents hadn't reached the disk.&lt;/p&gt;

&lt;p&gt;The 26 seconds made sense once I looked at how the disk is mounted. DigitalOcean's Ubuntu image mounts the root filesystem with &lt;code&gt;commit=30&lt;/code&gt;, so ext4 only commits its journal every 30 seconds, instead of the usual 5. Data that's only in the page cache can be up to 30 seconds old at the moment the snapshot freezes it.&lt;/p&gt;

&lt;p&gt;If your app writes logs, uploads or a queue to plain files without fsyncing them, a live snapshot can lose the last half minute of them, and leave zeros behind instead of a clean cut.&lt;/p&gt;

&lt;h2&gt;
  
  
  Powering off first
&lt;/h2&gt;

&lt;p&gt;With the Droplet shut down through the API, the snapshot had nothing to catch in flight. The restored copy had every row and every line in both files, and Postgres started without any recovery.&lt;/p&gt;

&lt;p&gt;The cost is downtime. From the shutdown request until I could SSH back in was 66 seconds: 8 to shut down, 32 for the snapshot, and 26 for the power-on action and the boot. A 2.3 GB snapshot taken live took 13 to 35 seconds, and the Droplet kept serving the whole time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bigger disks take longer, both ways
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Data on disk&lt;/th&gt;
&lt;th&gt;Snapshot size&lt;/th&gt;
&lt;th&gt;Snapshot took&lt;/th&gt;
&lt;th&gt;Restored Droplet active after&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2.3 GB&lt;/td&gt;
&lt;td&gt;2.27–2.33 GB&lt;/td&gt;
&lt;td&gt;13–35 s&lt;/td&gt;
&lt;td&gt;34–37 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13 GB&lt;/td&gt;
&lt;td&gt;13.04 GB&lt;/td&gt;
&lt;td&gt;147 s&lt;/td&gt;
&lt;td&gt;95 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;29 GB&lt;/td&gt;
&lt;td&gt;29.16 GB&lt;/td&gt;
&lt;td&gt;184 s&lt;/td&gt;
&lt;td&gt;114 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The snapshot size followed the data on the disk, not the 50 GB size of the disk. The time to take it grew, but not in step with the size: 13 times the data took about 5 to 14 times as long. Restoring grew too. A Droplet created from the 29 GB snapshot took 114 seconds to become active, three times as long as one from the small snapshot, plus another 10 to 20 seconds before SSH answered.&lt;/p&gt;

&lt;p&gt;Since DigitalOcean charges $0.06 per GB a month for snapshots, based on the size of the snapshot, that 29 GB one would have cost about $1.75 a month to keep.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deleting data shrinks the next snapshot
&lt;/h2&gt;

&lt;p&gt;After the 29 GB snapshot I deleted the random files and took another one. It was 2.33 GB. I'd expected it to stay big until I ran &lt;code&gt;fstrim&lt;/code&gt;, since deleting a file only marks its blocks free in the filesystem. But the same mount options include &lt;code&gt;discard&lt;/code&gt;, so ext4 tells the disk about freed blocks straight away. Running &lt;code&gt;fstrim&lt;/code&gt; afterwards reported 21.1 GiB trimmed, and the snapshot after that was still 2.33 GB.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong
&lt;/h2&gt;

&lt;p&gt;I thought the snapshot would have to include the deleted data, and planned the &lt;code&gt;fstrim&lt;/code&gt; step to show how much it would save. It saved nothing, because the image already discards on delete. I should have looked at the mount options before designing that part.&lt;/p&gt;

&lt;p&gt;I also tried to measure the clock difference between my laptop and the Droplet over SSH, so I could line the freeze moment up with the API's timeline. Each round trip took half a second, mostly connection setup, so the result was useless. I measured everything against the request time recorded on my side and the timestamps written on the Droplet instead, and both clocks were synced over NTP.&lt;/p&gt;

&lt;p&gt;And my first comparison of write latency "during" and "outside" the snapshot showed a 46-second gap outside it. That was my script measuring straight across the window it was supposed to leave out. The real longest gap was 42 ms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats
&lt;/h2&gt;

&lt;p&gt;This is one Droplet size, one region, one write rate, and Postgres with default settings. Each size was snapshotted once, and the timings at the small size varied from 13 to 35 seconds, so the bigger ones could vary as much. I didn't test Volumes, which aren't part of a Droplet snapshot, or databases other than Postgres.&lt;/p&gt;

&lt;p&gt;The whole run, eight snapshots and seven restored Droplets over about 35 minutes, cost less than five cents.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd take from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A live snapshot is a power cut at one moment, about three seconds after you ask. Anything that survives a power cut survives it.&lt;/li&gt;
&lt;li&gt;Postgres with default settings recovered in under a second every time, with nothing missing.&lt;/li&gt;
&lt;li&gt;Anything you write without fsync can be up to 30 seconds behind on these images, and the file may end in zeros. Stop those writers, or power off, if those files matter.&lt;/li&gt;
&lt;li&gt;Powering off gives you a clean copy for about a minute of downtime on a small Droplet.&lt;/li&gt;
&lt;li&gt;The snapshot is the size of your data, and deleted data really is gone from it on DigitalOcean's Ubuntu image.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>digitalocean</category>
      <category>postgres</category>
      <category>linux</category>
      <category>devops</category>
    </item>
    <item>
      <title>What happens to a Kafka consumer group when one consumer dies</title>
      <dc:creator>Remdore</dc:creator>
      <pubDate>Wed, 11 Nov 2026 12:20:13 +0000</pubDate>
      <link>https://dev.to/remdore/what-happens-to-a-kafka-consumer-group-when-one-consumer-dies-2n8k</link>
      <guid>https://dev.to/remdore/what-happens-to-a-kafka-consumer-group-when-one-consumer-dies-2n8k</guid>
      <description>&lt;p&gt;Kafka's promise to a consumer group is that if one consumer goes away, the others pick up its partitions. I wanted to see what that looks like from the consumers' side: how long the dead consumer's partitions sit unread, what happens to the messages it was in the middle of, and whether the consumers that stayed alive notice anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;I made a managed Kafka 4.3 cluster on DigitalOcean, the smallest size: three brokers with 2 vCPUs and 4 GB each, in Frankfurt. It was online about five and a half minutes after I asked for it. A small Droplet in the same private network ran the clients, using the Python &lt;code&gt;confluent-kafka&lt;/code&gt; package, which is librdkafka 2.16 underneath.&lt;/p&gt;

&lt;p&gt;Each run got its own topic with 6 partitions, replicated 3 times. A producer wrote numbered messages at 300 a second for 150 seconds, with &lt;code&gt;acks=all&lt;/code&gt; and idempotence on, and logged every acknowledgement. Three consumers in one group read them. Each message took 5 ms of "work", and each consumer logged every message it finished, with the partition and a timestamp.&lt;/p&gt;

&lt;p&gt;Forty seconds in, I took one consumer away in one of three ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SIGTERM.&lt;/strong&gt; The consumer catches it, finishes the message it's on and calls &lt;code&gt;close()&lt;/code&gt;, which tells the group it's leaving.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SIGKILL.&lt;/strong&gt; The process is gone, no goodbye.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SIGSTOP.&lt;/strong&gt; The process freezes and stops heartbeating but keeps its connections open. Sixty seconds later I sent SIGCONT to wake it up. This is the closest I could get to a long garbage collection pause or a VM that stalled.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I ran each of those with two commit setups, and with both group protocols Kafka 4 offers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Commits.&lt;/strong&gt; "Auto" is the default: the offset counts as done as soon as &lt;code&gt;poll()&lt;/code&gt; hands the message over, and it's committed every 5 seconds. "Manual" stores the offset only after the work is finished, still committed every 5 seconds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Protocols.&lt;/strong&gt; The classic rebalance protocol, and the new consumer protocol from KIP-848, where the broker works out the assignment. DigitalOcean's cluster had both turned on, so switching was one client setting, &lt;code&gt;group.protocol&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's 12 runs, plus one trial run before them. Afterwards I compared what the producer had acknowledged with what the consumers had finished.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nothing was lost
&lt;/h2&gt;

&lt;p&gt;In all 21 runs, counting the trial and eight I added later, every acknowledged message was processed at least once. That held for the auto commits too, which in theory can lose a message if the consumer dies after the offset is stored and before the work is done. With 5 ms of work per message that window is small, and I never hit it.&lt;/p&gt;

&lt;h2&gt;
  
  
  A clean shutdown costs very little
&lt;/h2&gt;

&lt;p&gt;With SIGTERM there were no duplicates in any run. The dead consumer's partitions were picked up by the others in 2.5 to 3 seconds with the classic protocol, and in 0.5 to 0.8 seconds with the new one.&lt;/p&gt;

&lt;p&gt;The new protocol also didn't disturb anyone else. With the classic protocol, every consumer gave up all of its partitions and got a new set, even the two that weren't going anywhere. That pause was short here, under 200 ms. With the new protocol, the two survivors kept what they had and each just received one more partition.&lt;/p&gt;

&lt;h2&gt;
  
  
  A crash costs 45 seconds
&lt;/h2&gt;

&lt;p&gt;With SIGKILL or SIGSTOP, the dead consumer's partitions sat unread for 40 to 49 seconds in every run, with either protocol. That's the session timeout. The group can't tell a crashed consumer from a slow one until 45 seconds pass without a heartbeat. In the new protocol the broker sets that timeout, with heartbeats every 5 seconds, which is part of why its runs spread from 40 to 49 seconds. The classic runs landed between 42 and 47.&lt;/p&gt;

&lt;p&gt;So the new protocol is much faster at a planned exit and no faster at a crash. If your consumers mostly die by deployment, it helps. If they die by OOM kill, it doesn't.&lt;/p&gt;

&lt;h2&gt;
  
  
  Every crash replayed work
&lt;/h2&gt;

&lt;p&gt;Each SIGKILL and SIGSTOP run in the main set produced between 459 and 493 duplicates. They were all messages the dead consumer had already finished, but whose offsets hadn't been committed yet. When its partitions moved, the new owner started from the last committed offset and did them again.&lt;/p&gt;

&lt;p&gt;Auto and manual commits made no difference to this. Both commit every 5 seconds, and both lose up to 5 seconds of progress in a crash. Manual storing only changes whether a message can be skipped, and nothing was skipped either way.&lt;/p&gt;

&lt;h2&gt;
  
  
  The survivors stalled too
&lt;/h2&gt;

&lt;p&gt;I expected the two remaining consumers to carry on as before. They didn't. Their own partitions, the ones they'd had all along, went quiet for 12 to 15 seconds after the takeover.&lt;/p&gt;

&lt;p&gt;The logs showed why. When a survivor got the dead consumer's partition, there were about 45 seconds of backlog waiting on it, around 2,400 messages. The consumer worked through that backlog as one block, which took about 13 seconds, before it returned to its own partitions. Its own messages kept arriving and just waited.&lt;/p&gt;

&lt;p&gt;With the classic protocol, the default assignor often gave both of the dead consumer's partitions to the same survivor: in 7 of 11 classic runs. That survivor then worked through two blocks, one after the other, about 26 seconds in all. In some of those runs it slipped a few of its own messages in between the two blocks, so its own partitions waited about 13 seconds. In three runs it didn't, and they waited 18 to 27 seconds. I don't know what decided that. The new protocol split the two partitions between the survivors in all 10 of its runs.&lt;/p&gt;

&lt;h2&gt;
  
  
  The frozen consumer knew it was dead
&lt;/h2&gt;

&lt;p&gt;I was most curious about the SIGSTOP case, because that's where the textbook warns about zombies. A consumer wakes up, still thinks it owns its partitions, and processes messages that someone else now owns.&lt;/p&gt;

&lt;p&gt;It barely happened. When the frozen process woke up, librdkafka noticed within 22 ms that its session had expired and reported the partitions as lost. Between waking and rejoining, it processed 0 to 4 messages per run, all of which the new owner had already done. Then it rejoined the group, 2.5 seconds later with the classic protocol and 5 seconds with the new one. That triggered another rebalance, so the comeback cost a second, smaller interruption.&lt;/p&gt;

&lt;p&gt;That's this client's behavior. librdkafka keeps its own track of when it last heard from the group, so it knew without asking. I didn't test other clients.&lt;/p&gt;

&lt;h2&gt;
  
  
  The duplicates depended on the clock
&lt;/h2&gt;

&lt;p&gt;The main runs all landed close to the maximum replay. With about 100 messages a second per consumer and a commit every 5 seconds, a crash can replay up to roughly 500. That looked suspicious, since the kill always came at the same second of the run.&lt;/p&gt;

&lt;p&gt;So I ran eight more SIGKILL runs with auto commits, four per protocol, killing at 41, 42, 43 and 44 seconds instead of 40. The duplicates came out as 79, 181, 291 and 378 with the classic protocol, and 84, 197, 286 and 369 with the new one. About 100 more for every second since the last commit. In the main runs, the kill had landed just before a commit every time.&lt;/p&gt;

&lt;p&gt;So the number to plan for isn't 480. It's anything from zero up to five seconds of a consumer's work, depending on when it dies.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong
&lt;/h2&gt;

&lt;p&gt;I thought the commit mode would matter most. I set up the whole matrix around auto versus manual, and it was the one setting that changed nothing measurable. The session timeout and the assignor decided almost everything.&lt;/p&gt;

&lt;p&gt;My first summary table was also wrong. For each run, it took the moment the first survivor in my list got one of the dead consumer's partitions, not the earliest moment either survivor did. One frozen-consumer run came out as a 62-second takeover when it was really 44 seconds. The 62 was the second rebalance, after the frozen consumer came back.&lt;/p&gt;

&lt;p&gt;I also explained the survivors' longest stalls wrong at first. After the main runs, I put them down to one survivor getting both of the dead consumer's partitions. The extra runs had that too, three times, and all three stalled for only about 13 seconds. Getting both partitions makes the longer stall possible, but it doesn't guarantee it.&lt;/p&gt;

&lt;p&gt;And my gap measurement started out naive. It measured the time between the last message before the kill and the first after, which counted the message the SIGTERM'd consumer finished on its way out as "after". I changed it to the longest silence on each partition in the two minutes after the kill.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats
&lt;/h2&gt;

&lt;p&gt;This is one client library, one message rate, and one size of work per message. The duplicates scale with how much a consumer gets through in 5 seconds, so a faster consumer replays more. Each combination ran once, apart from the extra runs above. The cluster was otherwise idle, and the clients sat in the same data center as the brokers.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd take from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Make consumers idempotent. A crash replayed up to 5 seconds of work, whichever commit mode I used. A shorter commit interval shrinks that, at the cost of more commits.&lt;/li&gt;
&lt;li&gt;Handle SIGTERM and call &lt;code&gt;close()&lt;/code&gt;. That's the difference between a 0.5-second handover with no duplicates and 45 seconds of silence plus a replay.&lt;/li&gt;
&lt;li&gt;If you're on Kafka 4 and librdkafka, try &lt;code&gt;group.protocol=consumer&lt;/code&gt;. It made planned exits about four times faster, didn't stop the other consumers, and spread the dead consumer's partitions more evenly.&lt;/li&gt;
&lt;li&gt;A lower session timeout shortens the crash case, and brings its own risk of kicking out consumers that are only slow.&lt;/li&gt;
&lt;li&gt;Watch the survivors, not just the dead one. Their own partitions stalled for 12 to 27 seconds while they caught up on someone else's backlog.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>kafka</category>
      <category>distributedsystems</category>
      <category>python</category>
      <category>devops</category>
    </item>
    <item>
      <title>Django 6.1's FETCH_PEERS against my own select_related</title>
      <dc:creator>Remdore</dc:creator>
      <pubDate>Tue, 10 Nov 2026 05:41:37 +0000</pubDate>
      <link>https://dev.to/remdore/django-61s-fetchpeers-against-my-own-selectrelated-4cp9</link>
      <guid>https://dev.to/remdore/django-61s-fetchpeers-against-my-own-selectrelated-4cp9</guid>
      <description>&lt;p&gt;Django 6.1 added fetch modes. With &lt;code&gt;FETCH_PEERS&lt;/code&gt;, when you touch a foreign key on one object from a queryset, Django loads that relation for every object the queryset returned, in one query. The classic N+1 loop becomes 2 queries without you writing &lt;code&gt;select_related&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;My football quiz site, ExtraTime, has 621 &lt;code&gt;select_related&lt;/code&gt; calls and 103 &lt;code&gt;prefetch_related&lt;/code&gt; calls in its Django API, outside the tests. I wanted to know how much of that work the new mode would have done for me.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I measured it
&lt;/h2&gt;

&lt;p&gt;The API has 6,635 tests, and a lot of them call the real endpoints through Django's test client. I installed Django 6.1.3 in a copy of the project, added a middleware that counts the SQL queries behind each request, and ran the whole suite six times:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the code as written&lt;/li&gt;
&lt;li&gt;with every &lt;code&gt;select_related&lt;/code&gt; call turned into a no-op&lt;/li&gt;
&lt;li&gt;the same, with &lt;code&gt;FETCH_PEERS&lt;/code&gt; on everywhere&lt;/li&gt;
&lt;li&gt;with both &lt;code&gt;select_related&lt;/code&gt; and &lt;code&gt;prefetch_related&lt;/code&gt; turned off&lt;/li&gt;
&lt;li&gt;the same, with &lt;code&gt;FETCH_PEERS&lt;/code&gt; on&lt;/li&gt;
&lt;li&gt;the code as written, with &lt;code&gt;FETCH_PEERS&lt;/code&gt; added on top&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Turning a method into a no-op was a small patch on &lt;code&gt;QuerySet&lt;/code&gt;. One exception: a &lt;code&gt;Prefetch&lt;/code&gt; with &lt;code&gt;to_attr&lt;/code&gt; stayed, because the code reads that attribute and would break without it. There's no setting for a global fetch mode. You set it per queryset with &lt;code&gt;.fetch_mode()&lt;/code&gt; or on a model's manager. For the experiment I changed the internal default that every new queryset starts with, which isn't a public API.&lt;/p&gt;

&lt;p&gt;To compare like with like, I kept only the routes the tests called the same number of times in every run: 467 routes and 3,963 requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  The totals
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;As written: 59,198 queries&lt;/li&gt;
&lt;li&gt;Without &lt;code&gt;select_related&lt;/code&gt;: 76,144&lt;/li&gt;
&lt;li&gt;Without &lt;code&gt;select_related&lt;/code&gt;, with &lt;code&gt;FETCH_PEERS&lt;/code&gt;: 64,416&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So taking out my &lt;code&gt;select_related&lt;/code&gt; calls added 16,946 queries, and &lt;code&gt;FETCH_PEERS&lt;/code&gt; won back 11,728 of them, about 69%. That's a lot for something you switch on rather than write.&lt;/p&gt;

&lt;p&gt;With both kinds of hand tuning removed, it was 74,955 queries, and 62,887 with &lt;code&gt;FETCH_PEERS&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Route by route, it never fully caught up
&lt;/h2&gt;

&lt;p&gt;The total hides how it gets there. &lt;code&gt;select_related&lt;/code&gt; made a difference on 179 routes. On none of them did &lt;code&gt;FETCH_PEERS&lt;/code&gt; get back to the hand-tuned count. It did better on 5, partly closed the gap on 59, and made no difference at all on 115.&lt;/p&gt;

&lt;p&gt;The biggest win was the endpoint that starts a Read the Room run: 2,245 queries over 153 requests as written, 8,018 without &lt;code&gt;select_related&lt;/code&gt;, and 2,725 with &lt;code&gt;FETCH_PEERS&lt;/code&gt;. That's the case it's made for, a list of objects that all touch the same relations. It still lands about 3 queries per request above the hand-tuned version, because each relation costs one extra query instead of being part of a join.&lt;/p&gt;

&lt;p&gt;The 115 routes where it did nothing come down to two things, which I checked separately on Django's own &lt;code&gt;Permission&lt;/code&gt; model, 16 rows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One object has no peers.&lt;/strong&gt; Loading a single permission and reading its content type takes 2 queries with or without &lt;code&gt;FETCH_PEERS&lt;/code&gt;, and 1 with &lt;code&gt;select_related&lt;/code&gt;. A lot of my endpoints load one game session and then walk its foreign keys. &lt;code&gt;FETCH_PEERS&lt;/code&gt; can't help there.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.iterator()&lt;/code&gt; switches it off in practice.&lt;/strong&gt; Looping over the list and reading each content type takes 17 queries normally and 2 with &lt;code&gt;FETCH_PEERS&lt;/code&gt;. The same loop over &lt;code&gt;.iterator()&lt;/code&gt; takes 17 either way. The peers are the objects already loaded, and an iterator hasn't loaded the others yet when the first one asks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The second one showed up in a place I didn't expect. The admin's "add group" page went from 14 queries to 1,198 without &lt;code&gt;select_related&lt;/code&gt;, and &lt;code&gt;FETCH_PEERS&lt;/code&gt; didn't change it at all. Form choice fields iterate over their queryset with &lt;code&gt;.iterator()&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The prefetch that cost more than it saved
&lt;/h2&gt;

&lt;p&gt;I expected that removing &lt;code&gt;prefetch_related&lt;/code&gt; could only add queries. On 34 routes it removed them, 2,762 in total, almost all on the multiplayer game rooms.&lt;/p&gt;

&lt;p&gt;Inviting a player to a room took 668 queries over 45 requests as written, and 162 without the prefetches. The SQL showed why. The room viewset's queryset prefetches the config table of every game type, 8 of them, so that the lobby list, which mixes game types, doesn't query per room. But the same queryset is used to look up a single room for actions like invite, leave and ready. Each of those requests paid 8 queries for config tables it never read.&lt;/p&gt;

&lt;p&gt;It's easy to miss in the code, because the prefetch lives in a shared helper. It only stood out once each request's queries were counted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Turning it on over code that's already tuned
&lt;/h2&gt;

&lt;p&gt;With &lt;code&gt;FETCH_PEERS&lt;/code&gt; on top of the code as written, the suite had exactly the same failures as without it, and the query count dropped by 412, under 1%. 22 routes got cheaper and 6 got slightly more expensive, by between 1 and 5 queries over all their requests. I didn't track down why those 6 went up.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tests noticed
&lt;/h2&gt;

&lt;p&gt;Without &lt;code&gt;select_related&lt;/code&gt;, 76 tests failed against 7 as written. With &lt;code&gt;FETCH_PEERS&lt;/code&gt;, 50 did. Many of the extra failures weren't wrong answers. They were tests that pin a query count, and this codebase has a lot of them: 92 uses of &lt;code&gt;assertNumQueries&lt;/code&gt; and 286 of &lt;code&gt;CaptureQueriesContext&lt;/code&gt;. That's what makes hand tuning hold up over time. Without those tests, a &lt;code&gt;select_related&lt;/code&gt; quietly stops covering what the view reads after the next change.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two things about upgrading to 6.1 itself
&lt;/h2&gt;

&lt;p&gt;Two things came up that have nothing to do with fetch modes. &lt;code&gt;django-celery-beat&lt;/code&gt; still declares it doesn't support Django 6.1, so I had to force the install. And five tests broke for real. Querysets combined with &lt;code&gt;.union()&lt;/code&gt; now apply the model's default ordering, and three places in the code union &lt;code&gt;values_list()&lt;/code&gt; queries on models with &lt;code&gt;Meta.ordering&lt;/code&gt;. Postgres rejects the result with "ORDER BY term does not match any column in the result set". An &lt;code&gt;.order_by()&lt;/code&gt; on each part fixes it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong
&lt;/h2&gt;

&lt;p&gt;I started on my Mac with the test runner's &lt;code&gt;--parallel&lt;/code&gt;. Forked workers crashed twice, once inside macOS's proxy lookup and once inside the Postgres client library, and a third run died when a failing test's result couldn't be sent back to the main process. I moved the runs into a Linux container, the way the project's CI does it, and they went through in about four minutes each.&lt;/p&gt;

&lt;p&gt;I also thought "turning it on" would be a setting. It isn't, and patching an internal default is fine for an experiment but not something I'd ship.&lt;/p&gt;

&lt;p&gt;And I lost raw data. After the main runs, I reran the game room tests in two of the modes to capture their SQL, and the script cleared each mode's output folder first. The totals and per-route numbers above were already computed and saved by then, but the raw per-request logs for those two runs are gone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats
&lt;/h2&gt;

&lt;p&gt;Test data is small. Most tests create a handful of rows, so an N+1 costs a few queries here and far more in production. That cuts both ways. &lt;code&gt;FETCH_PEERS&lt;/code&gt; keeps a loop at 2 queries however many rows there are, so in production it would win back more of the gap than 69%. But it still can't help a single object or an &lt;code&gt;.iterator()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The patch also turned off &lt;code&gt;select_related&lt;/code&gt; inside third-party packages like the admin, not only in my code. Only requests through the test client were counted, so Celery tasks and websockets aren't in these numbers. And this is one codebase.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd take from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;FETCH_PEERS&lt;/code&gt; on top of tuned code is cheap and broke nothing here. It's a reasonable safety net for the loops nobody has looked at yet.&lt;/li&gt;
&lt;li&gt;It doesn't replace &lt;code&gt;select_related&lt;/code&gt; for views that load one object and follow its foreign keys. Keep those.&lt;/li&gt;
&lt;li&gt;If a loop uses &lt;code&gt;.iterator()&lt;/code&gt;, &lt;code&gt;FETCH_PEERS&lt;/code&gt; won't help it.&lt;/li&gt;
&lt;li&gt;Count queries per request in your tests. That's what found 8 wasted queries on every room action, which no fetch mode would have fixed.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>django</category>
      <category>python</category>
      <category>performance</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Resizing a managed Postgres database while writing to it</title>
      <dc:creator>Remdore</dc:creator>
      <pubDate>Mon, 09 Nov 2026 21:05:24 +0000</pubDate>
      <link>https://dev.to/remdore/resizing-a-managed-postgres-database-while-writing-to-it-1g2n</link>
      <guid>https://dev.to/remdore/resizing-a-managed-postgres-database-while-writing-to-it-1g2n</guid>
      <description>&lt;p&gt;DigitalOcean's documentation for resizing a managed database says the cluster goes into a "Resizing" state for a few minutes and that it "does not cause downtime". I wanted to see what that looks like from the application's side, while it's writing.&lt;/p&gt;

&lt;p&gt;So I made two small Postgres 17 clusters in Frankfurt, one with a single node and one with a standby node. Both were the 1 vCPU, 2 GB size, and I resized each to 2 vCPU, 4 GB while a client wrote to it the whole time.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;A Droplet in the same region ran one writer per cluster, connected over the private network. Each writer inserted numbered rows, one per transaction, about 75 a second. For every insert it logged whether the database confirmed it, and every error and reconnect, with timestamps. On each reconnect it also asked the server who it was: its address, when its Postgres process started, and whether it was a replica.&lt;/p&gt;

&lt;p&gt;If an insert failed, the writer reconnected and tried the same number again. The table's primary key made that safe. If the retry hit a duplicate key, the first attempt had actually been committed even though the client got an error.&lt;/p&gt;

&lt;p&gt;At the end I compared every number the database had confirmed with what was actually in the table. I also polled the cluster status from the API every two seconds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Single node: one 5.9 second gap
&lt;/h2&gt;

&lt;p&gt;The resize call returned straight away and the status went to "resizing" a few seconds later. For the next three minutes nothing happened from the writer's point of view. Writes kept going at the same speed, with no slow commits.&lt;/p&gt;

&lt;p&gt;Then, 189 seconds in, the connection was cut with "terminating connection due to administrator command". The next connection attempt got "the database system is shutting down", and then 27 more attempts failed over the following few seconds, all but one with "server closed the connection unexpectedly" and once with "connection refused". 5.9 seconds after the cut, a connection worked again and writing carried on.&lt;/p&gt;

&lt;p&gt;The server it reconnected to had started its Postgres process about 8 seconds before the old one shut down. The API status went back to "online" 14 seconds after the cut.&lt;/p&gt;

&lt;h2&gt;
  
  
  With a standby node: the same, 5.3 seconds
&lt;/h2&gt;

&lt;p&gt;I expected the standby to make this shorter. That's the usual point of having one: there's a copy already running, and you switch to it.&lt;/p&gt;

&lt;p&gt;It didn't change much. The resize took longer overall, about 400 seconds against 200, but the cut itself looked the same: the same "administrator command" error, the same run of refused connections, and writes came back after 5.3 seconds. And again the server it landed on had started Postgres only 7 seconds before the cut.&lt;/p&gt;

&lt;p&gt;That last detail is the interesting one. A standby that had been running and was simply promoted would normally keep its original start time. So either the new primary was a freshly started node, or the standby was restarted as part of the switch. I can't tell which from the client side. Either way, from the client's side the standby didn't shorten the outage in this test.&lt;/p&gt;

&lt;h2&gt;
  
  
  The second disconnect
&lt;/h2&gt;

&lt;p&gt;There was a second break in both clusters, about 106 seconds after the writer had reconnected, when the status had already said "online" for over a minute and a half.&lt;/p&gt;

&lt;p&gt;After the first cut, both writers had reconnected to the new server through a private IPv6 address. 106 seconds later that connection closed with "EOF detected". The writer reconnected immediately, this time over the usual private IPv4 address, to the same server, judging by the same Postgres start time. That gap was under a tenth of a second, so it barely registered as an outage. But it's a second dropped connection, and any client that only reconnects at startup would have failed on it.&lt;/p&gt;

&lt;p&gt;The lesson is that "online" in the API doesn't mean the resize is finished with your connections.&lt;/p&gt;

&lt;h2&gt;
  
  
  The write that failed and succeeded
&lt;/h2&gt;

&lt;p&gt;On the standby cluster, the insert in flight at that second disconnect got "EOF detected" back. The client had no idea whether it went through. When the writer retried the same number, it hit the primary key, because the first attempt had been committed.&lt;/p&gt;

&lt;p&gt;So an error on the client doesn't mean the write didn't happen. Without the unique key, a retry would have written that row twice. Without a retry, the application would have reported a failure for a write that was actually saved.&lt;/p&gt;

&lt;p&gt;Across both clusters there were four of these uncertain writes. Three hadn't been committed and one had.&lt;/p&gt;

&lt;h2&gt;
  
  
  What was not lost
&lt;/h2&gt;

&lt;p&gt;Nothing the database had confirmed went missing. The single-node cluster confirmed 94,230 writes and the standby cluster 98,159, and every one of them was in the table afterwards. Outside the cut, commits stayed in the low milliseconds: a median of 1.4 ms on the standby cluster both before and after, and 2.1 ms falling to 1.5 ms on the single node once it was bigger. I also tried the API's install-update call on both clusters, since each had a pending maintenance update, but in the 8 minutes I waited, neither cluster changed status, and both still listed the update as pending.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong
&lt;/h2&gt;

&lt;p&gt;I set out to test failover, killing the primary and watching the standby take over. DigitalOcean doesn't let you trigger that yourself. Failover happens when they detect a broken node. So this is a planned switchover during a resize, which is the gentler case.&lt;/p&gt;

&lt;p&gt;I assumed the standby would shrink the gap. It didn't, and I still don't know whether the standby was promoted or replaced.&lt;/p&gt;

&lt;p&gt;And when I stopped the writers, my &lt;code&gt;pkill -f writer.py&lt;/code&gt; matched the command line of the same SSH session that was supposed to run the verification next, so it killed that too. It looked like the check had passed silently. It hadn't run. The real check, run separately, is the one above.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats
&lt;/h2&gt;

&lt;p&gt;This is one resize per cluster, in one region, on small clusters with about 100,000 tiny rows. A larger database may switch differently. There was one writer per cluster doing short inserts; a long transaction open at the cut would have been rolled back with its connection. The timings are from the client and from polling the API every two seconds, not from DigitalOcean's side.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd take from it
&lt;/h2&gt;

&lt;p&gt;The resize was a single API call and lost nothing it had confirmed, which is what you want from a managed database. But "no downtime" in practice meant roughly six seconds of refused connections, plus a second dropped connection about two minutes later. If you plan a resize:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make sure your client reconnects on its own, more than once, and not only at startup.&lt;/li&gt;
&lt;li&gt;Treat a write that errored during the switch as unknown, not failed. A unique key or idempotency key turns a retry into something safe.&lt;/li&gt;
&lt;li&gt;Don't count on a standby node to make a planned resize invisible. In this test it didn't.&lt;/li&gt;
&lt;li&gt;Wait a couple of minutes after the status says "online" before calling it done.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>postgres</category>
      <category>database</category>
      <category>devops</category>
      <category>cloud</category>
    </item>
  </channel>
</rss>
