<?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: Gabriella Andrews</title>
    <description>The latest articles on DEV Community by Gabriella Andrews (@gabriellaandrews).</description>
    <link>https://dev.to/gabriellaandrews</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%2F4208092%2F83fbb379-946e-489d-89ee-88e00bef9eb6.png</url>
      <title>DEV Community: Gabriella Andrews</title>
      <link>https://dev.to/gabriellaandrews</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gabriellaandrews"/>
    <language>en</language>
    <item>
      <title>Building a peptide dosage calculator: the unit-conversion math (mg/mcg, reconstitution, U-100 units)</title>
      <dc:creator>Gabriella Andrews</dc:creator>
      <pubDate>Wed, 25 Nov 2026 06:32:20 +0000</pubDate>
      <link>https://dev.to/gabriellaandrews/building-a-peptide-dosage-calculator-the-unit-conversion-math-mgmcg-reconstitution-u-100-units-3mkn</link>
      <guid>https://dev.to/gabriellaandrews/building-a-peptide-dosage-calculator-the-unit-conversion-math-mgmcg-reconstitution-u-100-units-3mkn</guid>
      <description>&lt;p&gt;&lt;em&gt;Educational purposes only. This post is about arithmetic and software, not medical advice. Nothing here tells anyone how much of anything to take — always follow your clinician's instructions.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I build small single-purpose web tools, and the peptide dosage calculator was supposed to be the easy one. It is "just" unit conversion: a dose in micrograms, a vial in milligrams, some water, a syringe graduated in units. Three inputs, one division. It took longer to get the math &lt;em&gt;trustworthy&lt;/em&gt; than to build the UI, and the reasons are the usual ones: unit traps, floating point, and rounding decisions that actually matter when the output is a volume someone draws into a syringe.&lt;/p&gt;

&lt;p&gt;This post walks through the conversion chain the way I implemented it — formulas, validation, and the precision pitfalls — with round demo numbers only.&lt;/p&gt;

&lt;h2&gt;
  
  
  The three quantities
&lt;/h2&gt;

&lt;p&gt;Everything reduces to three values:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Vial mass&lt;/strong&gt; — usually labelled in milligrams (mg).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Diluent volume&lt;/strong&gt; — the water added to reconstitute, in millilitres (mL).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Target dose&lt;/strong&gt; — usually prescribed in micrograms (mcg/µg).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;From the first two you get a &lt;strong&gt;concentration&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;concentration (mcg/mL) = vialMassMg × 1000 / diluentMl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The ×1000 is where the first bug class lives: 1 mg = 1000 mcg, and mixing the two scales is a 1000× error, not a rounding error. My rule in code: convert everything to mcg and mL at the boundary, immediately, and never let mg exist inside the calculation core.&lt;/p&gt;

&lt;p&gt;Demo numbers (chosen to be obviously illustrative): a 5 mg vial plus 2 mL of water gives 5000 / 2 = &lt;strong&gt;2500 mcg/mL&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  From dose to draw volume
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;drawVolume (mL) = doseMcg / concentration (mcg/mL)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the demo concentration, a hypothetical 250 mcg dose is 250 / 2500 = &lt;strong&gt;0.10 mL&lt;/strong&gt;. Clean numbers are a lie, though — real inputs produce things like 0.0837 mL, which no syringe can measure. That is a display and rounding problem, covered below.&lt;/p&gt;

&lt;h2&gt;
  
  
  The U-100 syringe conversion
&lt;/h2&gt;

&lt;p&gt;Insulin syringes are graduated in "units", and for a U-100 syringe the definition is fixed: &lt;strong&gt;100 units = 1 mL&lt;/strong&gt;. So:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;syringeUnits = drawVolumeMl × 100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;0.10 mL → 10 units. This is the number people actually read off the barrel, so it is the primary output of the tool, with mL shown alongside. The trap: this only holds for U-100 syringes. A U-40 syringe would be ×40. The calculator states the U-100 assumption next to the result instead of burying it in a help page.&lt;/p&gt;

&lt;h2&gt;
  
  
  The implementation
&lt;/h2&gt;

&lt;p&gt;The core is a handful of pure functions. Keeping them pure made the unit tests trivial, which matters because the test table &lt;em&gt;is&lt;/em&gt; the specification here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;MCG_PER_MG&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;U100_UNITS_PER_ML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;concentrationMcgPerMl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vialMassMg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;diluentMl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;assertPositiveFinite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vialMassMg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'vial mass'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;assertPositiveFinite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;diluentMl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'diluent volume'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vialMassMg&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;MCG_PER_MG&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;diluentMl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;doseToDraw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;doseMcg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;concMcgPerMl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;assertPositiveFinite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;doseMcg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'dose'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ml&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;doseMcg&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;concMcgPerMl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ml&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;units&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ml&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;U100_UNITS_PER_ML&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is also a second input mode: some labels state the concentration directly (mcg/mL or mg/mL), so the tool accepts a known concentration and skips the reconstitution step. Both modes converge on the same &lt;code&gt;doseToDraw&lt;/code&gt;, which keeps the tested surface small.&lt;/p&gt;

&lt;h2&gt;
  
  
  Validation is the product
&lt;/h2&gt;

&lt;p&gt;Most of the code is not the math — it is refusing bad math:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Zero and negative inputs&lt;/strong&gt; are rejected, not clamped. A diluent volume of 0 is a division by zero waiting to happen.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unit mismatch guards&lt;/strong&gt;: if a user types a dose in mcg into a field expecting mg (or the reverse), the result is off by 1000×. I can't detect intent, but I can sanity-check ranges: a computed draw volume larger than the whole vial, or a dose larger than the vial's total mass, triggers an explicit warning instead of a confident number.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Impossible precision&lt;/strong&gt;: if the draw volume works out below what the smallest syringe graduation can show, the tool says so rather than printing six decimal places.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Rounding: the subtle part
&lt;/h2&gt;

&lt;p&gt;JavaScript floats make &lt;code&gt;0.1 + 0.2 !== 0.3&lt;/code&gt;, and dosage outputs are exactly where that stops being a joke. My approach:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compute at full precision internally; round &lt;strong&gt;only&lt;/strong&gt; at display time.&lt;/li&gt;
&lt;li&gt;Display mL to 2 decimal places and units to the nearest 0.5 unit, because that is what syringe markings support.&lt;/li&gt;
&lt;li&gt;Never round an intermediate value and feed it back into the next step — the classic bug is rounding the concentration first, then computing the draw from the rounded concentration and compounding the error.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One more UI decision: show the full chain ("2500 mcg/mL → 0.10 mL → 10 units") instead of just the final number. When every intermediate step is visible, a unit mistake is obvious at a glance — the user can catch what validation can't.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running it
&lt;/h2&gt;

&lt;p&gt;All of this runs client-side in the browser; nothing is stored unless the user explicitly saves a calculation. If you want to try the tool itself, it is here: &lt;a href="https://peptidedosagecalculator.app" rel="noopener noreferrer"&gt;Peptide Dosage Calculator&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Educational purposes only — this post covers software arithmetic, not medical advice, and it does not recommend any dose of any substance. Follow your clinician's instructions.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Removing a green screen in code: what I learned open-sourcing a video matting pipeline</title>
      <dc:creator>Gabriella Andrews</dc:creator>
      <pubDate>Sun, 22 Nov 2026 14:20:23 +0000</pubDate>
      <link>https://dev.to/gabriellaandrews/removing-a-green-screen-in-code-what-i-learned-open-sourcing-a-video-matting-pipeline-35bl</link>
      <guid>https://dev.to/gabriellaandrews/removing-a-green-screen-in-code-what-i-learned-open-sourcing-a-video-matting-pipeline-35bl</guid>
      <description>&lt;p&gt;This pipeline started as the Standard pipeline behind &lt;a href="https://zapmatte.com" rel="noopener noreferrer"&gt;Zapmatte&lt;/a&gt;, the hosted green screen remover I run: upload a clip on the website, get a transparent video back. The hosted version made the workflow a form instead of a timeline — but every step inside it was still code, and code can be shared. So I took that pipeline, cleaned it up, and open-sourced it. This post is the tutorial I wish I had at the start: what the pipeline does, in what order, and how to run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why one keyer is not enough
&lt;/h2&gt;

&lt;p&gt;A plain chroma key works until it doesn't. The screen is never evenly lit, shadows fall on it, and the moment your subject has flyaway hair, the key either eats the hair or leaves a green halo. An AI matting model has the opposite problem: it is good at people and soft edges, but it does not know your props exist, and it can wobble from frame to frame.&lt;/p&gt;

&lt;p&gt;The pipeline I ended up with uses both, each where it is strong:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Human matting first.&lt;/strong&gt; Robust Video Matting (RVM, MobileNetV3) produces a soft alpha for the people in each frame. It has temporal memory, so edges don't flicker between frames.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chroma key, locally.&lt;/strong&gt; The screen colour is matched locally around the subject, so uneven lighting and shadows on the screen don't leave halos.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Combine the two.&lt;/strong&gt; Near people, the final alpha is the intersection of the RVM alpha and the key alpha — hair stays soft. Away from people, a colour-only key runs, so props and objects survive instead of being erased.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blue and teal screens.&lt;/strong&gt; The screen hue is detected from 5 frames and rotated to green before keying, so the same code path handles all three.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Despill.&lt;/strong&gt; Green spill gets pulled off hair, skin and edges — this is the step that kills the fringe.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Marker cleanup.&lt;/strong&gt; Small blobs enclosed by screen, away from people (tracking markers, tape corners), are removed.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Running it
&lt;/h2&gt;

&lt;p&gt;You need Python 3.10+ and ffmpeg (with libvpx and prores_ks) on your PATH.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/wsmhj/zapmatte-green-screen-remover
&lt;span class="nb"&gt;cd&lt;/span&gt; zapmatte-green-screen-remover
pip install -r requirements.txt   &lt;span class="c"&gt;# or: pip install .  (adds a remove-green-screen command)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The RVM weights download from GitHub on the first run, via &lt;code&gt;torch.hub&lt;/code&gt;. After that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python remove_green_screen.py clip.mp4                    &lt;span class="c"&gt;# -&amp;gt; clip.webm (transparent)&lt;/span&gt;
python remove_green_screen.py clip.mp4 --mov --matte      &lt;span class="c"&gt;# + ProRes 4444 MOV and alpha matte&lt;/span&gt;
python remove_green_screen.py clip.mp4 --color &lt;span class="s2"&gt;"#ffffff"&lt;/span&gt;  &lt;span class="c"&gt;# -&amp;gt; clip-bg.mp4 on white&lt;/span&gt;
python remove_green_screen.py clip.mp4 --image beach.jpg  &lt;span class="c"&gt;# -&amp;gt; clip-bg.mp4 on a picture&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or from Python:&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;from&lt;/span&gt; &lt;span class="n"&gt;zapmatte&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pipeline&lt;/span&gt;

&lt;span class="n"&gt;pipeline&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"clip.mp4"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"webm"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"out.webm"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"matte"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"matte.mp4"&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;h2&gt;
  
  
  Which output do you actually want?
&lt;/h2&gt;

&lt;p&gt;This took me longer to learn than the keying itself:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Output&lt;/th&gt;
&lt;th&gt;File&lt;/th&gt;
&lt;th&gt;Use it in&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mov&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;ProRes 4444 + alpha&lt;/td&gt;
&lt;td&gt;Premiere Pro, After Effects, Final Cut Pro, DaVinci Resolve&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;webm&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;VP9 + alpha, Opus audio&lt;/td&gt;
&lt;td&gt;OBS, web pages&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;matte&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;black/white H.264 MP4&lt;/td&gt;
&lt;td&gt;any editor as a track matte&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mp4&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;subject over a colour/picture&lt;/td&gt;
&lt;td&gt;CapCut, phones, social&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Resolution (up to 4K) and audio are kept. On a T4 GPU it runs about 41 fps at 720p, 19 fps at 1080p and 5.5 fps at 4K. It also runs on CPU, slowly — fine for a short clip, painful for a long one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Honest limits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It is made for green/blue screen footage. Ordinary videos without a screen are not what it is for — there is no magic "remove any background" step in this pipeline.&lt;/li&gt;
&lt;li&gt;Green clothing is kept but can look patchy.&lt;/li&gt;
&lt;li&gt;Green props far from people are keyed out with the screen, because away from people the colour key is in charge.&lt;/li&gt;
&lt;li&gt;Frames up to 4K (4096 wide, 2160 on the short side).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The repo is GPL-3.0, because it builds on Robust Video Matting (also GPL-3.0 — please cite their paper if you use this in research). If you'd rather not install anything, the same pipeline runs on the &lt;a href="https://zapmatte.com" rel="noopener noreferrer"&gt;Zapmatte website&lt;/a&gt; — upload a clip, download the result, first 10 seconds free.&lt;/p&gt;

&lt;p&gt;If you try it on your own footage and hit an edge case I haven't covered, open an issue — real-world clips are how this thing gets better.&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>python</category>
      <category>video</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>The Jobs That Never Came Back: How I Fixed Silent Failures in an Async Video Pipeline</title>
      <dc:creator>Gabriella Andrews</dc:creator>
      <pubDate>Mon, 26 Oct 2026 07:58:32 +0000</pubDate>
      <link>https://dev.to/gabriellaandrews/the-jobs-that-never-came-back-how-i-fixed-silent-failures-in-an-async-video-pipeline-43hg</link>
      <guid>https://dev.to/gabriellaandrews/the-jobs-that-never-came-back-how-i-fixed-silent-failures-in-an-async-video-pipeline-43hg</guid>
      <description>&lt;p&gt;The first ticket that scared me did not contain an error message. It contained a screenshot of a spinner.&lt;/p&gt;

&lt;p&gt;A user had uploaded a photo, paid for a render, and waited. The page kept spinning. There was no failed job in my dashboard, no error in my logs, and no refund request, because from the user's side nothing had technically gone wrong. Nothing had happened at all. That is the worst kind of failure for a tool that charges per job: the system looks alive, the money is gone, and the user is left staring at a loading animation.&lt;/p&gt;

&lt;p&gt;I run a small image-to-video tool. You upload a still photo, pick a motion style, and get back a short clip. The pipeline looks simple on a whiteboard: upload, queue, send to a rendering provider, wait for a webhook, deliver the file. In practice, every arrow between those boxes is a place where a job can die quietly. It took me about a month, and roughly 1,400 jobs, to learn all the ways. About 6% of jobs in that first month never reached the user in a usable form. Here is what was actually breaking, and the design that stopped it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pipeline, and where it lies to you
&lt;/h2&gt;

&lt;p&gt;My first version tracked a job with two states: pending and done. The code called the provider, waited for the webhook, and flipped the job to done when the webhook arrived. If the webhook never arrived, the job stayed pending forever. My dashboard showed a healthy queue with a few slow jobs. The users saw a spinner that never stopped.&lt;/p&gt;

&lt;p&gt;The fix started with admitting that "pending" was hiding four different situations. I now persist five states before I ever call the provider: queued, rendering, delivered, failed, and dead. The state row is written to the database first, and only then does the code call the provider. That order matters. If the process crashes between those two steps, I have a queued job with no provider call, and a sweeper can pick it up. In the old order, a crash left a provider-side render running with no record of it on my side at all.&lt;/p&gt;

&lt;p&gt;Every state change is also timestamped. That one field turned out to be the cheapest debugging tool I own. A job stuck in rendering for nine hours is not a slow render. It is a dead job wearing a slow job's clothes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Failure one: the provider just stops answering
&lt;/h2&gt;

&lt;p&gt;Rendering providers time out. Sometimes the provider is down, sometimes a single render gets stuck on their side, sometimes the network drops at exactly the wrong moment. My first timeout was 45 seconds, set because that felt reasonable. It was not based on any measurement, and it showed: normal renders took much longer than that, so the timeout fired on healthy jobs, and my code marked them failed while the provider kept rendering them in the background.&lt;/p&gt;

&lt;p&gt;I changed two things. First, I stopped treating a timeout as a failure. A timeout now means "unknown." The job goes back to a checking state where a separate worker asks the provider for the job's status instead of assuming the worst. Second, I set the timeout from real data: I looked at the distribution of render times, picked a value above the 99th percentile, and only then called it a timeout. Guessing at timeouts is how you build a system that fails its healthiest jobs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Failure two: the webhook never arrives
&lt;/h2&gt;

&lt;p&gt;The worst weekend I had came from my own deploy. I shipped a small change to the webhook endpoint on a Friday evening, and the new code returned a 500 error for a payload shape I had not tested. The provider retried a few times, then gave up. By Monday morning, 38 jobs were stuck in rendering. The renders had actually finished on the provider's side. My system simply never heard about them, and there was no code path that went looking.&lt;/p&gt;

&lt;p&gt;That weekend taught me the rule I now consider non-negotiable: never let a webhook be the only way you learn a job finished. I run a sweeper every ten minutes that lists jobs stuck in rendering past their expected window and asks the provider directly for their status. The webhook is still the fast path, and most jobs still complete through it. But the sweeper is the path that catches everything the fast path drops, including deploys like mine. It also pages me differently: one stuck job is a curiosity, ten stuck jobs in an hour is an incident, and the alert now says which.&lt;/p&gt;

&lt;h2&gt;
  
  
  Failure three: the file arrives, but it is broken
&lt;/h2&gt;

&lt;p&gt;This one took the longest to notice, because my code was marking these jobs delivered. The provider returned a file, the webhook arrived on time, and the user got a download link. The file just did not play. Sometimes it was truncated, sometimes it was a few frames of black, sometimes the container was corrupt. My system had verified that a file existed. It had never verified that the file was a video.&lt;/p&gt;

&lt;p&gt;Now nothing is marked delivered until a verification step passes: the file has a plausible size, the container parses, and the duration matches what the job requested within a small margin. If any check fails, the job goes to retry, not to the user. This added a few seconds to delivery, and it killed an entire class of tickets that used to start with "the video is broken." Verifying the output feels like wasted work until the first time it catches a corrupt file before a user does.&lt;/p&gt;

&lt;h2&gt;
  
  
  Failure four: the job that delivered twice
&lt;/h2&gt;

&lt;p&gt;Retries fixed the stuck jobs, and then created a new problem. A webhook arrived late, after my sweeper had already retried the job and delivered it. The provider's retry and my retry both completed, and the user was charged twice for one clip. The user noticed before I did, which is embarrassing in a specific way that stays with you.&lt;/p&gt;

&lt;p&gt;The fix is an idempotency key, and it has to live in the right place. Each job gets one key at creation, and that key is stored with the job row, not generated fresh on each attempt. The charge, the provider call, and the delivery all check the key before acting. A second delivery attempt with the same key returns the first result instead of doing the work again. This is the kind of thing that sounds obvious in a blog post and is easy to skip when you are rushing to ship retries. Skipping it cost me real refunds and one very patient user who deserved better.&lt;/p&gt;

&lt;h2&gt;
  
  
  The credit ledger: hold, settle, refund
&lt;/h2&gt;

&lt;p&gt;All of this sits on top of a credit system, and the credit system needed its own redesign. In the first version, credits were deducted when the job was created. A failed job meant a support ticket and a manual refund, which is fine at ten jobs a day and miserable at a hundred.&lt;/p&gt;

&lt;p&gt;Now credits are held when a job is created, settled only when delivery is verified, and released automatically when a job reaches a terminal failed state. The ledger records every hold, settle, and release as its own row, so I can answer "where did my credits go" without guessing. The dead-letter queue ties into this: a job that exhausts its retries lands in the dead queue with its full history attached, and releasing its held credits is part of moving it there, not a separate manual step. Users stopped asking about credits at almost exactly the moment the ledger became boring and automatic, which is how I knew it was working.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong along the way
&lt;/h2&gt;

&lt;p&gt;My first fix for all of this was "retry everything." It reduced stuck jobs and increased duplicate charges, which is a trade I would not make again. Retries without idempotency are just a second chance to cause the same harm.&lt;/p&gt;

&lt;p&gt;My second mistake was alerting on every failure. My phone buzzed all night for individual jobs that the retry loop would have fixed on its own, and I started ignoring the alerts, which is worse than having none. Now I alert on rates and on dead-letter growth, not on single jobs. A single failure is the system working as designed. A rising dead-letter queue is the system telling me something changed upstream.&lt;/p&gt;

&lt;p&gt;The third mistake was treating the provider as reliable and my code as the risk. It is the other way around. Providers go down, webhooks get lost, deploys break endpoints. The pipeline has to assume every external call can vanish, and still give the user either a video or their credits back. That is the whole job, really: never leave a user with neither.&lt;/p&gt;

&lt;h2&gt;
  
  
  A short checklist, if you are building one of these
&lt;/h2&gt;

&lt;p&gt;Write the state row before you call anyone. Give every job one idempotency key and keep it for the life of the job. Treat a timeout as "unknown," not "failed," and go ask the provider. Run a sweeper, because webhooks will fail on the worst weekend. Verify the output before you call it delivered. Hold credits, settle on verified delivery, refund automatically on terminal failure. And alert on the queue growing, not on each job dying.&lt;/p&gt;

&lt;p&gt;In the month after I put this in place, user-visible failures fell from around 6% to under 1%, and most of what remained was jobs that genuinely could not render, which now fail loudly with a refund instead of spinning forever. The spinner is still there, but now it has a deadline, and behind it there is a system that either delivers or gives the money back. That is a much easier thing to explain to a user.&lt;/p&gt;

&lt;p&gt;I build &lt;a href="https://stivio.ai" rel="noopener noreferrer"&gt;Image to Video&lt;/a&gt; tools for turning still photos into short clips, and most of what I know about async pipelines came from these failures, not from getting the design right the first time.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>showdev</category>
      <category>machinelearning</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
