<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>🐥 YellowDuck.be</title>
  <id>https://www.yellowduck.be/posts/feed</id>
  <updated>2026-12-04T18:00:00Z</updated>
  <author>
    <name>Pieter Claerhout</name>
    <email>pieter@yellowduck.be</email>
  </author>
  <link rel="self" href="https://www.yellowduck.be/posts/feed"/>
  <link rel="alternate" href="https://www.yellowduck.be"/>
  <entry>
    <id>https://www.yellowduck.be/posts/laravel-rust-and-go-reinventing-laravel-in-other-languages</id>
    <title>🐥 Laravel Rust and Go: Reinventing Laravel in Other Languages?</title>
    <updated>2026-12-04T18:00:00Z</updated>
    <published>2026-12-04T18:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/laravel-rust-and-go-reinventing-laravel-in-other-languages"/>
    <content type="html">&lt;p&gt;Laravel has built a reputation for making PHP application development productive. Its conventions, integrated tooling and extensive ecosystem make it relatively easy to build complete business applications without assembling dozens of independent libraries.&lt;/p&gt;
&lt;p&gt;With &lt;a href=&quot;https://laravel.com/blog/introducing-laravel-for-rust&quot;&gt;Laravel Rust&lt;/a&gt; and &lt;a href=&quot;https://laravel.com/blog/introducing-laravel-for-go&quot;&gt;Laravel Go&lt;/a&gt;, the idea is to bring that same philosophy to two different programming languages.&lt;/p&gt;
&lt;p&gt;It's an interesting proposition, but does it make sense to choose these new frameworks over established ecosystems such as Elixir Phoenix or ASP.NET Core?&lt;/p&gt;
&lt;h1&gt;What are Laravel Rust and Laravel Go?&lt;/h1&gt;
&lt;p&gt;Both projects aim to recreate much of the Laravel developer experience in another language.&lt;/p&gt;
&lt;p&gt;Rather than providing just a web framework, they attempt to offer an integrated application development platform with features such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Routing and middleware.&lt;/li&gt;
&lt;li&gt;Authentication and authorization.&lt;/li&gt;
&lt;li&gt;Database access and migrations.&lt;/li&gt;
&lt;li&gt;Validation.&lt;/li&gt;
&lt;li&gt;Background jobs and queues.&lt;/li&gt;
&lt;li&gt;Mail and notifications.&lt;/li&gt;
&lt;li&gt;Inertia integration.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Laravel Rust builds on Rust's ecosystem, including &lt;a href=&quot;https://github.com/tokio-rs/axum&quot;&gt;Axum&lt;/a&gt; and &lt;a href=&quot;https://tokio.rs/&quot;&gt;Tokio&lt;/a&gt;. Laravel Go uses Go's standard HTTP infrastructure and concurrency model.&lt;/p&gt;
&lt;p&gt;The underlying idea is appealing: combine Laravel's productivity and conventions with the performance and language characteristics of Rust or Go.&lt;/p&gt;
&lt;p&gt;The source code is available on GitHub: &lt;a href=&quot;https://github.com/laravel/rust&quot;&gt;Laravel Rust&lt;/a&gt; and &lt;a href=&quot;https://github.com/laravel/go&quot;&gt;Laravel Go&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;But there is an important distinction between adopting a language and adopting a new framework built around it.&lt;/p&gt;
&lt;h1&gt;The safety argument&lt;/h1&gt;
&lt;p&gt;One of the most obvious reasons to move away from PHP is type safety.&lt;/p&gt;
&lt;p&gt;Rust and Go provide static typing, whereas PHP is dynamically typed, even though modern PHP has made considerable progress with type declarations, enums, readonly properties and static analysis tools such as &lt;a href=&quot;https://phpstan.org/&quot;&gt;PHPStan&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Rust goes considerably further.&lt;/p&gt;
&lt;p&gt;Its &lt;a href=&quot;https://doc.rust-lang.org/book/ch04-00-understanding-ownership.html&quot;&gt;ownership and borrowing system&lt;/a&gt; provides compile-time guarantees around memory safety and data races in safe Rust code. This eliminates entire categories of problems that can otherwise be difficult to detect through testing.&lt;/p&gt;
&lt;p&gt;Go offers static typing and garbage collection, but doesn't provide the same compile-time guarantees as Rust.&lt;/p&gt;
&lt;p&gt;However, neither language automatically makes business applications more secure.&lt;/p&gt;
&lt;p&gt;A perfectly memory-safe Rust application can still contain broken authorization, SQL injection or tenant-isolation vulnerabilities.&lt;/p&gt;
&lt;p&gt;For most SaaS applications, these architectural and application-level security concerns are often more important than memory safety alone.&lt;/p&gt;
&lt;h1&gt;Performance isn't necessarily the deciding factor&lt;/h1&gt;
&lt;p&gt;Rust and Go have clear performance advantages over PHP in many workloads.&lt;/p&gt;
&lt;p&gt;Laravel's own &lt;a href=&quot;https://laravel.com/blog/laravel-rust-and-cloud-for-rails-django-go-and-more&quot;&gt;Laravel Rust performance benchmarks&lt;/a&gt; demonstrate substantial improvements compared with traditional Laravel PHP.&lt;/p&gt;
&lt;p&gt;However, synthetic HTTP benchmarks don't necessarily represent real business applications.&lt;/p&gt;
&lt;p&gt;A typical SaaS application spends considerable time waiting for database queries, external APIs, file storage and background processing.&lt;/p&gt;
&lt;p&gt;The language runtime might not be the actual bottleneck.&lt;/p&gt;
&lt;p&gt;Furthermore, performance comes with trade-offs. Rust introduces additional development complexity, while compiling and maintaining a Rust application can be more demanding than working with PHP.&lt;/p&gt;
&lt;p&gt;Go is considerably simpler, but its performance advantage doesn't automatically justify adopting an entirely new framework.&lt;/p&gt;
&lt;h1&gt;The ecosystem maturity problem&lt;/h1&gt;
&lt;p&gt;This is where I have the biggest reservations.&lt;/p&gt;
&lt;p&gt;Laravel PHP benefits from years of development, documentation, community knowledge and third-party integrations.&lt;/p&gt;
&lt;p&gt;ASP.NET Core has a similarly mature ecosystem, backed by Microsoft.&lt;/p&gt;
&lt;p&gt;Elixir Phoenix has an established ecosystem built around OTP, Ecto, LiveView and a coherent set of libraries.&lt;/p&gt;
&lt;p&gt;Laravel Rust and Go are starting from a very different position.&lt;/p&gt;
&lt;p&gt;Even if the initial framework implementation is excellent, several questions remain:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How quickly will third-party integrations become available?&lt;/li&gt;
&lt;li&gt;How mature will the ORM and database abstractions become?&lt;/li&gt;
&lt;li&gt;How reliable will the queue and background-processing implementations be?&lt;/li&gt;
&lt;li&gt;How quickly will security vulnerabilities be addressed?&lt;/li&gt;
&lt;li&gt;Will the frameworks evolve alongside their underlying language ecosystems?&lt;/li&gt;
&lt;li&gt;Will there be enough community adoption to make long-term maintenance practical?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These aren't necessarily reasons to dismiss the projects. But adopting a new framework means accepting some uncertainty about its future.&lt;/p&gt;
&lt;p&gt;A safer language doesn't automatically result in a more maintainable application.&lt;/p&gt;
&lt;h1&gt;What about Elixir Phoenix and ASP.NET Core?&lt;/h1&gt;
&lt;p&gt;Interestingly, I think these two established ecosystems offer more compelling alternatives.&lt;/p&gt;
&lt;h2&gt;Elixir Phoenix&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://www.phoenixframework.org/&quot;&gt;Phoenix&lt;/a&gt; approaches application development from a different architectural perspective.&lt;/p&gt;
&lt;p&gt;Instead of focusing primarily on static typing and compilation, Elixir combines functional programming, immutable data structures and the &lt;a href=&quot;https://www.erlang.org/doc/system/conc_prog.html&quot;&gt;BEAM's lightweight process model&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This has some important benefits:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Immutable data structures reduce unexpected side effects.&lt;/li&gt;
&lt;li&gt;Isolated processes make concurrency easier to reason about.&lt;/li&gt;
&lt;li&gt;Message passing avoids much of the complexity of shared mutable state.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.erlang.org/doc/system/sup_princ.html&quot;&gt;OTP supervision&lt;/a&gt; provides built-in fault isolation and recovery.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://hexdocs.pm/phoenix_live_view/&quot;&gt;Phoenix LiveView&lt;/a&gt; makes interactive applications possible without requiring a separate frontend architecture.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For applications with substantial background processing, integrations and concurrent workloads, these characteristics can be more valuable than raw HTTP performance.&lt;/p&gt;
&lt;p&gt;The trade-off is dynamic typing and a smaller ecosystem compared with mainstream enterprise platforms.&lt;/p&gt;
&lt;h2&gt;ASP.NET Core&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/aspnet/core/&quot;&gt;ASP.NET Core&lt;/a&gt; is probably the strongest all-round alternative for conventional enterprise application development.&lt;/p&gt;
&lt;p&gt;It offers:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Strong static typing through C#.&lt;/li&gt;
&lt;li&gt;Excellent compiler and IDE support.&lt;/li&gt;
&lt;li&gt;Mature dependency injection.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/ef/core/&quot;&gt;Entity Framework Core&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Authentication and authorization infrastructure.&lt;/li&gt;
&lt;li&gt;Background services and asynchronous execution.&lt;/li&gt;
&lt;li&gt;Extensive observability and diagnostics.&lt;/li&gt;
&lt;li&gt;A large ecosystem of libraries and integrations.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Unlike Laravel Rust and Go, ASP.NET Core has a long-established ecosystem and a predictable support lifecycle.&lt;/p&gt;
&lt;p&gt;It also doesn't require developers to adopt an unnecessarily complicated architecture. &lt;a href=&quot;https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis&quot;&gt;Minimal APIs&lt;/a&gt; make it possible to build relatively lightweight applications.&lt;/p&gt;
&lt;p&gt;If the primary motivation for moving away from PHP is stronger typing, maintainability and enterprise integration capabilities, ASP.NET Core is already a compelling option.&lt;/p&gt;
&lt;h1&gt;The AI development argument&lt;/h1&gt;
&lt;p&gt;Another interesting aspect of Laravel's new direction is its apparent focus on AI-assisted development.&lt;/p&gt;
&lt;p&gt;The reasoning makes sense.&lt;/p&gt;
&lt;p&gt;If AI agents generate increasingly large portions of an application, frameworks benefit from:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Strong conventions.&lt;/li&gt;
&lt;li&gt;Predictable project structures.&lt;/li&gt;
&lt;li&gt;Built-in functionality.&lt;/li&gt;
&lt;li&gt;Strict compiler checks.&lt;/li&gt;
&lt;li&gt;Fewer architectural decisions.&lt;/li&gt;
&lt;li&gt;Automated validation of generated code.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I agree with this direction, but I don't think Laravel Rust or Go has an exclusive advantage here.&lt;/p&gt;
&lt;p&gt;ASP.NET Core already provides excellent compiler diagnostics and tooling. Phoenix offers consistent architectural conventions through OTP and libraries such as &lt;a href=&quot;https://ash-hq.org/&quot;&gt;Ash&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;A mature ecosystem with extensive documentation and established patterns can actually be more valuable to an AI coding agent than a new framework specifically designed around AI-assisted development.&lt;/p&gt;
&lt;h1&gt;How would I choose?&lt;/h1&gt;
&lt;p&gt;The following is how I would position the different options for a new SaaS application.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Requirement&lt;/th&gt;
&lt;th&gt;My preference&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Maximum compile-time memory safety&lt;/td&gt;
&lt;td&gt;Rust&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;High performance with simple development&lt;/td&gt;
&lt;td&gt;Go&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Complex concurrent systems&lt;/td&gt;
&lt;td&gt;Elixir / Phoenix&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Enterprise application development&lt;/td&gt;
&lt;td&gt;ASP.NET Core&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fast business application development&lt;/td&gt;
&lt;td&gt;Laravel PHP&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Interactive server-driven applications&lt;/td&gt;
&lt;td&gt;Phoenix LiveView&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;As for Laravel's new offerings:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Laravel Rust&lt;/strong&gt; is interesting. It combines genuine language-level safety and performance advantages with an attempt to provide a familiar, batteries-included development experience. I would keep an eye on its ecosystem, particularly its database and integration capabilities.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Laravel Go&lt;/strong&gt; is less compelling to me. Go already has a relatively simple language, a strong standard library and established web frameworks such as &lt;a href=&quot;https://github.com/go-chi/chi&quot;&gt;Chi&lt;/a&gt;, &lt;a href=&quot;https://gin-gonic.com/&quot;&gt;Gin&lt;/a&gt; and &lt;a href=&quot;https://echo.labstack.com/&quot;&gt;Echo&lt;/a&gt;. I'm not yet convinced that recreating Laravel's ecosystem is necessary to make Go productive for web development.&lt;/p&gt;
&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;I think Laravel is making an interesting strategic move, but I'm not yet convinced that Laravel Rust or Go represents a meaningful improvement over existing application development ecosystems.&lt;/p&gt;
&lt;p&gt;There are three things worth distinguishing:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Language safety:&lt;/strong&gt; Rust genuinely provides stronger compile-time memory-safety guarantees.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Framework productivity:&lt;/strong&gt; Laravel's conventions and integrated tooling are valuable, regardless of the underlying language.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Application maintainability:&lt;/strong&gt; This depends much more on architecture, ecosystem maturity, team knowledge and code quality than on the language itself.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If I were starting a new enterprise SaaS application today, I would still seriously consider Elixir Phoenix and ASP.NET Core before choosing either of the new Laravel implementations.&lt;/p&gt;
&lt;p&gt;Not because Laravel Rust or Go are bad ideas, but because both introduce an additional risk: building a long-lived application on top of a brand-new framework ecosystem.&lt;/p&gt;
&lt;p&gt;The real test won't be the benchmarks or the initial developer experience. It will be the quality of the applications people build with these frameworks, the maturity of their integrations and how well they hold up over several years of maintenance.&lt;/p&gt;
&lt;p&gt;That's what ultimately determines whether these projects become serious alternatives or remain interesting experiments in bringing Laravel's philosophy to other languages.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/golang&quot;&gt;#golang&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/rust&quot;&gt;#rust&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/development&quot;&gt;#development&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/laravel&quot;&gt;#laravel&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/php&quot;&gt;#php&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/i-dont-write-code-anymore</id>
    <title>🔗 I Don't Write Code Anymore</title>
    <updated>2026-12-04T14:00:00Z</updated>
    <published>2026-12-04T14:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/i-dont-write-code-anymore"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;What happens when a programmer stops reviewing every line of AI-generated code? Jason McCreary describes a year-long shift through four stages, from using AI for tedious snippets to handing it the whole job. He moved from writing tests himself, to letting AI write and run them, to trusting automated checks instead of reading the code.&lt;/p&gt;
&lt;p&gt;The change, he argues, works only when strong guardrails are already in place: tests, static analysis, CI, and adversarial agents that challenge the code and its coverage. McCreary says his value is no longer typing code but delivering results and guiding AI with experience. He built Double and PHPUnit TIA without opening an IDE, and now frames his role as a software foreman. It’s a provocative case for letting go—but not for letting quality controls go.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://jasonmccreary.me/articles/i-dont-write-code-anymore&quot;&gt;Continue reading on &lt;strong&gt;jasonmccreary.me&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/development&quot;&gt;#development&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/ai&quot;&gt;#ai&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/testing&quot;&gt;#testing&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/the-last-technical-interview</id>
    <title>🔗 The Last Technical Interview</title>
    <updated>2026-12-04T09:00:00Z</updated>
    <published>2026-12-04T09:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/the-last-technical-interview"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;Today we will pour one out for the vaunted technical interview process, which is on its last leg. And we’ll talk a little about what’s replacing it.&lt;/p&gt;
&lt;p&gt;This post has been almost 35 years in the making; that’s how long I have been conducting technical interviews. And for a few of those decades, I also worked to try to improve the process itself. I’ve had to care a lot about it, because it’s so broken.&lt;/p&gt;
&lt;p&gt;It turns out interviewing was broken long before I learned the trade, and despite the many attempts to band-aid it, it’s still broken today. It has managed to survive in spite of that. But it is finally dying on its own. People are a bit unclear on what’s next, so we’ll talk about some of our options.&lt;/p&gt;
&lt;p&gt;But it’s not an easy path I bring you, no silver bullet. Remember that, grasshopper, when you get to the end and come back to yell at me.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://steve-yegge.medium.com/the-last-technical-interview-bc13ddcf4564&quot;&gt;Continue reading on &lt;strong&gt;steve-yegge.medium.com&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/development&quot;&gt;#development&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/understand-team-effectiveness</id>
    <title>🔗 Understand team effectiveness</title>
    <updated>2026-12-03T18:00:00Z</updated>
    <published>2026-12-03T18:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/understand-team-effectiveness"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;What truly defines an effective team? Grounded in Google’s foundational research from Project Oxygen and Project Aristotle, this article explores the nuanced dynamics of teamwork. It highlights that effectiveness extends beyond mere metrics, requiring a blend of qualitative insights and measurable outputs. Psychological safety emerges as a critical factor, allowing team members to take interpersonal risks without fear. The article also emphasizes concrete steps to assess and improve team dynamics, such as gathering feedback on dependability and clarity. With substantial data collected from various team compositions, it reveals that how teams work together is often more significant than who is on the team, challenging traditional views on team dynamics.  Whether you're in a tech startup or a large corporation, understanding these principles can transform team performance and drive meaningful results.&lt;/p&gt;
&lt;p&gt;The full insights on nurturing effective teams are drawn from extensive studies involving over 180 teams, laying a framework for organizations to follow.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://rework.withgoogle.com/intl/en/guides/understand-team-effectiveness&quot;&gt;Continue reading on &lt;strong&gt;rework.withgoogle.com&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/development&quot;&gt;#development&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/best-practice&quot;&gt;#best-practice&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/claude-for-legal</id>
    <title>🔗 Claude for Legal</title>
    <updated>2026-12-03T14:00:00Z</updated>
    <published>2026-12-03T14:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/claude-for-legal"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;What if a contract’s most costly clause were hiding in plain sight? Ruben Hassid shows how to set up Anthropic’s commercial-legal plugin in Claude, teach it personal contract rules, and use it to review agreements, track renewals, and summarize whether a deal is ready to sign. The guide walks through five practical scenarios, from checking an NDA to examining a software vendor’s data terms, and explains why Claude Code is useful for keeping a playbook available across sessions.&lt;/p&gt;
&lt;p&gt;The setup takes about 30 minutes, but the advice comes with important limits: the plugin’s output is a draft, not legal counsel. Hassid recommends escalating disputes, equity deals, personal guarantees, and other high-stakes matters to a lawyer, while also checking privacy settings before sharing sensitive contracts. It’s a practical way to catch issues earlier—not a reason to stop getting professional advice.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://ruben.substack.com/p/claude-for-legal&quot;&gt;Continue reading on &lt;strong&gt;ruben.substack.com&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/tools&quot;&gt;#tools&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/ai&quot;&gt;#ai&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/dont-size-teams-size-loops</id>
    <title>🔗 Don't size teams, size loops</title>
    <updated>2026-12-03T09:00:00Z</updated>
    <published>2026-12-03T09:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/dont-size-teams-size-loops"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;What changes when agents take on the grunt work and engineering teams shrink? This piece considers how smaller teams alter the roles leaders rely on, and whether the familiar idea of a team still fits.&lt;/p&gt;
&lt;p&gt;Drawing on conversations with engineering leaders, the article focuses on feedback loops once administered through frameworks like Scrum. Its central question is practical: when agents do more of the work, how should teams rethink the way they coordinate and learn? Rather than treating team size as the main measure, it points attention toward the loops that keep work moving and provide feedback.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://zarar.dev/dont-size-teams-size-loops/&quot;&gt;Continue reading on &lt;strong&gt;zarar.dev&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/development&quot;&gt;#development&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/best-practice&quot;&gt;#best-practice&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/ai&quot;&gt;#ai&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/apt-says-the-php-ppa-changed-its-label-what-it-means-and-what-to-do</id>
    <title>🐥 Apt Says the PHP PPA “Changed Its Label”: What It Means and What to Do</title>
    <updated>2026-12-02T18:00:00Z</updated>
    <published>2026-12-02T18:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/apt-says-the-php-ppa-changed-its-label-what-it-means-and-what-to-do"/>
    <content type="html">&lt;p&gt;Running &lt;code&gt;apt update&lt;/code&gt; on a server one morning gave us this:&lt;/p&gt;
&lt;pre class=&quot;lumis&quot;&gt;&lt;code class=&quot;language-plaintext&quot; translate=&quot;no&quot; tabindex=&quot;0&quot;&gt;&lt;span class=&quot;l-line&quot; data-line=&quot;1&quot;&gt;E: Repository &amp;#39;https://ppa.setup-php.com/ondrej/php/ubuntu jammy InRelease&amp;#39;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;2&quot;&gt;   changed its &amp;#39;Label&amp;#39; value from &amp;#39;PPA for PHP&amp;#39; to &amp;#39;PPA for PHP (deprecated)&amp;#39;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;3&quot;&gt;N: This must be accepted explicitly before updates for this repository can be&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;4&quot;&gt;   applied. See apt-secure(8) manpage for details.&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;5&quot;&gt;Do you want to accept these changes and continue updating from this repository? [y/N]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Answering &lt;code&gt;y&lt;/code&gt; makes the update go through. But the message signals that something upstream is changing, so it's worth understanding.&lt;/p&gt;
&lt;h1&gt;Why apt asks&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;apt&lt;/code&gt; treats changes to a repository's release metadata (Label, Origin, Suite, Codename) as suspicious because a hijacked mirror could change them. It refuses to continue until a human accepts the change. Here, the cause is harmless: the maintainer relabeled the repository.&lt;/p&gt;
&lt;p&gt;In non-interactive runs (provisioning scripts, deploy hooks, cron), nobody can answer the prompt, so &lt;code&gt;apt update&lt;/code&gt; fails. &lt;code&gt;apt-get update --allow-releaseinfo-change&lt;/code&gt; gets past the error, but only silences it. It does not change where your packages come from.&lt;/p&gt;
&lt;h1&gt;What the new label says&lt;/h1&gt;
&lt;p&gt;Reports on several forums (Nextcloud, HestiaCP, Mail-in-a-Box) show the same change on the Ondřej Surý PHP PPA, with the label reading &amp;quot;Use packages.sury.org/php instead&amp;quot;. The PPA appears to be moving to &lt;code&gt;packages.sury.org/php&lt;/code&gt;, the repository already used for Debian. We found no official announcement or timeline, so treat this as a strong hint rather than a confirmed schedule.&lt;/p&gt;
&lt;h1&gt;What we found on our server&lt;/h1&gt;
&lt;p&gt;Our staging worker runs Ubuntu 22.04 (jammy) and was provisioned by Laravel Forge. Listing the apt sources showed two entries for the same PPA:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;File&lt;/th&gt;
&lt;th&gt;Source&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ondrej-php.list&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ppa.setup-php.com/ondrej/php&lt;/code&gt;, a mirror, with &lt;code&gt;signed-by=/usr/share/keyrings/ondrej-php.gpg&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ondrej-ubuntu-php-jammy.list&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ppa.launchpadcontent.net/ondrej/php&lt;/code&gt;, the standard &lt;code&gt;add-apt-repository ppa:ondrej/php&lt;/code&gt; entry&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The mirror entry raised the Label error. &lt;code&gt;apt-cache policy&lt;/code&gt; showed that both repositories served identical PHP builds:&lt;/p&gt;
&lt;pre class=&quot;lumis&quot;&gt;&lt;code class=&quot;language-plaintext&quot; translate=&quot;no&quot; tabindex=&quot;0&quot;&gt;&lt;span class=&quot;l-line&quot; data-line=&quot;1&quot;&gt;$ apt-cache policy php8.5-cli&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;2&quot;&gt;php8.5-cli:&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;3&quot;&gt;  Installed: 8.5.13-2+ubuntu22.04.1+deb.sury.org+1&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;4&quot;&gt;  Candidate: 8.5.13-2+ubuntu22.04.1+deb.sury.org+1&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;5&quot;&gt;  Version table:&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;6&quot;&gt; *** 8.5.13-2+ubuntu22.04.1+deb.sury.org+1 500&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;7&quot;&gt;        500 https://ppa.setup-php.com/ondrej/php/ubuntu jammy/main amd64 Packages&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;8&quot;&gt;        500 https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy/main amd64 Packages&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Same version, two sources. Removing either one changes nothing about what is installed.&lt;/p&gt;
&lt;h1&gt;What we did&lt;/h1&gt;
&lt;p&gt;We removed the deprecated mirror entry and kept the Launchpad one:&lt;/p&gt;
&lt;pre class=&quot;lumis&quot;&gt;&lt;code class=&quot;language-bash&quot; translate=&quot;no&quot; tabindex=&quot;0&quot;&gt;&lt;span class=&quot;l-line&quot; data-line=&quot;1&quot;&gt;&lt;span class=&quot;l-function-call&quot;&gt;sudo&lt;/span&gt; &lt;span class=&quot;l-variable-parameter&quot;&gt;mv&lt;/span&gt; &lt;span class=&quot;l-variable-parameter&quot;&gt;/etc/apt/sources.list.d/ondrej-php.list&lt;/span&gt; &lt;span class=&quot;l-variable-parameter&quot;&gt;~/ondrej-php.list.bak&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;2&quot;&gt;&lt;span class=&quot;l-function-call&quot;&gt;sudo&lt;/span&gt; &lt;span class=&quot;l-variable-parameter&quot;&gt;apt&lt;/span&gt; &lt;span class=&quot;l-variable-parameter&quot;&gt;update&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;3&quot;&gt;&lt;span class=&quot;l-function-call&quot;&gt;apt-cache&lt;/span&gt; &lt;span class=&quot;l-variable-parameter&quot;&gt;policy&lt;/span&gt; &lt;span class=&quot;l-variable-parameter&quot;&gt;php8.5-cli&lt;/span&gt; &lt;span class=&quot;l-variable-parameter&quot;&gt;php8.4-cli&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Moving the file to a backup instead of deleting it keeps the change easy to undo. After this, &lt;code&gt;policy&lt;/code&gt; should list only the Launchpad source with the same candidate versions.&lt;/p&gt;
&lt;h1&gt;Caveats&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Provisioning tools may re-add the entry.&lt;/strong&gt; If a tool like Forge created the mirror entry, it might recreate it the next time it installs or updates PHP. Check after your next PHP action.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;This is a stopgap.&lt;/strong&gt; If the PPA is moving to &lt;code&gt;packages.sury.org/php&lt;/code&gt;, the Launchpad entry will eventually go stale too. Watch for a similar Label message on it. The real fix is migrating to the sury.org repository, following the maintainer's instructions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Official docs lag.&lt;/strong&gt; The PHP downloads page for Ubuntu still tells you to run &lt;code&gt;add-apt-repository ppa:ondrej/php&lt;/code&gt;. It also notes that these are third-party builds with patches the PHP project doesn't control. That's worth knowing regardless of which source you use.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Check every server.&lt;/strong&gt; Run &lt;code&gt;grep -r &amp;quot;&amp;quot; /etc/apt/sources.list.d/&lt;/code&gt; on each one. Duplicates like this are easy to miss.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;Takeaways&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;A Label-change prompt from apt is a prompt to investigate, not just to press &lt;code&gt;y&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--allow-releaseinfo-change&lt;/code&gt; silences the error and migrates nothing.&lt;/li&gt;
&lt;li&gt;Audit your apt sources for duplicates. We had the same PPA twice.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;apt-cache policy &amp;lt;package&amp;gt;&lt;/code&gt; to see which repository your packages really come from.&lt;/li&gt;
&lt;/ol&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/laravel&quot;&gt;#laravel&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/php&quot;&gt;#php&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/devops&quot;&gt;#devops&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/terminal&quot;&gt;#terminal&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/linux&quot;&gt;#linux&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/how-to-be-more-ambitious-a-tutorial-for-humans-with-models</id>
    <title>🔗 How to Be More Ambitious: A Tutorial for Humans with Models</title>
    <updated>2026-12-02T14:00:00Z</updated>
    <published>2026-12-02T14:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/how-to-be-more-ambitious-a-tutorial-for-humans-with-models"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;What does “be more ambitious with AI” mean in practice? A Claude team member turns the advice into four dimensions: speed, altitude, depth, and range. The focus is on the last three: aim at the outcome beyond the immediate task, use the raw data and professional methods experts would rely on, and bring in techniques from other fields.&lt;/p&gt;
&lt;p&gt;A quarterly business review becomes the running example, with prompts for finding urgent decisions, testing assumptions about customer churn, and designing a better way to catch problems than a deck. The piece also argues for outside validation rather than asking a model to grade its own work. Its practical message is sharp: don’t just ask a model to do more; give it a harder goal, better tools, and a way to prove the result.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://felixrieseberg.com/how-to-be-more-ambitious-a-tutorial-for-humans-with-models/&quot;&gt;Continue reading on &lt;strong&gt;felixrieseberg.com&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/best-practice&quot;&gt;#best-practice&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/ai&quot;&gt;#ai&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/how-the-claude-code-team-does-code-review</id>
    <title>🔗 How the Claude Code team does code review</title>
    <updated>2026-12-02T09:00:00Z</updated>
    <published>2026-12-02T09:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/how-the-claude-code-team-does-code-review"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;What happens when AI agents produce more code than people can read line by line? The Claude Code team shifted much of its review earlier and into automated checks, while reserving human attention for decisions that need judgment. From June to September, merged pull requests more than doubled, while the share that had to be reverted fell by over 40 percent.&lt;/p&gt;
&lt;p&gt;The process layers verification before a pull request, AI bug and security reviews, blocking tests, risk-based human approvals, a merge queue, and fast rollback. Findings are checked by other agents, and past incidents feed a daily evaluation of the reviewer. The goal is not to eliminate human review, but to reduce its cost without increasing reverts or incidents—a practical model for handling higher change volume without treating “a human read every line” as the only measure of safety.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://claude.dev/blog/solving-code-review-at-anthropic/&quot;&gt;Continue reading on &lt;strong&gt;claude.dev&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/development&quot;&gt;#development&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/best-practice&quot;&gt;#best-practice&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/ai&quot;&gt;#ai&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/testing&quot;&gt;#testing&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/what-a-good-ai-policy-looks-like</id>
    <title>🔗 What a Good “AI” Policy Looks Like</title>
    <updated>2026-12-01T18:00:00Z</updated>
    <published>2026-12-01T18:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/what-a-good-ai-policy-looks-like"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;What should an AI policy allow when the technology is already here? The comments point to a practical middle ground: distinguish AI-generated creative work from tools that support human work, and define the terms before setting rules. One commenter highlights the policy’s contract-like structure and careful treatment of scope; others see a template that could transfer to publishing, where tools such as Grammarly and ProWritingAid help polish an author’s work without creating it.&lt;/p&gt;
&lt;p&gt;The debate also exposes a hard boundary to draw. Mastering, mixing, and EQ are creative processes too, so calling a task “grunt work” can obscure whose expertise is being discounted. The policy’s value, as readers see it, lies in making those distinctions explicit rather than treating “AI” as one thing. An executive summary might help, but the detailed definitions give the policy a useful foundation.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://whatever.scalzi.com/2026/10/18/what-a-good-ai-policy-looks-like/&quot;&gt;Continue reading on &lt;strong&gt;whatever.scalzi.com&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/best-practice&quot;&gt;#best-practice&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/ai&quot;&gt;#ai&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/how-to-review-ai-code-without-reading-the-code</id>
    <title>🔗 How to review AI code without reading the code</title>
    <updated>2026-12-01T14:00:00Z</updated>
    <published>2026-12-01T14:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/how-to-review-ai-code-without-reading-the-code"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;The argument over whether engineers should stop reading code is over, because we already have.&lt;/p&gt;
&lt;p&gt;Faros AI’s new report shows a 76.3% increase in pull requests merged without review since their last report in April. Many companies now run AI reviews on 50% to 80% of their PRs. AI review took over bug-finding. But it didn’t take over the conversation where a team debates what it decided and why, and that is the part I missed too.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://thenewstack.io/review-decisions-not-code/&quot;&gt;Continue reading on &lt;strong&gt;thenewstack.io&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/development&quot;&gt;#development&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/ai&quot;&gt;#ai&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/from-tailwind-to-stylex</id>
    <title>🔗 From Tailwind to StyleX</title>
    <updated>2026-12-01T09:00:00Z</updated>
    <published>2026-12-01T09:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/from-tailwind-to-stylex"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;Can more explicit styling code make an LLM a better teammate? After converting a side project from Tailwind to StyleX, the author found that StyleX did not make styling faster by hand. Tailwind’s shorthand and sensible defaults still win for quick, manual work. But StyleX’s extra structure proved useful when coding agents were involved: design tokens are imported, variants and component overrides have named conventions, and styles use familiar CSS properties.&lt;/p&gt;
&lt;p&gt;Those choices give an LLM concrete patterns to find and reuse, while TypeScript and the compiler can catch some mistakes. They also make generated changes easier for the author to review, though StyleX does not stop an agent from ignoring tokens or producing bad styles. The takeaway is measured, not evangelistic: StyleX’s verbosity matters less when an LLM handles the typing, but the author is keeping it for this project—not planning to migrate existing Tailwind code or abandon Tailwind for fast, hands-on work.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://spatie.be/blog/from-tailwind-to-stylex&quot;&gt;Continue reading on &lt;strong&gt;spatie.be&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/typescript&quot;&gt;#typescript&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/frontend&quot;&gt;#frontend&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/css&quot;&gt;#css&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/ai&quot;&gt;#ai&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/auto-assign-new-issues-and-pull-requests-with-github-actions</id>
    <title>🐥 Auto-assign new issues and pull requests with GitHub Actions</title>
    <updated>2026-11-30T18:00:00Z</updated>
    <published>2026-11-30T18:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/auto-assign-new-issues-and-pull-requests-with-github-actions"/>
    <content type="html">&lt;p&gt;When you’re the only maintainer of a repository, every new issue and pull request is yours anyway. Still, I like having the assignee field filled in. It makes GitHub’s “assigned to me” filters useful and keeps things working if more people join later. Doing this by hand is the kind of chore I forget, so I automated it with a small GitHub Actions workflow.&lt;/p&gt;
&lt;h1&gt;The workflow&lt;/h1&gt;
&lt;p&gt;I used &lt;a href=&quot;https://github.com/gustavofreze/auto-assign&quot;&gt;&lt;code&gt;gustavofreze/auto-assign&lt;/code&gt;&lt;/a&gt;. It assigns the issue or pull request that triggered the workflow to the logins you specify. Create &lt;code&gt;.github/workflows/auto-assign.yml&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;lumis&quot;&gt;&lt;code class=&quot;language-yaml&quot; translate=&quot;no&quot; tabindex=&quot;0&quot;&gt;&lt;span class=&quot;l-line&quot; data-line=&quot;1&quot;&gt;&lt;span class=&quot;l-property&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;Auto assign&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;2&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;3&quot;&gt;&lt;span class=&quot;l-property&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;4&quot;&gt;  &lt;span class=&quot;l-property&quot;&gt;issues&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;5&quot;&gt;    &lt;span class=&quot;l-property&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;6&quot;&gt;      &lt;span class=&quot;l-punctuation-delimiter&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;opened&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;7&quot;&gt;  &lt;span class=&quot;l-property&quot;&gt;pull_request&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;8&quot;&gt;    &lt;span class=&quot;l-property&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;9&quot;&gt;      &lt;span class=&quot;l-punctuation-delimiter&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;opened&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;10&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;11&quot;&gt;&lt;span class=&quot;l-property&quot;&gt;jobs&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;12&quot;&gt;  &lt;span class=&quot;l-property&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;13&quot;&gt;    &lt;span class=&quot;l-property&quot;&gt;runs-on&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;ubuntu-latest&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;14&quot;&gt;    &lt;span class=&quot;l-property&quot;&gt;permissions&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;15&quot;&gt;      &lt;span class=&quot;l-property&quot;&gt;issues&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;write&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;16&quot;&gt;      &lt;span class=&quot;l-property&quot;&gt;pull-requests&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;write&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;17&quot;&gt;    &lt;span class=&quot;l-property&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;18&quot;&gt;      &lt;span class=&quot;l-punctuation-delimiter&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;l-property&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;Auto assigns assignees&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;19&quot;&gt;        &lt;span class=&quot;l-property&quot;&gt;uses&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;gustavofreze/auto-assign@3.0.0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;20&quot;&gt;        &lt;span class=&quot;l-property&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;21&quot;&gt;          &lt;span class=&quot;l-property&quot;&gt;assignees&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;#39;your-github-login&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;22&quot;&gt;          &lt;span class=&quot;l-property&quot;&gt;assignment_options&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;#39;ISSUE,PULL_REQUEST&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h1&gt;How it works&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Triggers:&lt;/strong&gt; The workflow runs when an issue or pull request is opened. For these events, the action only touches the item that triggered the run, and only if it has no assignee yet. A pull request event never assigns issues, and an issue event never assigns pull requests.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;assignment_options&lt;/code&gt;:&lt;/strong&gt; The default is &lt;code&gt;ISSUE&lt;/code&gt;. Set it to &lt;code&gt;ISSUE,PULL_REQUEST&lt;/code&gt; to cover both.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Permissions:&lt;/strong&gt; The job needs &lt;code&gt;issues: write&lt;/code&gt; and &lt;code&gt;pull-requests: write&lt;/code&gt;. The default workflow token is enough, so there’s no secret to create or rotate.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pinning:&lt;/strong&gt; I pinned the action to the &lt;code&gt;3.0.0&lt;/code&gt; tag. For stricter supply-chain hygiene, you can pin it to a commit SHA instead.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;Options worth knowing about&lt;/h1&gt;
&lt;p&gt;The action has a few inputs I didn’t need but you might:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&quot;left&quot;&gt;Input&lt;/th&gt;
&lt;th align=&quot;left&quot;&gt;Default&lt;/th&gt;
&lt;th align=&quot;left&quot;&gt;What it does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;&lt;code&gt;skip_bots&lt;/code&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Skips items opened by bots such as &lt;code&gt;dependabot[bot]&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;&lt;code&gt;skip_drafts&lt;/code&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Skips draft pull requests&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;&lt;code&gt;assign_author&lt;/code&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Also assigns the author of the item&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;&lt;code&gt;allow_no_assignees&lt;/code&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Lets the run succeed when nobody can be assigned&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h1&gt;Caveats&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Forks:&lt;/strong&gt; On the &lt;code&gt;pull_request&lt;/code&gt; event, pull requests from forks get a read-only token, so assignment will fail for them. That doesn’t matter for a personal repo. If you accept outside contributions, you would need &lt;code&gt;pull_request_target&lt;/code&gt;, which has its own security trade-offs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Default branch:&lt;/strong&gt; The &lt;code&gt;issues&lt;/code&gt; trigger only fires once the workflow file is on the default branch. The &lt;code&gt;pull_request&lt;/code&gt; trigger uses the workflow file from the pull request itself, so the PR that introduces the workflow is its first test.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It’s a 23-line file that removes one small manual step. I opened the pull request that adds it on a branch of its own so I could see whether it assigned itself.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/devops&quot;&gt;#devops&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/github&quot;&gt;#github&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/why-ddd-is-more-important-than-ever</id>
    <title>🔗 Why DDD Is More Important Than Ever</title>
    <updated>2026-11-30T14:00:00Z</updated>
    <published>2026-11-30T14:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/why-ddd-is-more-important-than-ever"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;The supplied text does not include an article about DDD. It contains three separate teasers: one on a team-owned software factory, one on AI fixing a goalkeeper bug from a short video, and one on hydrating React components inside Django pages. Without the DDD article’s text, its argument and supporting details cannot be summarized accurately. The page title points to a topic, but it does not establish what the article says, so filling in the gap would risk inventing claims. The available material also does not identify which teaser, if any, is meant to accompany that title.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://madewithlove.com/blog/why-ddd-is-more-important-than-ever/&quot;&gt;Continue reading on &lt;strong&gt;madewithlove.com&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/development&quot;&gt;#development&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/pattern&quot;&gt;#pattern&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/from-cinema-ticket-to-website-with-mcp</id>
    <title>🔗 From Cinema Ticket to Website with MCP</title>
    <updated>2026-11-30T09:00:00Z</updated>
    <published>2026-11-30T09:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/from-cinema-ticket-to-website-with-mcp"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;What if logging a night out took one photo instead of a trip through a clunky editor? Henrique Dias added an MCP server to Eagle, his Go-powered website, so Claude can read a cinema ticket and create a log entry. The server also supports searching and editing entries, with strict input rules intended to make unclear or incomplete ticket details fail rather than slip through.&lt;/p&gt;
&lt;p&gt;The build covers the practical work behind that convenience: wiring up the official Go MCP SDK, securing access with OAuth 2.1 and PKCE, and adapting IndieAuth to support Client ID Metadata Documents. Dias also describes a JSON Schema snag caused by Go’s nil slices, and why he chose to identify editable records by their current values instead of adding IDs. It’s a useful account of MCP as an API integration, where clear schemas and field descriptions matter as much as the model.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://hacdias.com/2026/10/17/mcp/&quot;&gt;Continue reading on &lt;strong&gt;hacdias.com&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/golang&quot;&gt;#golang&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/http&quot;&gt;#http&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/ai&quot;&gt;#ai&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/auth&quot;&gt;#auth&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/sort-git-branches-by-date</id>
    <title>🔗 Sort Git branches by date</title>
    <updated>2026-11-29T18:00:00Z</updated>
    <published>2026-11-29T18:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/sort-git-branches-by-date"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;Want &lt;code&gt;git branch&lt;/code&gt; to show the branches you touched most recently at the top? Rob Allen shares a one-line Git configuration that sorts branches by their last commit date: &lt;code&gt;git config --global branch.sort -committerdate&lt;/code&gt;. The leading minus sign puts the newest commit first, making the usual branch list more useful when a repository has accumulated branches over time.&lt;/p&gt;
&lt;p&gt;The change applies globally, so it affects &lt;code&gt;git branch&lt;/code&gt; across repositories. Allen also gives the reset command, &lt;code&gt;git config --global --unset branch.sort&lt;/code&gt;, for anyone who wants to restore Git’s default ordering. It is a small quality-of-life tweak, but one that can save a bit of hunting around when returning to older work.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://akrabat.com/sort-git-branches-by-date/&quot;&gt;Continue reading on &lt;strong&gt;akrabat.com&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/tools&quot;&gt;#tools&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/git&quot;&gt;#git&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/your-phoenix-app-has-two-trust-stores</id>
    <title>🔗 Your Phoenix App Has Two Trust Stores</title>
    <updated>2026-11-29T14:00:00Z</updated>
    <published>2026-11-29T14:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/your-phoenix-app-has-two-trust-stores"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;What if a successful deploy changed nothing? After eMudhra’s compromised certificate intermediates came to light, Charlie Forêt found that his Phoenix app relied on two separate TLS trust stores: Debian’s operating-system bundle for Req and Mint, and a bundle compiled into certifi for hackney. A routine rebuild had also reused a cached image layer, leaving the OS bundle stale. The result was that Stripe, S3, and web push remained exposed through hackney even after the apparent fix.&lt;/p&gt;
&lt;p&gt;Forêt traces the risks and the work needed to close them: force a fresh certificate-package install, remove suspect roots and verify the filtered bundle, replace hackney clients with Req where possible, and override hackney’s chain-validation behavior for Stripe. He also adds CI checks, boot-time alerts, and tests designed to catch regressions. The practical lesson is that changing one trust store—or merely deploying again—doesn’t secure every outbound TLS connection.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://charlieforet.com/blog/your-phoenix-app-has-two-trust-stores&quot;&gt;Continue reading on &lt;strong&gt;charlieforet.com&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/best-practice&quot;&gt;#best-practice&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/elixir&quot;&gt;#elixir&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/phoenix&quot;&gt;#phoenix&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/devops&quot;&gt;#devops&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/testing&quot;&gt;#testing&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/from-27-minutes-to-4-cutting-ci-build-time-by-85</id>
    <title>🔗 From 27 Minutes to 4: Cutting CI Build Time by 85%</title>
    <updated>2026-11-29T09:00:00Z</updated>
    <published>2026-11-29T09:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/from-27-minutes-to-4-cutting-ci-build-time-by-85"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;What’s worse than a slow CI run? A slow run that keeps repeating work it never needed to do. Alexis cut a Scala project’s pull-request builds from about 27 minutes to roughly 4 without dropping tests, replacing real Postgres or app integration tests with mocks, or adding infrastructure. The improvements came from measuring each suspected bottleneck on actual CI rather than guessing.&lt;/p&gt;
&lt;p&gt;The biggest gains came from sharing one Postgres container across the test suite, reusing a warm sbt server, and fixing ineffective caches. Smaller wins came from running tests in parallel on the four-core CI runner, limiting checks to changed paths, and reducing redundant setup. The post lays out the measured changes and their trade-offs, including why a remote build cache or splitting jobs wasn’t worthwhile yet. Its central lesson is refreshingly practical: inspect the slow steps, test one fix at a time, and optimize for the machine that actually runs your builds.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://alexitc.com/blog/2026-10-23-from-27-minutes-to-4-cutting-ci-build-time-by-85-percent/&quot;&gt;Continue reading on &lt;strong&gt;alexitc.com&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/development&quot;&gt;#development&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/database&quot;&gt;#database&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/devops&quot;&gt;#devops&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/testing&quot;&gt;#testing&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/building-a-safe-image-proxy-in-phoenix</id>
    <title>🐥 Building a Safe Image Proxy in Phoenix</title>
    <updated>2026-11-28T18:00:00Z</updated>
    <published>2026-11-28T18:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/building-a-safe-image-proxy-in-phoenix"/>
    <content type="html">&lt;p&gt;If you render content from other websites, you’ll eventually run into broken images. Some hosts refuse hotlinking, some check the &lt;code&gt;Referer&lt;/code&gt; header, and your own Content Security Policy may only allow images from a short list of origins. The result is the same: a page full of broken image icons.&lt;/p&gt;
&lt;p&gt;One fix is to stop showing images. Another is to serve them yourself through a small proxy. This post walks through the second option and, more importantly, the ways it can go wrong.&lt;/p&gt;
&lt;h1&gt;The idea&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;Rewrite every remote image URL in your content to point to your own server.&lt;/li&gt;
&lt;li&gt;When the browser requests it, fetch the original image server-side and stream it back.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Because the image now comes from your own origin, your CSP is happy. Because your server makes the request without a &lt;code&gt;Referer&lt;/code&gt;, most hotlink protection doesn’t trigger.&lt;/p&gt;
&lt;p&gt;The catch: you’ve just built a service that makes HTTP requests to URLs chosen by someone else. That is exactly the shape of an SSRF vulnerability, so most of the work is making it safe.&lt;/p&gt;
&lt;h1&gt;Step 1: sign the URLs&lt;/h1&gt;
&lt;p&gt;An unauthenticated &lt;code&gt;/proxy?url=...&lt;/code&gt; endpoint is an open proxy. Anyone can use it to hide their traffic, hammer a third party, or probe your internal network.&lt;/p&gt;
&lt;p&gt;Instead, only proxy URLs that your own code generated. Sign the source URL and put the signature in the path:&lt;/p&gt;
&lt;pre class=&quot;lumis&quot;&gt;&lt;code class=&quot;language-elixir&quot; translate=&quot;no&quot; tabindex=&quot;0&quot;&gt;&lt;span class=&quot;l-line&quot; data-line=&quot;1&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;do: &lt;/span&gt;&lt;span class=&quot;l-string&quot;&gt;&amp;quot;/proxy/image/&amp;quot;&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;sign&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;2&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;3&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;verify&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;token&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;do: &lt;/span&gt;&lt;span class=&quot;l-module&quot;&gt;Plug.Crypto.MessageVerifier&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;verify&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;token&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;secret&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;4&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;5&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;defp&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;sign&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;do: &lt;/span&gt;&lt;span class=&quot;l-module&quot;&gt;Plug.Crypto.MessageVerifier&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;sign&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;secret&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;6&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;7&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;defp&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;secret&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;8&quot;&gt;  &lt;span class=&quot;l-variable&quot;&gt;base&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;MyAppWeb.Endpoint&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:secret_key_base&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;9&quot;&gt;  &lt;span class=&quot;l-module&quot;&gt;Plug.Crypto.KeyGenerator&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;generate&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;image proxy&amp;quot;&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;10&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A few notes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;MessageVerifier&lt;/code&gt; is deterministic: the same URL always gives the same token. &lt;code&gt;Phoenix.Token&lt;/code&gt; includes a timestamp, which would make every render produce a different URL. That breaks HTTP caching and any cache of rendered HTML.&lt;/li&gt;
&lt;li&gt;Deriving the key with a dedicated salt keeps the proxy’s signatures separate from your other uses of the secret.&lt;/li&gt;
&lt;li&gt;Signing is not a complete defense. The URLs still originate from third-party pages, so the fetch itself has to be safe too.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;Step 2: rewrite the content&lt;/h1&gt;
&lt;p&gt;If your content is Markdown, a regular expression over the image syntax is enough for a first version:&lt;/p&gt;
&lt;pre class=&quot;lumis&quot;&gt;&lt;code class=&quot;language-elixir&quot; translate=&quot;no&quot; tabindex=&quot;0&quot;&gt;&lt;span class=&quot;l-line&quot; data-line=&quot;1&quot;&gt;&lt;span class=&quot;l-operator&quot;&gt;&lt;span class=&quot;l-constant&quot;&gt;@&lt;span class=&quot;l-function-call&quot;&gt;&lt;span class=&quot;l-constant&quot;&gt;image &lt;span class=&quot;l-string-special&quot;&gt;~r/&lt;/span&gt;!&lt;span class=&quot;l-string-escape&quot;&gt;\[&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;([&lt;/span&gt;^&lt;span class=&quot;l-string-escape&quot;&gt;\]&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;l-string-escape&quot;&gt;\]\(&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;https&lt;span class=&quot;l-operator&quot;&gt;?&lt;/span&gt;:&lt;span class=&quot;l-string-escape&quot;&gt;\/\/&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;[&lt;/span&gt;^&lt;span class=&quot;l-constant&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;l-string-escape&quot;&gt;\s&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)((?:&lt;/span&gt;&lt;span class=&quot;l-string-escape&quot;&gt;\s&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;+&lt;/span&gt;&amp;quot;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;[&lt;/span&gt;^&lt;span class=&quot;l-constant&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;*&lt;/span&gt;&amp;quot;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;l-string-escape&quot;&gt;\)&lt;/span&gt;&lt;span class=&quot;l-string-special&quot;&gt;/&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;2&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;3&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;rewrite_markdown&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;markdown&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;4&quot;&gt;  &lt;span class=&quot;l-module&quot;&gt;Regex&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;replace&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;&lt;span class=&quot;l-constant&quot;&gt;@&lt;span class=&quot;l-constant&quot;&gt;image&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;markdown&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;title&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;5&quot;&gt;    &lt;span class=&quot;l-string&quot;&gt;&amp;quot;![&lt;span class=&quot;l-string-special&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;l-string-special&quot;&gt;}&lt;/span&gt;](&lt;span class=&quot;l-string-special&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;l-string-special&quot;&gt;}#{&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;l-string-special&quot;&gt;}&lt;/span&gt;)&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;6&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;7&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Only absolute &lt;code&gt;http(s)&lt;/code&gt; sources are rewritten. Relative paths and &lt;code&gt;data:&lt;/code&gt; URIs stay untouched. The known limitation: an image example inside a code block gets rewritten too. If that matters, rewrite on the parsed AST instead.&lt;/p&gt;
&lt;h1&gt;Step 3: fetch defensively&lt;/h1&gt;
&lt;p&gt;This is the dangerous part. Everything below matters.&lt;/p&gt;
&lt;h2&gt;Block private addresses&lt;/h2&gt;
&lt;p&gt;Before connecting, resolve the host and refuse anything that isn’t a public address: loopback, private ranges, link-local (which includes cloud metadata endpoints), carrier-grade NAT, and multicast. Don’t forget IPv6, including IPv4-mapped addresses like &lt;code&gt;::ffff:127.0.0.1&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;lumis&quot;&gt;&lt;code class=&quot;language-elixir&quot; translate=&quot;no&quot; tabindex=&quot;0&quot;&gt;&lt;span class=&quot;l-line&quot; data-line=&quot;1&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;public_address?&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;})&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;2&quot;&gt;  &lt;span class=&quot;l-keyword-operator&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;l-keyword-operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;l-punctuation-bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;l-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;127&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;l-keyword-operator&quot;&gt;or&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;3&quot;&gt;         &lt;span class=&quot;l-variable&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;224&lt;/span&gt; &lt;span class=&quot;l-keyword-operator&quot;&gt;or&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;4&quot;&gt;         &lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;100&lt;/span&gt; &lt;span class=&quot;l-keyword-operator&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;l-keyword-operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;64&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;l-number&quot;&gt;127&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword-operator&quot;&gt;or&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;5&quot;&gt;         &lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;169&lt;/span&gt; &lt;span class=&quot;l-keyword-operator&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;254&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword-operator&quot;&gt;or&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;6&quot;&gt;         &lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;172&lt;/span&gt; &lt;span class=&quot;l-keyword-operator&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;l-keyword-operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;l-number&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword-operator&quot;&gt;or&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;7&quot;&gt;         &lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;192&lt;/span&gt; &lt;span class=&quot;l-keyword-operator&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;168&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;8&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;9&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;10&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;public_address?&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;l-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0xFFFF&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;hi&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;lo&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;})&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;11&quot;&gt;  &lt;span class=&quot;l-function-call&quot;&gt;public_address?&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;hi&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;rem&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;hi&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;lo&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;rem&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;lo&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;12&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;13&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;14&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;public_address?&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;l-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;})&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;do: &lt;/span&gt;&lt;span class=&quot;l-boolean&quot;&gt;false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;15&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;public_address?&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;})&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;first&lt;/span&gt; &lt;span class=&quot;l-keyword-operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0xFC00&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;l-number&quot;&gt;0xFDFF&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;do: &lt;/span&gt;&lt;span class=&quot;l-boolean&quot;&gt;false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;16&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;public_address?&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;})&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;first&lt;/span&gt; &lt;span class=&quot;l-keyword-operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0xFE80&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;l-number&quot;&gt;0xFEBF&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;do: &lt;/span&gt;&lt;span class=&quot;l-boolean&quot;&gt;false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;17&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;public_address?&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;})&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;first&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0xFF00&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;do: &lt;/span&gt;&lt;span class=&quot;l-boolean&quot;&gt;false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;18&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;public_address?&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;})&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;do: &lt;/span&gt;&lt;span class=&quot;l-boolean&quot;&gt;true&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Check &lt;em&gt;every&lt;/em&gt; address a hostname resolves to, not just the first.&lt;/p&gt;
&lt;h2&gt;Follow redirects yourself&lt;/h2&gt;
&lt;p&gt;If the HTTP client follows redirects automatically, an attacker can point a public URL at &lt;code&gt;http://169.254.169.254/...&lt;/code&gt;, and your check on the first host is useless. Turn automatic redirects off, follow them manually with a small limit, and run the full validation on every hop:&lt;/p&gt;
&lt;pre class=&quot;lumis&quot;&gt;&lt;code class=&quot;language-elixir&quot; translate=&quot;no&quot; tabindex=&quot;0&quot;&gt;&lt;span class=&quot;l-line&quot; data-line=&quot;1&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;defp&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-comment&quot;&gt;_src&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;hops_left&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;hops_left&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;do: &lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:error&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;:too_many_redirects&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;2&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;3&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;defp&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;hops_left&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;4&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:ok&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;5&quot;&gt;       &lt;span class=&quot;l-string-special-symbol&quot;&gt;:ok&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;ensure_public_host&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;6&quot;&gt;       &lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:ok&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;7&quot;&gt;    &lt;span class=&quot;l-function-call&quot;&gt;handle_response&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;hops_left&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;8&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;9&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Limit what you accept&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Timeouts.&lt;/strong&gt; A slow host shouldn’t tie up a worker. Use a short receive timeout and disable retries.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Size.&lt;/strong&gt; Stream the body and stop once it passes a limit (say 10 MB), rather than loading whatever the server sends into memory.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Content type.&lt;/strong&gt; Allow a short list of raster formats: PNG, JPEG, GIF, WebP, and AVIF. Leave SVG out. It can contain script, and serving it from your origin is an XSS risk.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With Req, the streaming limit looks like this. The accumulator lives on the response:&lt;/p&gt;
&lt;pre class=&quot;lumis&quot;&gt;&lt;code class=&quot;language-elixir&quot; translate=&quot;no&quot; tabindex=&quot;0&quot;&gt;&lt;span class=&quot;l-line&quot; data-line=&quot;1&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;defp&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;collect&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:data&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;})&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;2&quot;&gt;  &lt;span class=&quot;l-variable&quot;&gt;chunks&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;Req.Response&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;get_private&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;:chunks&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-punctuation-bracket&quot;&gt;[])&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;3&quot;&gt;  &lt;span class=&quot;l-variable&quot;&gt;size&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;Req.Response&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;get_private&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;:size&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;byte_size&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;4&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;5&quot;&gt;  &lt;span class=&quot;l-variable&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;=&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;6&quot;&gt;    &lt;span class=&quot;l-variable&quot;&gt;response&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;7&quot;&gt;    &lt;span class=&quot;l-operator&quot;&gt;|&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;Req.Response&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;put_private&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:chunks&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-punctuation-bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;chunks&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;])&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;8&quot;&gt;    &lt;span class=&quot;l-operator&quot;&gt;|&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;Req.Response&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;put_private&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:size&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;9&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;10&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;size&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;&lt;span class=&quot;l-constant&quot;&gt;@&lt;span class=&quot;l-constant&quot;&gt;max_bytes&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;11&quot;&gt;    &lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:halt&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;Req.Response&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;put_private&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;:too_large&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)}}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;12&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;else&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;13&quot;&gt;    &lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:cont&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;}}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;14&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;15&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Don’t send a referer&lt;/h2&gt;
&lt;p&gt;Simply don’t set one. Send a plain user agent and an &lt;code&gt;Accept: image/*&lt;/code&gt; header.&lt;/p&gt;
&lt;h1&gt;Step 4: serve it safely&lt;/h1&gt;
&lt;p&gt;The controller verifies the token, fetches the image, and responds. Even though you only allow raster images, add defense in depth:&lt;/p&gt;
&lt;pre class=&quot;lumis&quot;&gt;&lt;code class=&quot;language-elixir&quot; translate=&quot;no&quot; tabindex=&quot;0&quot;&gt;&lt;span class=&quot;l-line&quot; data-line=&quot;1&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-punctuation-special&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-string&quot;&gt;&amp;quot;token&amp;quot;&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;token&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;})&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;2&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:ok&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;ImageProxy&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;verify&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;token&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;3&quot;&gt;       &lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:ok&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;content_type&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;ImageProxy&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;4&quot;&gt;    &lt;span class=&quot;l-variable&quot;&gt;conn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;5&quot;&gt;    &lt;span class=&quot;l-operator&quot;&gt;|&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;put_resp_content_type&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;content_type&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-constant-builtin&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;6&quot;&gt;    &lt;span class=&quot;l-operator&quot;&gt;|&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;put_resp_header&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-string&quot;&gt;&amp;quot;cache-control&amp;quot;&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;public, max-age=604800, immutable&amp;quot;&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;7&quot;&gt;    &lt;span class=&quot;l-operator&quot;&gt;|&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;put_resp_header&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-string&quot;&gt;&amp;quot;content-security-policy&amp;quot;&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;default-src &amp;#39;none&amp;#39;; sandbox&amp;quot;&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;8&quot;&gt;    &lt;span class=&quot;l-operator&quot;&gt;|&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;put_resp_header&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-string&quot;&gt;&amp;quot;x-content-type-options&amp;quot;&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;nosniff&amp;quot;&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;9&quot;&gt;    &lt;span class=&quot;l-operator&quot;&gt;|&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;send_resp&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-number&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;10&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;else&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;11&quot;&gt;    &lt;span class=&quot;l-comment&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;send_resp&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;404&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;12&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;13&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Always return a plain 404 on failure. Don’t leak the reason to the client. Log it instead.&lt;/p&gt;
&lt;p&gt;Put the route in a scope with no browser pipeline. An image doesn’t need a session, CSRF protection, or HTML security headers.&lt;/p&gt;
&lt;h1&gt;Testing it&lt;/h1&gt;
&lt;p&gt;Req’s &lt;code&gt;plug&lt;/code&gt; option lets you stub the remote server without any network access:&lt;/p&gt;
&lt;pre class=&quot;lumis&quot;&gt;&lt;code class=&quot;language-elixir&quot; translate=&quot;no&quot; tabindex=&quot;0&quot;&gt;&lt;span class=&quot;l-line&quot; data-line=&quot;1&quot;&gt;&lt;span class=&quot;l-module&quot;&gt;Req.Test&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;stub&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-module&quot;&gt;ImageProxy&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;conn&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;2&quot;&gt;  &lt;span class=&quot;l-variable&quot;&gt;conn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;3&quot;&gt;  &lt;span class=&quot;l-operator&quot;&gt;|&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;Plug.Conn&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;put_resp_content_type&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-string&quot;&gt;&amp;quot;image/png&amp;quot;&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;4&quot;&gt;  &lt;span class=&quot;l-operator&quot;&gt;|&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;Plug.Conn&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;send_resp&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-number&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;png&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;5&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;6&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;7&quot;&gt;&lt;span class=&quot;l-function-call&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:ok&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;png&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;image/png&amp;quot;&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;ImageProxy&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-string&quot;&gt;&amp;quot;https://93.184.216.34/a.png&amp;quot;&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Using an IP literal in the test URL avoids a real DNS lookup. The tests worth writing:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the token round-trips, and a tampered or garbage token is rejected&lt;/li&gt;
&lt;li&gt;tokens are deterministic&lt;/li&gt;
&lt;li&gt;loopback, private, link-local, and IPv4-mapped IPv6 hosts are refused&lt;/li&gt;
&lt;li&gt;non-&lt;code&gt;http(s)&lt;/code&gt; schemes are refused&lt;/li&gt;
&lt;li&gt;SVG and other content types are refused&lt;/li&gt;
&lt;li&gt;an oversized body is refused&lt;/li&gt;
&lt;li&gt;a redirect to a private address is refused&lt;/li&gt;
&lt;li&gt;a redirect loop gives up&lt;/li&gt;
&lt;li&gt;no &lt;code&gt;Referer&lt;/code&gt; header is sent&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;Pitfalls I ran into&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Hidden middleware can block the route.&lt;/strong&gt; If you have a plug that blocks suspicious paths (many apps do, to deflect scanners), a path like &lt;code&gt;/proxy/...&lt;/code&gt; may be on its list. My tests got a friendly “not found” page with a 200 status until I allowlisted the route.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Where Req keeps streaming state.&lt;/strong&gt; With &lt;code&gt;into:&lt;/code&gt; as a function, the accumulator is &lt;code&gt;{request, response}&lt;/code&gt;, and the final response is built from the one you return. State stored on the request is gone by the time you get the result. Store it on the response.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sigils and parentheses.&lt;/strong&gt; &lt;code&gt;~s(...)&lt;/code&gt; breaks as soon as your test string contains parentheses. Use &lt;code&gt;~s|...|&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;What’s still missing&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;DNS rebinding.&lt;/strong&gt; The code resolves the host to validate it, then the HTTP client resolves it again to connect. A hostile DNS server could answer differently the second time. Closing that gap means connecting to the validated IP while still sending the right &lt;code&gt;Host&lt;/code&gt; header and TLS server name. Signed URLs shrink the exposure but don’t remove it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Server-side caching.&lt;/strong&gt; The &lt;code&gt;Cache-Control&lt;/code&gt; header lets browsers and CDNs cache, but your server will still refetch on a cold cache. A CDN in front is the cheapest fix. Storing the images yourself also keeps them alive after the source disappears.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cost.&lt;/strong&gt; You now pay for the bandwidth, and you’re re-serving other people’s images. Think about whether that’s acceptable for your use case.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;Should you do this at all?&lt;/h1&gt;
&lt;p&gt;Not always. If you don’t care about the images, stripping them is simpler, has no attack surface, and costs nothing to run. Before building a proxy, check &lt;em&gt;why&lt;/em&gt; the images are broken. If it’s your own CSP, the cheapest fix may be a configuration change. If it’s &lt;code&gt;Referer&lt;/code&gt;-based hotlink protection, a &lt;code&gt;no-referrer&lt;/code&gt; referrer policy on the images may be enough.&lt;/p&gt;
&lt;p&gt;The proxy earns its place when you want the images, the hosts really do block direct loading, and you’re willing to own the security and operations that come with fetching URLs on behalf of the internet.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/http&quot;&gt;#http&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/elixir&quot;&gt;#elixir&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/phoenix&quot;&gt;#phoenix&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/auth&quot;&gt;#auth&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/introducing-mishka-cms-how-we-built-a-runtime-cms-on-phoenix-liveview</id>
    <title>🔗 Introducing Mishka CMS: How We Built a Runtime CMS on Phoenix LiveView</title>
    <updated>2026-11-28T14:00:00Z</updated>
    <published>2026-11-28T14:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/introducing-mishka-cms-how-we-built-a-runtime-cms-on-phoenix-liveview"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;What if publishing a page never meant restarting the website? Mishka CMS is an open-source CMS built with Elixir, Phoenix LiveView, and Ash that serves many websites from one install. Its pages, layouts, and components live in the database and compile into LiveView modules at runtime, so changes can go live without a redeploy.&lt;/p&gt;
&lt;p&gt;The launch story traces the project from Mishka Chelekom and several earlier CMS attempts to its first release. It explains how pages are compiled and published, how multi-site data stays scoped, and how realtime updates reach both admins and visitors. One telling lesson: the first React-based editor was replaced with LiveView, adding 15,069 lines while removing 11,240. The post also covers performance fixes, including an optional SHA-256-checked module cache that cut cold-start compilation from 11–25 seconds to about 400 milliseconds.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://mishka.tools/blog/mishka-cms-0-0-1-realtime-runtime-cms-for-elixir-and-phoenix&quot;&gt;Continue reading on &lt;strong&gt;mishka.tools&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/development&quot;&gt;#development&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/database&quot;&gt;#database&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/elixir&quot;&gt;#elixir&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/phoenix&quot;&gt;#phoenix&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/announcement&quot;&gt;#announcement&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/if-your-team-is-happy-are-you-doing-a-good-job</id>
    <title>🔗 If your Team Is Happy, Are You Doing a Good Job?</title>
    <updated>2026-11-28T09:00:00Z</updated>
    <published>2026-11-28T09:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/if-your-team-is-happy-are-you-doing-a-good-job"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;Can a happy team still be underperforming? Charity Majors argues that psychological safety was meant to support excellence by enabling learning—not to guarantee that nobody feels uncomfortable. She traces how tech’s shift from celebrating “brilliant jerks” toward team effectiveness, including Google’s Project Aristotle and DORA, became blurred with the idea that a manager’s job is simply to keep people happy.&lt;/p&gt;
&lt;p&gt;Majors distinguishes kindness from avoiding hard calls: effective leaders care about people while also operating the business, setting expectations, and challenging their teams. Learning can feel vulnerable and uncomfortable, she says, but that is part of how it builds trust and improves performance. She also warns that workshops and meetings are not automatically useful; learning needs a clear rationale and evidence of results. The piece closes by asking whether workplace fairness should be judged by individual managers or by the systems shaping outcomes.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://charity.wtf/p/if-your-team-is-happy-are-you-doing&quot;&gt;Continue reading on &lt;strong&gt;charity.wtf&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/development&quot;&gt;#development&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/best-practice&quot;&gt;#best-practice&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/do-web-components-have-a-future-if-nobody-is-writing-them</id>
    <title>🔗 Do Web Components Have a Future if Nobody Is Writing Them?</title>
    <updated>2026-11-27T18:00:00Z</updated>
    <published>2026-11-27T18:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/do-web-components-have-a-future-if-nobody-is-writing-them"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;What happens to web components when AI agents write the code—and may not choose them at all? Nolan Lawson argues that agentic coding weakens their traditional pitch: reusable components mattered when people wrote code by hand, but agents can generate boilerplate or switch frameworks with little friction. Google’s Modern Web Guidance, he notes, rarely recommends custom elements for new products, instead treating them as a fit for narrower cases such as design systems, embedded widgets, and isolated interfaces.&lt;/p&gt;
&lt;p&gt;Lawson still sees a role for web components in micro-frontends and portable, self-contained tools such as his emoji picker. But he argues that their future depends on solving persistent problems in server-side rendering, stylesheet sharing, and accessibility—issues that affect users regardless of who writes the code. The sharper question is whether standards and browser teams can make web components useful enough that agents reach for them without being told.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://nolanlawson.com/2026/10/19/do-web-components-have-a-future-if-nobody-is-writing-them/&quot;&gt;Continue reading on &lt;strong&gt;nolanlawson.com&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/javascript&quot;&gt;#javascript&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/development&quot;&gt;#development&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/frontend&quot;&gt;#frontend&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/ai&quot;&gt;#ai&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/html&quot;&gt;#html&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/giving-a-codebase-a-memory</id>
    <title>🔗 Giving a Codebase a Memory</title>
    <updated>2026-11-27T14:00:00Z</updated>
    <published>2026-11-27T14:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/giving-a-codebase-a-memory"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;Documentation rots, and what your product does ends up in a few developers' heads. So I stopped writing docs and started extracting them: small, typed, linked notes pulled from the codebase, written for product, with every claim traced back to the line it came from.&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://madewithlove.com/blog/giving-a-codebase-a-memory/&quot;&gt;Continue reading on &lt;strong&gt;madewithlove.com&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/ai&quot;&gt;#ai&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/an-rv-on-a-bike</id>
    <title>🔗 An RV on a Bike</title>
    <updated>2026-11-27T09:00:00Z</updated>
    <published>2026-11-27T09:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/an-rv-on-a-bike"/>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;Could a cargo bike double as a tiny RV in the desert? Bryan Cockfield reports on [Attoparsec]'s Burning Man build, which started with a cargo bike and added an extended bed, a foam-and-tape sleeping enclosure, and rear trailer wheels to counterbalance the extra length. A reinforced chain and solar-powered refrigerator rounded out the setup. The improvised shelter kept out the sun and playa dust, and its roof stayed dry through a rainstorm—better results than the drivetrain managed.&lt;/p&gt;
&lt;p&gt;The customized drivetrain developed problems and was temporarily fixed by striking a wheel with a hammer. Attoparsec also left Burning Man early, so the trip was a limited test rather than proof of a road-ready mobile home. The project sits somewhere between practical cargo-bike engineering and the rough, resourceful camp builds common at the event. It also raises the obvious question: How far can a bicycle-based shelter go when the route, weather, and vehicle infrastructure are less forgiving?&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://hackaday.com/2026/10/19/an-rv-on-a-bike/&quot;&gt;Continue reading on &lt;strong&gt;hackaday.com&lt;/strong&gt;&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/reading-list&quot;&gt;#reading-list&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/sports&quot;&gt;#sports&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://www.yellowduck.be/posts/a-tiny-self-invalidating-cache-in-elixir-with-ets</id>
    <title>🐥 A tiny, self-invalidating cache in Elixir with ETS</title>
    <updated>2026-11-26T18:00:00Z</updated>
    <published>2026-11-26T18:00:00Z</published>
    <author><name>Pieter Claerhout</name><email>pieter@yellowduck.be</email></author>
    <link rel="alternate" href="https://www.yellowduck.be/posts/a-tiny-self-invalidating-cache-in-elixir-with-ets"/>
    <content type="html">&lt;p&gt;Sometimes you have a pure function that is expensive to run and gets called with the same input again and again. Rendering Markdown with syntax highlighting is a good example: it’s CPU-heavy, the output depends only on the input, and the same document is requested over and over.&lt;/p&gt;
&lt;p&gt;You could reach for a caching library, and often that’s the right call. But for a small, well-bounded case, a plain ETS table gets you surprisingly far in about 70 lines. Here’s the technique and the traps to avoid.&lt;/p&gt;
&lt;h1&gt;The shape of the solution&lt;/h1&gt;
&lt;p&gt;Three ideas, each small:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;A GenServer that only owns the table.&lt;/strong&gt; It does no work on the hot path.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A public ETS table&lt;/strong&gt;, so callers read and write directly, without going through a single process.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A cache key that includes everything the output depends on&lt;/strong&gt;, so you never need to invalidate by hand.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;1. The GenServer is just a table owner&lt;/h2&gt;
&lt;p&gt;An ETS table lives as long as the process that created it. Put that process in your supervision tree, and the table follows the lifecycle of your app.&lt;/p&gt;
&lt;p&gt;The common mistake is to route every read through the GenServer. That turns a concurrent data structure into a bottleneck: one process handling one message at a time. Instead, make the table &lt;code&gt;:public&lt;/code&gt; and let callers talk to ETS directly:&lt;/p&gt;
&lt;pre class=&quot;lumis&quot;&gt;&lt;code class=&quot;language-elixir&quot; translate=&quot;no&quot; tabindex=&quot;0&quot;&gt;&lt;span class=&quot;l-line&quot; data-line=&quot;1&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;defmodule&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;MyApp.Renderer.Cache&lt;/span&gt; &lt;span class=&quot;l-keyword-function&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;2&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;GenServer&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;3&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;4&quot;&gt;  &lt;span class=&quot;l-operator&quot;&gt;&lt;span class=&quot;l-constant&quot;&gt;@&lt;span class=&quot;l-function-call&quot;&gt;&lt;span class=&quot;l-constant&quot;&gt;table &lt;span class=&quot;l-constant-builtin&quot;&gt;__MODULE__&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;5&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;6&quot;&gt;  &lt;span class=&quot;l-keyword-function&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;start_link&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;opts&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;\\&lt;/span&gt; &lt;span class=&quot;l-punctuation-bracket&quot;&gt;[])&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;7&quot;&gt;    &lt;span class=&quot;l-string-special-symbol&quot;&gt;do: &lt;/span&gt;&lt;span class=&quot;l-module&quot;&gt;GenServer&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;start_link&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-constant-builtin&quot;&gt;__MODULE__&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;opts&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;name: &lt;/span&gt;&lt;span class=&quot;l-constant-builtin&quot;&gt;__MODULE__&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;8&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;9&quot;&gt;  &lt;span class=&quot;l-operator&quot;&gt;&lt;span class=&quot;l-constant&quot;&gt;@&lt;span class=&quot;l-function-call&quot;&gt;&lt;span class=&quot;l-constant&quot;&gt;impl &lt;span class=&quot;l-boolean&quot;&gt;true&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;10&quot;&gt;  &lt;span class=&quot;l-keyword-function&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-comment&quot;&gt;_opts&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;11&quot;&gt;    &lt;span class=&quot;l-type&quot;&gt;:ets&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;&lt;span class=&quot;l-constant&quot;&gt;@&lt;span class=&quot;l-constant&quot;&gt;table&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-punctuation-bracket&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;12&quot;&gt;      &lt;span class=&quot;l-string-special-symbol&quot;&gt;:set&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;13&quot;&gt;      &lt;span class=&quot;l-string-special-symbol&quot;&gt;:public&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;14&quot;&gt;      &lt;span class=&quot;l-string-special-symbol&quot;&gt;:named_table&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;15&quot;&gt;      &lt;span class=&quot;l-string-special-symbol&quot;&gt;read_concurrency: &lt;/span&gt;&lt;span class=&quot;l-boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;16&quot;&gt;      &lt;span class=&quot;l-string-special-symbol&quot;&gt;write_concurrency: &lt;/span&gt;&lt;span class=&quot;l-boolean&quot;&gt;true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;17&quot;&gt;    &lt;span class=&quot;l-punctuation-bracket&quot;&gt;])&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;18&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;19&quot;&gt;    &lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:ok&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-constant-builtin&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;20&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;21&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;read_concurrency: true&lt;/code&gt; optimizes for many simultaneous readers, which is exactly the access pattern of a cache. The GenServer has no &lt;code&gt;handle_call&lt;/code&gt; at all; its only job is to keep the table alive.&lt;/p&gt;
&lt;h2&gt;2. A &lt;code&gt;fetch/3&lt;/code&gt; that computes on a miss&lt;/h2&gt;
&lt;p&gt;The public API is a single function: give it an input, a version, and a function that produces the value on a miss.&lt;/p&gt;
&lt;pre class=&quot;lumis&quot;&gt;&lt;code class=&quot;language-elixir&quot; translate=&quot;no&quot; tabindex=&quot;0&quot;&gt;&lt;span class=&quot;l-line&quot; data-line=&quot;1&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;fun&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;is_binary&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword-operator&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;is_function&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;fun&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;2&quot;&gt;  &lt;span class=&quot;l-variable&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-type&quot;&gt;:crypto&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;hash&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:sha256&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;3&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;4&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;lookup&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;5&quot;&gt;    &lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:ok&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;6&quot;&gt;      &lt;span class=&quot;l-variable&quot;&gt;value&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;7&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;8&quot;&gt;    &lt;span class=&quot;l-string-special-symbol&quot;&gt;:error&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;9&quot;&gt;      &lt;span class=&quot;l-variable&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;fun&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;10&quot;&gt;      &lt;span class=&quot;l-function-call&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;11&quot;&gt;      &lt;span class=&quot;l-variable&quot;&gt;value&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;12&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;13&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;14&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;15&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;defp&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;lookup&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;16&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;l-type&quot;&gt;:ets&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;lookup&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;&lt;span class=&quot;l-constant&quot;&gt;@&lt;span class=&quot;l-constant&quot;&gt;table&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;17&quot;&gt;    &lt;span class=&quot;l-punctuation-bracket&quot;&gt;[{&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;}]&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:ok&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;18&quot;&gt;    &lt;span class=&quot;l-punctuation-bracket&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;:error&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;19&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;20&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;rescue&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;21&quot;&gt;  &lt;span class=&quot;l-module&quot;&gt;ArgumentError&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;:error&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;22&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;rescue ArgumentError&lt;/code&gt; is deliberate. If the table does not exist (the cache process is down or restarting), &lt;code&gt;:ets.lookup/2&lt;/code&gt; raises. Treating that as a miss means the cache can fail without taking the feature down: you just fall back to computing the value. A cache should never be a hard dependency.&lt;/p&gt;
&lt;p&gt;Calling it looks like this:&lt;/p&gt;
&lt;pre class=&quot;lumis&quot;&gt;&lt;code class=&quot;language-elixir&quot; translate=&quot;no&quot; tabindex=&quot;0&quot;&gt;&lt;span class=&quot;l-line&quot; data-line=&quot;1&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;render_article&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;markdown&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;2&quot;&gt;  &lt;span class=&quot;l-module&quot;&gt;Cache&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;markdown&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;renderer_version&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;3&quot;&gt;    &lt;span class=&quot;l-variable&quot;&gt;markdown&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;4&quot;&gt;    &lt;span class=&quot;l-operator&quot;&gt;|&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;sanitize&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;5&quot;&gt;    &lt;span class=&quot;l-operator&quot;&gt;|&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;convert_to_html&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;6&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;7&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;3. Put the version in the key&lt;/h2&gt;
&lt;p&gt;This is the part that removes the hardest problem in caching.&lt;/p&gt;
&lt;p&gt;The key is &lt;code&gt;{version, sha256(input)}&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The hash&lt;/strong&gt; means identical input hits the same entry, and the key stays small no matter how large the document is.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The version&lt;/strong&gt; captures everything else the output depends on. Here, it’s a fingerprint built from the versions of the libraries doing the work:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;lumis&quot;&gt;&lt;code class=&quot;language-elixir&quot; translate=&quot;no&quot; tabindex=&quot;0&quot;&gt;&lt;span class=&quot;l-line&quot; data-line=&quot;1&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;renderer_version&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;2&quot;&gt;  &lt;span class=&quot;l-string&quot;&gt;&amp;quot;mdex-&lt;span class=&quot;l-string-special&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;app_version&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:mdex&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;l-string-special&quot;&gt;}&lt;/span&gt;+lumis-&lt;span class=&quot;l-string-special&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;app_version&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:lumis&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;l-string-special&quot;&gt;}&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;3&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;4&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;5&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;defp&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;app_version&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;6&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;Application&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;:vsn&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;7&quot;&gt;    &lt;span class=&quot;l-variable&quot;&gt;vsn&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;l-function-call&quot;&gt;is_list&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;vsn&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;to_string&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;vsn&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;8&quot;&gt;    &lt;span class=&quot;l-constant-builtin&quot;&gt;nil&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;unknown&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;9&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;10&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When you upgrade a dependency, the version string changes, every old key becomes unreachable, and new requests render fresh output. No flush on deploy, no “did we remember to clear the cache?” step. If you change your own rendering logic in a way the dependencies cannot detect, add a manual &lt;code&gt;@version &amp;quot;2&amp;quot;&lt;/code&gt; to the fingerprint and bump it.&lt;/p&gt;
&lt;p&gt;Stale entries are never served; they just sit there until the table is trimmed.&lt;/p&gt;
&lt;h1&gt;Keeping it bounded&lt;/h1&gt;
&lt;p&gt;A cache without a limit is a memory leak with good intentions. The simplest bound that works:&lt;/p&gt;
&lt;pre class=&quot;lumis&quot;&gt;&lt;code class=&quot;language-elixir&quot; translate=&quot;no&quot; tabindex=&quot;0&quot;&gt;&lt;span class=&quot;l-line&quot; data-line=&quot;1&quot;&gt;&lt;span class=&quot;l-operator&quot;&gt;&lt;span class=&quot;l-constant&quot;&gt;@&lt;span class=&quot;l-function-call&quot;&gt;&lt;span class=&quot;l-constant&quot;&gt;max_entries &lt;span class=&quot;l-number&quot;&gt;500&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;2&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;3&quot;&gt;&lt;span class=&quot;l-keyword-function&quot;&gt;defp&lt;/span&gt; &lt;span class=&quot;l-function&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;4&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;l-type&quot;&gt;:ets&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;&lt;span class=&quot;l-constant&quot;&gt;@&lt;span class=&quot;l-constant&quot;&gt;table&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;:size&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;&lt;span class=&quot;l-constant&quot;&gt;@&lt;span class=&quot;l-constant&quot;&gt;max_entries&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;5&quot;&gt;    &lt;span class=&quot;l-string-special-symbol&quot;&gt;do: &lt;/span&gt;&lt;span class=&quot;l-type&quot;&gt;:ets&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;delete_all_objects&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;&lt;span class=&quot;l-constant&quot;&gt;@&lt;span class=&quot;l-constant&quot;&gt;table&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;6&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;7&quot;&gt;  &lt;span class=&quot;l-type&quot;&gt;:ets&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;&lt;span class=&quot;l-constant&quot;&gt;@&lt;span class=&quot;l-constant&quot;&gt;table&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;8&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;rescue&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;9&quot;&gt;  &lt;span class=&quot;l-module&quot;&gt;ArgumentError&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-string-special-symbol&quot;&gt;:ok&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;10&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When the table is full, throw everything away. It’s crude, and I wouldn’t call it a good eviction policy. But it’s bounded, it’s one line, and the worst case is that some entries get recomputed. For a cache whose misses are merely slow rather than dangerous, that’s a fair trade.&lt;/p&gt;
&lt;h1&gt;What this does not give you&lt;/h1&gt;
&lt;p&gt;Be honest about the limits. This approach is a good fit for small caches and a poor one when you need any of the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Real eviction.&lt;/strong&gt; Flushing everything at the limit means a busy moment can empty a warm cache. If you care about keeping the hottest entries, you want LRU or something similar.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;TTLs.&lt;/strong&gt; Entries live until the next flush. That’s fine when the key already encodes everything that matters, but wrong for data that goes stale with time.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Stampede protection.&lt;/strong&gt; If ten requests miss the same key at once, all ten compute the value. For expensive work under bursty traffic, you want single-flight behavior, where one caller computes and the rest wait.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sharing across nodes.&lt;/strong&gt; The table is local to one node. Each node warms its own copy.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you need those features, a library such as Cachex provides them. The migration is small precisely because the call site is a single &lt;code&gt;fetch&lt;/code&gt;. Start simple, and swap the implementation when a real limitation shows up.&lt;/p&gt;
&lt;h1&gt;Testing it&lt;/h1&gt;
&lt;p&gt;Because the interesting behavior is “computed once per key and version,” the tests are short. Count how many times the function runs:&lt;/p&gt;
&lt;pre class=&quot;lumis&quot;&gt;&lt;code class=&quot;language-elixir&quot; translate=&quot;no&quot; tabindex=&quot;0&quot;&gt;&lt;span class=&quot;l-line&quot; data-line=&quot;1&quot;&gt;&lt;span class=&quot;l-function-call&quot;&gt;test&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;computes the value only once per input and version&amp;quot;&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;2&quot;&gt;  &lt;span class=&quot;l-variable&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;once &lt;span class=&quot;l-string-special&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;l-module&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;unique_integer&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:positive&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;])&lt;/span&gt;&lt;span class=&quot;l-string-special&quot;&gt;}&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;3&quot;&gt;  &lt;span class=&quot;l-punctuation-bracket&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:ok&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;calls&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;Agent&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;start_link&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-keyword&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;4&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;5&quot;&gt;  &lt;span class=&quot;l-variable&quot;&gt;compute&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;6&quot;&gt;    &lt;span class=&quot;l-module&quot;&gt;Agent&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;update&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;calls&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;&amp;amp;1&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;7&quot;&gt;    &lt;span class=&quot;l-string&quot;&gt;&amp;quot;html&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;8&quot;&gt;  &lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;9&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;10&quot;&gt;  &lt;span class=&quot;l-function-call&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;Cache&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;v1&amp;quot;&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;compute&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;html&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;11&quot;&gt;  &lt;span class=&quot;l-function-call&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;Cache&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;v1&amp;quot;&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-variable&quot;&gt;compute&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;html&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;12&quot;&gt;  &lt;span class=&quot;l-function-call&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;Agent&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;calls&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;&amp;amp;1&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;l-number&quot;&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;13&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;14&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;15&quot;&gt;&lt;span class=&quot;l-function-call&quot;&gt;test&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;does not share entries between versions&amp;quot;&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;16&quot;&gt;  &lt;span class=&quot;l-variable&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;versioned &lt;span class=&quot;l-string-special&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;l-module&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;unique_integer&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;l-string-special-symbol&quot;&gt;:positive&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;])&lt;/span&gt;&lt;span class=&quot;l-string-special&quot;&gt;}&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;17&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;18&quot;&gt;  &lt;span class=&quot;l-function-call&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;Cache&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;v1&amp;quot;&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;old&amp;quot;&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;old&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;19&quot;&gt;  &lt;span class=&quot;l-function-call&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;Cache&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;v2&amp;quot;&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;new&amp;quot;&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;new&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;20&quot;&gt;  &lt;span class=&quot;l-function-call&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;l-module&quot;&gt;Cache&lt;/span&gt;&lt;span class=&quot;l-operator&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;l-function-call&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;l-variable&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;v1&amp;quot;&lt;/span&gt;&lt;span class=&quot;l-punctuation-delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;unused&amp;quot;&lt;/span&gt; &lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;l-punctuation-bracket&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;l-operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;l-string&quot;&gt;&amp;quot;old&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;l-line&quot; data-line=&quot;21&quot;&gt;&lt;span class=&quot;l-keyword&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note the &lt;code&gt;System.unique_integer/1&lt;/code&gt; in the input. The table is global, so tests that run concurrently must use distinct keys or they’ll interfere with each other.&lt;/p&gt;
&lt;h1&gt;Takeaways&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Use a GenServer to &lt;strong&gt;own&lt;/strong&gt; an ETS table, not to &lt;strong&gt;serve&lt;/strong&gt; it.&lt;/li&gt;
&lt;li&gt;Make the table public with &lt;code&gt;read_concurrency: true&lt;/code&gt; and let callers hit ETS directly.&lt;/li&gt;
&lt;li&gt;Put everything the output depends on into the &lt;strong&gt;key&lt;/strong&gt;, and you can skip invalidation entirely.&lt;/li&gt;
&lt;li&gt;Treat a missing table as a cache miss, so the cache can never take the feature down.&lt;/li&gt;
&lt;li&gt;Always bound the size, even if the policy is blunt.&lt;/li&gt;
&lt;li&gt;Know where this stops being enough, and have a plan for what you would swap in.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It’s not a replacement for a full caching library. It’s a good way to avoid pulling one in until you actually need it.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.yellowduck.be/tags/development&quot;&gt;#development&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/database&quot;&gt;#database&lt;/a&gt; &lt;a href=&quot;https://www.yellowduck.be/tags/elixir&quot;&gt;#elixir&lt;/a&gt;&lt;/p&gt;</content>
  </entry>
</feed>
