<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Sten Roger Sandvik]]></title><description><![CDATA[Sten Roger Sandvik]]></description><link>https://stenrs.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 23:55:19 GMT</lastBuildDate><atom:link href="https://stenrs.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Running a whole product on Cloudflare]]></title><description><![CDATA[Stagd gives every pull request its own running preview of an app. The previews run on our customers' compute. Stagd itself, the API, the dashboard, the…]]></description><link>https://stenrs.hashnode.dev/running-a-whole-product-on-cloudflare</link><guid isPermaLink="true">https://stenrs.hashnode.dev/running-a-whole-product-on-cloudflare</guid><category><![CDATA[cloudflare]]></category><category><![CDATA[serverless]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[Devops]]></category><dc:creator><![CDATA[Sten Roger Sandvik]]></dc:creator><pubDate>Mon, 30 Nov 2026 09:06:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b017afaca75dd874defa7cb/bd9e5892-6400-42c6-b00d-10ef6ba5c289.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Stagd gives every pull request its own running preview of an app. The previews run on our customers' compute. Stagd itself, the API, the dashboard, the webhooks and the edge that routes every preview's URL, runs entirely on Cloudflare.</p>
<p>This is why we built it there, what it looks like, and what we'd tell anyone thinking of doing the same.</p>
<h2>Why Cloudflare</h2>
<p>Four reasons:</p>
<ul>
<li><strong>Everything in one place.</strong> A database, object storage, queues, background jobs, cron, WebSockets, headless browsers, email, DNS and TLS for wildcard domains, under one account, one bill and one deploy tool. For a small team, every extra provider is another dashboard, another set of keys and another thing that breaks at night.</li>
<li><strong>Cheap.</strong> Workers bill for CPU time, not for a server waiting on requests. A product with a few users costs almost nothing to run, and nothing runs while nobody's using it.</li>
<li><strong>It scales without us.</strong> No instance sizes, no autoscaling rules, no region to choose. If launch day goes well, nothing has to be resized.</li>
<li><strong>Stability.</strong> Stagd sits in the path of every preview's URL, so when it's down, every customer's previews are down with it. We wanted Stagd spread across many places, not on one server in one region. Cloudflare's network already carries a large part of the web, and our Workers run on all of it.</li>
</ul>
<h2>What runs where</h2>
<p>Three Workers, talking to each other over service bindings with plain TypeScript, no RPC framework in between:</p>
<ul>
<li><strong>The server</strong>: the API, sign-in, the dashboard as static assets, and everything a preview's life needs.</li>
<li><strong>Hooks</strong>: takes GitHub's webhooks and puts them on a <strong>Queue</strong> at once, so a delivery isn't lost while the server deploys or has a bad minute.</li>
<li><strong>The edge</strong>: every preview's URL, <code>*.stagd.run</code>, checks who may open it and forwards to the right compute.</li>
</ul>
<p>Behind them:</p>
<ul>
<li><strong>D1</strong> for all the data, one database per environment, split into global tables and tables owned by a workspace, so a workspace can move to its own database later.</li>
<li><strong>Durable Objects</strong> for state that lives longer than a request: live updates pushed to each workspace's open dashboards, and the connection to each customer's relay.</li>
<li><strong>Workflows</strong> for long jobs that must finish: deploying a preview (build, restore the database, start the services, wait until it's live) and deleting a workspace, each step retried on its own.</li>
<li><strong>R2</strong> for backups, previews' thumbnails and the volumes of sleeping previews.</li>
<li><strong>Analytics Engine</strong> for each preview's CPU and memory over time.</li>
<li><strong>Browser Run</strong> to take a screenshot of each preview as it goes live.</li>
<li><strong>Cron triggers</strong> for the sweep every minute that puts idle previews to sleep and expires old ones.</li>
<li><strong>Cloudflare Tunnel</strong> to reach previews on compute behind a firewall.</li>
<li><strong>Email</strong> for sign-in codes and invites.</li>
</ul>
<h2>What worked</h2>
<p><strong>Building was fast.</strong> The platform did most of the infrastructure work for us: there was nothing to provision. The CLI and the dashboard only talk to the server through one API contract, generated for TypeScript, so the server can change underneath them without either noticing.</p>
<p><strong>Durable Objects are the best part.</strong> Each workspace has one object that every open dashboard listens to, so a change shows up everywhere at once. Our customers' relays keep a long-lived connection to an object of their own, and we run a small multiplexing protocol over it in TypeScript. On a server, those would have been a pub/sub system and a pool of long-lived connections to build and look after.</p>
<p><strong>Workflows fit long jobs well.</strong> A preview deploy takes a minute or two and touches several outside systems. Writing it as steps that are retried on their own, and that survive a deploy of our own code in the middle, removed a whole class of "stuck in Building" bugs.</p>
<p><strong>Queues in front of webhooks.</strong> GitHub doesn't retry a failed delivery on its own. A tiny Worker that only puts them on a queue means our server can be down for a deploy without missing a pull request.</p>
<h2>What hurt</h2>
<p><strong>We can't preview Stagd with Stagd.</strong> This is the one that hurts the most. Stagd builds previews from a compose file and runs them as containers. Stagd itself is Workers, D1, Durable Objects, Workflows and queues, and none of that fits in a container. <code>wrangler dev</code> runs it locally, and Cloudflare can upload a Worker's version with its own URL, but a full copy of the system per pull request, with its own database, objects and workflows, is something we'd have to assemble ourselves. So the product that gives every pull request a preview is reviewed the old way: locally and on staging. Making Stagd work for apps like itself is on our list.</p>
<p><strong>D1 is fast, until it isn't.</strong> Most queries take a few milliseconds. Now and then one takes seconds. Since every page in the dashboard checks the session first, one slow query was a blank page. We now keep who's signed in for 30 seconds per Worker instance, the dashboard asks again when the session check hangs, and the server logs any lookup slower than a second, so we can tell it happening.</p>
<p><strong>Some context doesn't survive.</strong> We tag each request's errors and analytics with the workspace and preview through <code>AsyncLocalStorage</code>. A Workflow's steps are called back outside the context they were started in, so for a while their events and errors were silently dropped. Nothing failed: data just went missing. Each step now goes back into its context explicitly.</p>
<p><strong>Error messages can point the wrong way.</strong> One morning every deploy, to staging and to production, failed with "You need to enable Analytics Engine" (error 10089). Analytics Engine was working fine, and our live Workers were writing to it. The real cause was that the account had dropped from Workers Paid to Workers Free. Upgrading the plan fixed it. If you see 10089 on a project that worked yesterday, check the plan first.</p>
<p><strong>Headless browsers and busy pages.</strong> Browser Run waits for a page's network to go quiet before it takes a screenshot. A page with a WebSocket, polling or hot reload never goes quiet, so the screenshot failed. Telling it to take the page as it stands after 15 seconds fixed it.</p>
<p><strong>Shared mail reputation.</strong> Sign-in codes sent through a shared sending IP landed in Junk at Microsoft 365 for a while, even with SPF, DKIM and DMARC passing. We <a href="https://stagd.dev/blog/junk-mail/">wrote about that</a> separately.</p>
<h2>Would we do it again?</h2>
<p>Yes, for sure. Everything in one place, a bill that grows with use rather than with servers, and nothing to resize when it gets busy: for a small team building a product like this, that's worth more than the rough edges above. The one we most want gone is that Stagd can't preview itself yet, and that's ours to fix.</p>
<h2>What's next</h2>
<p>Cloudflare runs containers now too, started and addressed from a Worker like any other binding. That opens a door we may go through: some parts of Stagd in another language, where a long-running process or a library from another ecosystem fits better than a Worker, while the rest stays on Workers, without giving up having everything in one place.</p>
<p>The same goes for the database. If D1's occasional slow queries or its size limits start to pinch, Postgres through Hyperdrive, Cloudflare's connection pooling and query caching in front of a regular Postgres database, is the obvious next step.</p>
<h2>What's open</h2>
<p>The server described here is closed, but what talks to it isn't. <a href="https://github.com/stagdhq/stagd">stagdhq/stagd</a> is open source under Apache 2.0: the CLI, the relay that connects private clusters and Docker hosts, and the API contract (protobuf, served over Connect) that the dashboard, the CLI and the MCP server all use. Anything the dashboard can do, a script can do from the same contract.</p>
<p>The server may well be opened too one day. For now it's changing too fast, and we'd rather open it once it's in a shape others can build on.</p>
<h2>If you're thinking of it</h2>
<ul>
<li><strong>Design around Durable Objects early.</strong> Anything that needs one writer, a live connection or fan-out is simpler as an object than as rows and locks.</li>
<li><strong>Put a queue in front of anything you can't afford to drop.</strong> It's a dozen lines.</li>
<li><strong>Treat D1 latency as variable.</strong> Cache what every request needs, and log slow queries from the start.</li>
<li><strong>Write long jobs as Workflows,</strong> and carry your request context into each step yourself.</li>
<li><strong>Keep an eye on the plan.</strong> Some errors about a missing feature really mean a missing plan.</li>
</ul>
<p>Stagd gives every pull request its own preview, with its own database and a link in the review, on compute you already have. <a href="https://stagd.dev/docs/quickstart/">Try it</a>, or tell us about your own Cloudflare setup at <a href="mailto:hello@stagd.dev">hello@stagd.dev</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Our sign-in codes went to Junk, and every check passed]]></title><description><![CDATA[SPF, DKIM and DMARC all passed, and Microsoft 365 still put our mail in Junk. What the headers said, and what helped.]]></description><link>https://stenrs.hashnode.dev/our-sign-in-codes-went-to-junk-and-every-check-passed</link><guid isPermaLink="true">https://stenrs.hashnode.dev/our-sign-in-codes-went-to-junk-and-every-check-passed</guid><category><![CDATA[email]]></category><category><![CDATA[email security]]></category><category><![CDATA[Microsoft365]]></category><category><![CDATA[Devops]]></category><dc:creator><![CDATA[Sten Roger Sandvik]]></dc:creator><pubDate>Mon, 23 Nov 2026 18:00:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b017afaca75dd874defa7cb/2cf9d949-bb90-4d99-923c-0c6998cf2b70.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Stagd signs people in with a code by email. People who review previews, such as designers, product managers and clients, often have no GitHub account, so the code is how they get in. It has one job: arrive within a minute, in the inbox.</p>
<p>At a Gmail address it did. At a Microsoft 365 address it went to Junk, or didn't show up at all. This is how we found out why, and why the usual checklist wasn't the answer.</p>
<h2>The checklist was green</h2>
<p>When mail goes to spam, the first suspects are always the same three records, so we checked them first:</p>
<ul>
<li><strong>SPF:</strong> passed, through the bounce domain our sending service uses.</li>
<li><strong>DKIM:</strong> passed, signed for our own domain.</li>
<li><strong>DMARC:</strong> passed, with a <code>p=reject</code> policy, the strictest there is.</li>
</ul>
<p>Microsoft agreed. The headers of a junked code said so in its own words:</p>
<pre><code>spf=pass  dkim=pass header.d=stagd-staging.dev  dmarc=pass
compauth=pass reason=100
</code></pre>
<p><code>compauth=pass</code> is Microsoft's own verdict on whether the sender is who they say they are. So authentication wasn't the problem. Every guide that starts with "check your SPF record" had nothing more to tell us.</p>
<h2>What the headers actually said</h2>
<p>The line that mattered was further down:</p>
<pre><code>SCL:5; SFV:SPM; CAT:SPM; BCL:0
</code></pre>
<ul>
<li><strong>SCL 5</strong> is the spam confidence level. Five and above goes to Junk.</li>
<li><strong>SFV:SPM</strong> means the spam filter marked it as spam.</li>
<li><strong>BCL:0</strong> is the bulk complaint level: zero, so not a newsletter or marketing mail.</li>
</ul>
<p>Microsoft believed the mail came from us, and still thought it looked like spam. That's a verdict about reputation, not identity: who has sent from this domain and this IP before, and how people reacted to it.</p>
<p>And we had no reputation. The domain was new, and its mail went out through our provider's shared IP, <code>104.30.16.132</code>, which carries the history of everyone else sending through it. Gmail weighs that differently and delivered it to the inbox. Microsoft didn't.</p>
<h2>What we tried</h2>
<p><strong>A From domain that can receive mail.</strong> Staging's sending domain had no MX record and no root SPF record: it could send mail but not receive any. That's a known mark against a sender in Microsoft 365. We turned on mail routing for it, which gave it MX records and a root SPF. Staging's codes went from not arriving at all to arriving in Junk. Progress, of a kind.</p>
<p><strong>No hidden preheader.</strong> Our mail had a preheader: hidden text at the top that inboxes show as a preview line. Hidden text is a classic spam signal, so we removed it. The next code got the same verdict, <code>SCL:5</code>. It wasn't the cause, but we've left it out since: the heading and first lines make a fine preview.</p>
<p><strong>A reply-to someone reads.</strong> Our mail came from <code>no-reply@</code>, and a sender nobody can answer counts against it. Replies now go to <code>hello@stagd.dev</code>, a mailbox we read. It's better for the people getting the mail too: someone who answers an invite reaches a person.</p>
<p><strong>A message id for every mail.</strong> The server now logs our provider's message id for each mail it sends. The next code that goes missing can be found in Microsoft 365's message trace, instead of guessed at.</p>
<h2>Where it stands</h2>
<p>Our sign-in codes now reach the inbox at Microsoft 365, still sent through the same provider. We can't point to one thing that did it. Most likely it's the fixes above, and time: reputation is built by sending mail people want and open.</p>
<p>If they slip back into Junk, two things help:</p>
<ul>
<li><strong>Marking it as not junk.</strong> When a code lands in Junk, "Not junk" in Outlook, and a submission to Microsoft as a false positive, both count in the sender's favour.</li>
<li><strong>A sending service with standing at Microsoft.</strong> Services that send only transactional mail, such as Postmark, keep their shared IPs clean, and their mail usually reaches the inbox from the first day. Every mail Stagd sends goes through one function, so moving is a small change, and we'll make it if codes start landing in Junk again.</li>
</ul>
<p>Sign-in doesn't have to rely on mail at all, either. Reviewers can sign in with Google, with Microsoft to follow, so most of them use an account they already have, and the code is the fallback.</p>
<h2>What we'd tell you</h2>
<ul>
<li><strong>Passing SPF, DKIM and DMARC means Microsoft knows it's you.</strong> It doesn't mean Microsoft trusts you. Read the <code>X-Forefront-Antispam-Report</code> header: <code>SCL</code> and <code>SFV</code> say what the filter decided.</li>
<li><strong>A new domain on a shared IP starts with no standing.</strong> Gmail and Microsoft 365 treat that differently, so test with both before your users do.</li>
<li><strong>Make the From domain able to receive mail,</strong> and give people a reply-to they can use.</li>
<li><strong>Log a message id for every mail,</strong> so a missing one can be traced rather than guessed at.</li>
</ul>
<p>Stagd gives every pull request its own preview, with its own database and a link in the review. Its previews catch your app's mail too, in an inbox reviewers can read, so nothing a preview sends reaches a real person. <a href="https://stagd.dev/docs/quickstart/">Try it</a>, or tell us about your own mail troubles at <a href="mailto:hello@stagd.dev">hello@stagd.dev</a>.</p>
<hr />
<p><em>First published on the <a href="https://stagd.dev/blog/junk-mail/">Stagd blog</a>.</em></p>
]]></content:encoded></item><item><title><![CDATA[I got tired of rebuilding preview environments, so I built Stagd]]></title><description><![CDATA[A live preview of every pull request, with its own database, its own inbox and a link in the review, on compute you already have.]]></description><link>https://stenrs.hashnode.dev/i-got-tired-of-rebuilding-preview-environments-so-i-built-stagd</link><guid isPermaLink="true">https://stenrs.hashnode.dev/i-got-tired-of-rebuilding-preview-environments-so-i-built-stagd</guid><category><![CDATA[Devops]]></category><category><![CDATA[Docker]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Kubernetes]]></category><dc:creator><![CDATA[Sten Roger Sandvik]]></dc:creator><pubDate>Sat, 21 Nov 2026 11:11:02 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b017afaca75dd874defa7cb/e1401937-1d0b-4dae-bccc-85392211b6ed.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi Hashnode! I'm Sten, a developer in Norway. This is my first post here, so let me start with the thing I've been building.</p>
<p>Every few projects, I'd end up building preview environments for pull requests again: shell scripts, a GitHub Actions workflow, some glue to start a database and post a link. It worked, and then the next project needed it all over again. I kept waiting for a product that made this easy and still let me keep my own compose file, my own compute and my own data. It didn't show up, so I built it. It's called <strong>Stagd</strong>.</p>
<h2>The problem it solves</h2>
<p>Most teams have one staging environment and more changes than it can hold. Someone deploys their branch, someone else overwrites it, and the reviewer opens a link that's running somebody else's code. "Is my change on staging yet?" gets asked in the team channel every day.</p>
<p>The review suffers most. A pull request gets read, not tried. The designer, the product manager or the client who could have caught the problem in thirty seconds of clicking only sees it after the merge.</p>
<h2>What Stagd does</h2>
<p>Open a pull request, and Stagd:</p>
<ul>
<li>builds your images from the branch (with cache),</li>
<li>starts a database and restores a seed you choose into it,</li>
<li>brings your services up and gives each one that needs it a URL,</li>
<li>catches the mail your app sends in an inbox on the preview, so nothing reaches a real person,</li>
<li>posts the link in the pull request, and updates the same comment as each step finishes.</li>
</ul>
<p>A typical app is live in about a minute. The preview sleeps when nobody uses it, wakes on the next visit or push, and is removed with its database when the pull request closes.</p>
<h2>One file in your repository</h2>
<p>There's no settings page where you click your app together. The setup is a <code>stagd.yaml</code> next to the compose file you already run locally:</p>
<pre><code class="language-yaml">version: 1
app:
  compose: compose.yaml
ingress:
  site: { service: web, port: 3000, primary: true }
  api: { service: api, port: 8080 }
services:
  postgres:
    seed: app-anonymized
  mail: {}
lifecycle: { sleep_after: 2h }
</code></pre>
<p>That gives the preview a URL for the site, one for the API, a Postgres database restored from the <code>app-anonymized</code> seed and an inbox for its mail. Because it lives in the repository, a pull request that adds a worker or a second URL gets a preview that already runs with it, and the change is reviewed like any other.</p>
<p>Postgres, MySQL, MariaDB and MongoDB all work, restored from a dump in your own blob storage.</p>
<h2>Your compute, not ours</h2>
<p>Previews run in your Namespace workspace, your Kubernetes cluster or a Docker host. Stagd sends the instructions and reads status and logs back, so your code and data stay on your infrastructure, and you pay your provider directly, with no markup. A cluster behind NAT connects with <code>stagd relay</code>, which dials out, so there are no ports to open.</p>
<h2>Reviewers without a GitHub account</h2>
<p>Who can open a preview is set in Stagd, not in the pull request, so a change can't open up its own access. People outside your GitHub organisation are invited and sign in with Google or a code by email.</p>
<h2>Agents can use it too</h2>
<p>A preview doesn't need a pull request. You can start one from any branch through the CLI, the API or the MCP server, and that makes it something a coding agent can drive: start a preview of its change, wait for it, take a screenshot, read the logs and the mail, fix what's broken and push again. By the time a person opens the pull request, the change has already been seen running.</p>
<pre><code class="language-sh">stagd mcp install
</code></pre>
<h2>Trying it</h2>
<pre><code class="language-sh">curl -fsSL https://stagd.dev/install.sh | bash
stagd login
stagd init
</code></pre>
<p><code>stagd init</code> writes a first <code>stagd.yaml</code> from your compose file, and <code>stagd setup</code> shows what's left (connecting GitHub, picking a repository, connecting compute). The <a href="https://stagd.dev/docs/quickstart/">quickstart</a> walks through each step, and the CLI is open source under Apache-2.0.</p>
<p>Stagd is in early access and free while it is. If you want the longer story, it's on the <a href="https://stagd.dev/blog/launch/">Stagd blog</a>.</p>
<h2>I'd love your feedback</h2>
<p>What's your team doing for previews today: one shared staging, something home-made, or nothing at all? And what would stop you from trying something like this? Tell me in the comments, or at <a href="mailto:hello@stagd.dev">hello@stagd.dev</a>. I read everything.</p>
]]></content:encoded></item></channel></rss>