Skip to content
AXVI BUILD · WRITE · SHIP
Blog

Loco for Laravel Developers 1.1: the Blog Moves to Loco 1.3

Loco 1.3 brought sessions, job retries, notifications and a database cache, the things a Laravel developer reaches for on day one. Version 1.1 of the book rebuilds the whole blog on it. Free for everyone who already has the book.

Loco for Laravel Developers 1.1: the Blog Moves to Loco 1.3

Less than two weeks ago I published Loco for Laravel Developers, a book that builds a complete blog in Rust with the Loco framework, one step at a time, comparing every step with the Laravel way. It was written on Loco 1.2. Loco 1.3 came out while I was finishing it, and the book said so in the introduction: every step was rebuilt on 1.3.1, it compiles, the tests pass.

That was true, and it wasn't enough. Then a reader asked a question under one of my posts: how do retries and failed jobs in Loco compare with Laravel's defaults? The honest answer was "Loco 1.3 has retries with backoff, and the book doesn't mention them". So I went through the 1.3 changelog line by line, and it turned out the release added exactly the things a Laravel developer reaches for on day one.

Version 1.1 of the book moves the whole blog to Loco 1.3.1.

What changed in the blog

  • Login with sessions. In 1.0 the browser kept a JWT in an httpOnly cookie, behind about 160 lines of my own extractor. Now it's Loco's own sessions, stored in the database, with "Remember me". Logout really ends the session on the server: a copy of the old cookie no longer works. That's Laravel's web guard, while the JSON API keeps its JWT, like the api guard.
  • Flash messages in the session, Laravel's session()->flash(), instead of a one-time cookie.
  • Storage configured in YAML, like config/filesystems.php, with the in-memory driver for tests as Storage::fake().
  • Retries and unique jobs. The post-processing worker now has $tries and $backoff (max_retries and retry_backoff in Loco), and three saves in a row queue one job, like ShouldBeUnique.
  • Notifications instead of a mailer. Every subscriber's email is its own background job with its own retries. I stopped the mail server on purpose and watched the retries come 10, 20 and 40 seconds apart.
  • A cache in the database, shared by the web server, the worker and the scheduler. In 1.0 the cache lived in each process's memory, and a post re-rendered by the worker stayed stale on the site for up to a minute.
  • A Postgres queue that cleans up after itself: a reaper for jobs whose worker died, and retention for finished jobs.

Measured again

Every command output, build time and load test was recorded again on 1.3.1, on the same two cores:

Book 1.0 (Loco 1.2) Book 1.1 (Loco 1.3)
First build of a new app 3 min 16 s, 600+ crates 2 min 11 s, 340 crates
Release build 8 min 35 s 5 min 40 s
Release binary 43.6 MB 34.2 MB

And an honest number for the cache. With the cache in process memory, the home page goes from about 1,500 to about 20,500 requests per second. With the cache in the database, which the blog uses because it's correct across processes, it's about 5,900. The chapter shows all of these side by side and explains why the blog takes the slower one.

What else came out of it

Testing every claim on the new version found a few things worth writing about: a notification template that fails to render without a single error, a template tag inside a YAML comment that stopped my production stack from starting, and a controller generator bug that is still there in 1.3.1. I reported that one to the Loco developers along with a fix.

Getting the update

If you already have the book, version 1.1 is in your Leanpub library at no cost, in PDF and EPUB. The companion code is in axvilab/loco-for-laravel-devs: the step-01-new … step-13-deploy tags now point to the Loco 1.3 code, and the 1.0 code is kept under v1.0-step-*.

If you don't have it yet, there's a free sample with the first steps of the blog, and the full book is on Leanpub.

Esc