<?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: Mattia Maggioni</title>
    <description>The latest articles on DEV Community by Mattia Maggioni (@mattiamaggioni).</description>
    <link>https://dev.to/mattiamaggioni</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%2F4208478%2F68d0364b-bef2-4dce-adb2-287d22a9c0f8.jpg</url>
      <title>DEV Community: Mattia Maggioni</title>
      <link>https://dev.to/mattiamaggioni</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mattiamaggioni"/>
    <language>en</language>
    <item>
      <title>One codebase, two renderers: live previews in the browser, final renders in the cloud</title>
      <dc:creator>Mattia Maggioni</dc:creator>
      <pubDate>Sat, 07 Nov 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/mattiamaggioni/one-codebase-two-renderers-live-previews-in-the-browser-final-renders-in-the-cloud-52in</link>
      <guid>https://dev.to/mattiamaggioni/one-codebase-two-renderers-live-previews-in-the-browser-final-renders-in-the-cloud-52in</guid>
      <description>&lt;p&gt;Our app, HypeFox, renders short videos from code: a model writes a scene file in JSON, and Remotion turns it into 1080×1920 frames on cloud containers. Last week we shipped an editor where people change a video and see the result right away. These are our notes from running the same video code in two places.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;The cloud renders with Remotion 4.0.536 on containers that sleep when there's no work (we wrote about that part &lt;a href="https://dev.to/mattiamaggioni/rendering-ai-short-videos-on-containers-that-switch-off-after-2-minutes-our-setup-and-real-costs-4cek"&gt;here&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;The editor plays the video with Remotion's Player: same version, same style components. No style exists twice.&lt;/li&gt;
&lt;li&gt;Whatever the person changes is stored as overrides on top of the scene file: captions, texts, colors, transitions, elements. A save sends the overrides, and the cloud renders with the same code and the same overrides.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Prove they match before building any UI
&lt;/h2&gt;

&lt;p&gt;The first thing we built was not a button. It was a check: two real videos, one with a generated voice and one cut from a person's footage, played by the Player in the browser and rendered by the same renderer we run in the cloud, then compared frame by frame. They matched.&lt;/p&gt;

&lt;p&gt;Every later feature had to pass the same kind of test. Transitions, for example: with no transition set, the new code must produce frames identical to the old code. We compare 27 frames per example, at the scene boundaries and a few frames around them, pixel by pixel, in every style.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ship only the style you open
&lt;/h2&gt;

&lt;p&gt;Six styles in one bundle came to almost 1 MB compressed. Split per style, the editor downloads 209 to 602 KB compressed, depending on the style of the video you open.&lt;/p&gt;

&lt;h2&gt;
  
  
  Phones are the real test
&lt;/h2&gt;

&lt;p&gt;Measured on an iPhone: three styles preview at 30 fps, one at 28, one at 21 and the heaviest at 18. We kept the live preview for all of them. A few dropped frames in a preview are fine. A preview that doesn't match the final video is not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Things that bit us
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Music that restarted every tenth of a second.&lt;/strong&gt; Static assets on Cloudflare answered every request with a 200 and the whole file, never a 206 for a &lt;code&gt;Range&lt;/code&gt; request. Chrome then treated the audio as not seekable, and a track that starts in the middle kept seeking forever. A Worker now serves audio and video with real &lt;code&gt;Range&lt;/code&gt; support (206, &lt;code&gt;Content-Range&lt;/code&gt;, 416 when out of range). The seekable range went from &lt;code&gt;[0,0]&lt;/code&gt; to &lt;code&gt;[0,180]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fonts from a third party.&lt;/strong&gt; The styles loaded fonts from Google Fonts. Our content security policy would have blocked them, and we'd rather not tell Google who opens the editor. The Worker fetches each font once, caches it and serves it from our own domain.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A glyph the cloud didn't have.&lt;/strong&gt; A typewriter caption style used "▍" as the cursor. It looked fine on a Mac. The cloud's fonts don't have it, so it rendered as an empty box. It's "_" now.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transitions must not move the captions.&lt;/strong&gt; When someone sets a transition between two scenes, the style cuts straight at that boundary and the effect is applied to the picture only. Captions and overlays stay still.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Overlays that follow words
&lt;/h2&gt;

&lt;p&gt;People don't think "at 7.4 seconds". They think "when I say rent". So a text, sticker or shape can be anchored to a spoken word, using the word timings from the voice step. When a sentence changes or a cut moves, the overlay moves with its word.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a save costs
&lt;/h2&gt;

&lt;p&gt;Only the sentences that changed go back to the voice. The render runs on the same containers as new videos. A save costs about a cent of container time.&lt;/p&gt;

&lt;p&gt;How do you preview server-rendered media: the same code in the browser, or a fast low-res render?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Written with the help of an AI assistant, from our own code, notes and measurements.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>remotion</category>
      <category>react</category>
      <category>webdev</category>
      <category>performance</category>
    </item>
    <item>
      <title>Rendering AI short videos on containers that switch off after 2 minutes: our setup and real costs</title>
      <dc:creator>Mattia Maggioni</dc:creator>
      <pubDate>Fri, 30 Oct 2026 15:07:00 +0000</pubDate>
      <link>https://dev.to/mattiamaggioni/rendering-ai-short-videos-on-containers-that-switch-off-after-2-minutes-our-setup-and-real-costs-4cek</link>
      <guid>https://dev.to/mattiamaggioni/rendering-ai-short-videos-on-containers-that-switch-off-after-2-minutes-our-setup-and-real-costs-4cek</guid>
      <description>&lt;p&gt;In our app, HypeFox, every short video is rendered from code: a language model writes the scenes, Remotion turns them into 1080×1920 frames. The renderer is the most expensive part of the stack and the easiest one to break. This is how it runs today, less than two weeks after the first commit, with the numbers we measured.&lt;/p&gt;

&lt;h2&gt;
  
  
  What makes one video
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Script and scenes.&lt;/strong&gt; A small language model writes the script, then fills a JSON scene file that follows the schema of the chosen style. The model never writes code: it picks layouts, icons, words and timings from what the schema allows. If the file fails the checks, the errors go back to the model and it tries again.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fact-check.&lt;/strong&gt; Up to four checkable claims are searched on the web; only the lines that fail are rewritten.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Voice.&lt;/strong&gt; A text-to-speech API reads the lines and returns per-word timings. Those timings set the length of every scene and drive the captions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Render.&lt;/strong&gt; Remotion, 1080×1920 at 30 fps. The cover image is generated in parallel and never blocks the video.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Steps 1 to 3 are API calls. Step 4 needs a real machine: Node, a headless Chrome, ffmpeg, a few CPUs.&lt;/p&gt;

&lt;h2&gt;
  
  
  From a Mac on a desk to containers that sleep
&lt;/h2&gt;

&lt;p&gt;On day one the worker ran on a Mac. It worked until the Mac was off. The same evening we moved the exact same worker code to Cloudflare Containers: a Linux image with Node 22, Chrome for Remotion and ffmpeg. The container runs only when there's work, and we pay only while it's on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Waking it up
&lt;/h2&gt;

&lt;p&gt;Two paths, both asking one question: is there work?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A database trigger.&lt;/strong&gt; When a row lands in the &lt;code&gt;video&lt;/code&gt; table, a Postgres trigger calls the worker's wake-up endpoint with &lt;code&gt;pg_net&lt;/code&gt;. The request goes out only after the transaction commits, and it can't fail the insert: if it gets lost, the second path catches it. The secret lives in Supabase Vault; the Worker only keeps its SHA-256.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A cron every minute&lt;/strong&gt;, as the safety net for a lost wake-up or a video put back in the queue.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both call one database function that returns the queue: videos waiting, videos in progress, covers still coming. The Worker keeps busy containers on and starts a free one for each item waiting, up to four.&lt;/p&gt;

&lt;p&gt;From the insert to a cold container picking up the video: 7 to 10 seconds. The wake-up reaches the Worker in 0.2 to 0.3 s and the container boots in 2 to 4 s. With the cron alone it could take up to a minute.&lt;/p&gt;

&lt;h2&gt;
  
  
  Going back to sleep
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;sleepAfter&lt;/code&gt; is 2 minutes (it was 4 on day one). Before stopping, the worker checks the queue one last time.&lt;/li&gt;
&lt;li&gt;When the platform stops a container (SIGTERM), the half-made video goes back to the queue.&lt;/li&gt;
&lt;li&gt;Every container is its own named worker in the database. On boot, a worker re-queues the videos &lt;em&gt;it&lt;/em&gt; left half done. With one shared name, a new container would steal work from the others. The extra workers' secrets are derived from the first one with HMAC-SHA256, so the Worker still holds a single secret.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The numbers
&lt;/h2&gt;

&lt;p&gt;Measured on October 18: a 36-second video, cold container, same function the web app calls.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Instance&lt;/th&gt;
&lt;th&gt;Picked up after&lt;/th&gt;
&lt;th&gt;Render&lt;/th&gt;
&lt;th&gt;Ready after&lt;/th&gt;
&lt;th&gt;Cost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;standard-4 (4 vCPU, 12 GiB)&lt;/td&gt;
&lt;td&gt;7.1 s&lt;/td&gt;
&lt;td&gt;56 s&lt;/td&gt;
&lt;td&gt;104 s&lt;/td&gt;
&lt;td&gt;$0.011&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3 vCPU, 9 GiB&lt;/td&gt;
&lt;td&gt;9.8 s&lt;/td&gt;
&lt;td&gt;81 s&lt;/td&gt;
&lt;td&gt;136 s&lt;/td&gt;
&lt;td&gt;$0.010&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2 vCPU, 6 GiB&lt;/td&gt;
&lt;td&gt;10.4 s&lt;/td&gt;
&lt;td&gt;86 s&lt;/td&gt;
&lt;td&gt;144 s&lt;/td&gt;
&lt;td&gt;$0.008&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One video alone costs about 1.1 cents of container time:&lt;/strong&gt; 0.61 for memory, 0.47 for CPU, 0.03 for disk. With the old 4-minute sleep it was about 1.5 cents.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Back to back it's about 0.8 cents a video&lt;/strong&gt;, because the last two idle minutes are shared.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;We kept standard-4.&lt;/strong&gt; Fewer vCPUs render almost proportionally slower (2.1 to 2.6 seconds of render per second of video, against 1.5) and the video arrives 30 to 40% later, to save 0.1 to 0.3 cents.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;We pay for 12 GiB and use 3 at most.&lt;/strong&gt; Custom instances need at least 3 GiB per vCPU, so 4 vCPU with 6 GiB isn't an option.&lt;/li&gt;
&lt;li&gt;The monthly allowance included in Workers Paid covers about 36 solo videos. Memory runs out first.&lt;/li&gt;
&lt;li&gt;The language-model calls (script, scenes, fact-check) add roughly half a cent to two and a half cents per video, depending on the style. The voice is extra.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Things that bit us
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Deploys restart work.&lt;/strong&gt; A rollout stops running machines, and a video in progress starts again from zero. One of our own test videos restarted from 98%. Now we check that nothing is in progress before deploying.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build from a clean commit.&lt;/strong&gt; The image takes files as they are on disk, so we build from &lt;code&gt;git archive HEAD&lt;/code&gt; in a temp folder, never from the working folder.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rollouts with every container asleep&lt;/strong&gt; didn't start; &lt;code&gt;wrangler deploy --containers-rollout=immediate&lt;/code&gt; fixed it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pin what Remotion pins.&lt;/strong&gt; &lt;code&gt;zod&lt;/code&gt; is fixed at the version Remotion expects, so &lt;code&gt;npx remotion versions&lt;/code&gt; is clean and cloud renders match local ones.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nothing fancy, and that's the point: one queue in Postgres, one question, containers that are allowed to die.&lt;/p&gt;

&lt;p&gt;If you render video on demand: do you keep a warm instance, or live with the cold start?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Written with the help of an AI assistant, from our own code, notes and measurements.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>remotion</category>
      <category>cloudflare</category>
      <category>serverless</category>
      <category>ai</category>
    </item>
    <item>
      <title>Our app runs its own Instagram accounts: how the autopilot works, and week 1's real numbers</title>
      <dc:creator>Mattia Maggioni</dc:creator>
      <pubDate>Mon, 26 Oct 2026 10:56:17 +0000</pubDate>
      <link>https://dev.to/mattiamaggioni/our-app-runs-its-own-instagram-accounts-how-the-autopilot-works-and-week-1s-real-numbers-264d</link>
      <guid>https://dev.to/mattiamaggioni/our-app-runs-its-own-instagram-accounts-how-the-autopilot-works-and-week-1s-real-numbers-264d</guid>
      <description>&lt;p&gt;I'm building an app that creates, edits and posts short videos on its own. To test it in public, it runs two Instagram accounts by itself: one in English since October 21 and one in Italian since October 22. Nobody edits the videos; when something comes out wrong we fix the app. Here's how the autopilot works, and what week 1 looked like.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the autopilot works
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. A plan per calendar week.&lt;/strong&gt; Every Monday, in the audience's time zone, a worker plans Monday to Sunday: the slots (at the audience's best times, up to 2 a day), a role for each slot (core format, sales or test, with fixed shares counted over the last 4 weeks), the format for each slot, a hook and an ending, and an idea. Switch it on mid-week and the first plan only runs to Sunday, so the next one starts with a full week of data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Formats are picked with Thompson sampling.&lt;/strong&gt; For each core slot it draws a random number around each format's score, wider when the format has little data, and the highest wins. No format gets more than 60% of the core slots over 4 weeks. In week 1 there's no data, so every format is equal and the plan is mostly tests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Videos are made about 30 hours before their slot.&lt;/strong&gt; A Postgres cron job (pg_cron) checks every 10 minutes for approved slots going out within 30 hours and queues the video.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Making one video.&lt;/strong&gt; A small language model writes the script, then fills a JSON scene file that follows the style's schema. The model never writes code. A fact-check pass reads the script first. A text-to-speech voice reads the lines and returns word timings, which set each scene's length and the captions. Remotion renders 1080×1920 at 30 fps inside a container that only runs when there's work. The language-model parts are cheap: title and caption about 0.1 cents per video, the fact-check about 1 cent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Learning at day 7.&lt;/strong&gt; Each video gets a score from reach, watch time and actions. Each number is divided by the median of the account's recent mature videos on the same network, in log scale, so a 300-view account and a 300,000-view account both have a "×1". Small numbers are smoothed toward the account's usual. Hits count at most ×3 and flops at least ×0.33 for their format. It needs at least 5 scored videos before it learns anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Week 1: the cold start, in numbers
&lt;/h2&gt;

&lt;p&gt;Read on Monday, October 26. Only videos made by HypeFox; one demo video we posted ourselves on each account is left out.&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;English account (Oct 21–25)&lt;/th&gt;
&lt;th&gt;Italian account (Oct 22–25)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Videos posted&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Views&lt;/td&gt;
&lt;td&gt;1,074 (49–175 per video)&lt;/td&gt;
&lt;td&gt;1,019 (120–232)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Swiped away in the first 3 s (avg)&lt;/td&gt;
&lt;td&gt;57%&lt;/td&gt;
&lt;td&gt;58%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Avg watch time&lt;/td&gt;
&lt;td&gt;6.1 s of ~34 s&lt;/td&gt;
&lt;td&gt;6.3 s of ~36 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Likes / saves / comments / shares&lt;/td&gt;
&lt;td&gt;3 / 4 / 2 / 0&lt;/td&gt;
&lt;td&gt;4 / 1 / 0 / 0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Followers&lt;/td&gt;
&lt;td&gt;2 → 5&lt;/td&gt;
&lt;td&gt;1 → 4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Signups from the account&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Point 5 is why week 1 can't be smart: no video is 7 days old yet, so there's nothing to learn from. The Monday report says it plainly: "no numbers yet". The first videos turn 7 days old on Wednesday, and next Monday's plan will be the first one built on the account's own numbers.&lt;/p&gt;

&lt;h2&gt;
  
  
  What surprised me
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The best English video, made by the AI, was titled "An AI tool can't run your account by itself" (175 views, 44% swiped away, the best hold on that account).&lt;/li&gt;
&lt;li&gt;The polished demo we made ourselves was the most skipped video of the week: 99% swiped away in 3 seconds on the English account. The AI's plain explainers kept about 43 out of 100 viewers past 3 seconds.&lt;/li&gt;
&lt;li&gt;The two sales videos ("DM me PLAN") held worse than average and nobody sent the word.&lt;/li&gt;
&lt;li&gt;14 of 16 videos landed between 116 and 232 views: a new account's test audience, and nothing broke out yet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What we changed (the app, never a video)
&lt;/h2&gt;

&lt;p&gt;We rebuilt the main style on day 1 (drawn places, moving icons, a moving camera), added background music, and picked new script instructions with blind tests judged by models that didn't know which version they were reading.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next
&lt;/h2&gt;

&lt;p&gt;Week 2 is running: 14 videos per account, still without lessons. I'll post the numbers every Monday, including the first week the learning loop actually kicks in.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>buildinpublic</category>
      <category>showdev</category>
      <category>automation</category>
    </item>
  </channel>
</rss>
