Laravel Go: a third Laravel, one day after Laravel Rust

On December 2 the Laravel team released the first beta of Laravel Go, a full-stack web framework for Go. It came one day after Laravel Rust, so there are now three Laravels: PHP, Rust and Go. If you run a PHP project, this changes nothing for you today.

I haven't tried it yet. This article is based on the official announcement, the documentation, and an independent developer's first measurements.

The short version

  1. Your PHP app needs no changes. Keep updating it as before.
  2. Laravel Go is a 0.x beta. The documentation warns that releases before 1.0 may include breaking changes, so an upgrade can mean changing your code or configuration.
  3. If you want to try one of the two new versions, the difference is roughly this: the Go version builds much faster, while the Rust compiler catches more mistakes.
  4. Before you rewrite anything for speed, profile your app to see whether PHP really is the bottleneck.

What is Laravel Go?

It is built directly on Go's standard net/http package and goroutines, with no third-party web framework underneath. Your application is an ordinary http.Handler, so other Go libraries that work with net/http can be plugged in. According to the announcement it includes:

  • routing, middleware, validation, sessions and authentication;
  • models with typed query builders, a schema builder and migrations (PostgreSQL, MySQL, MariaDB, SQLite; PostgreSQL by default);
  • queues (database, Redis, Amazon SQS, Laravel Cloud), durable workflows, mail, broadcasting and a WebSocket server compatible with Reverb;
  • Inertia with React, Vue or Svelte, or server-rendered templates;
  • OpenTelemetry tracing and testing helpers that run with go test.

Taylor Otwell writes that it doesn't copy the syntax of the PHP or the Rust version: the goal was to offer the same features in idiomatic Go. A struct with json tags describes incoming form and JSON data, and its Rules method defines the validation rules. A queued job is a struct with a Handle(ctx context.Context) error method.

It is open source under the MIT license and needs Go 1.27 or later. The framework itself is the go.laravel.com module (v0.1.1 at the time of writing), and new apps start from the laravel/go template.

Why Go as well?

In his letter to the community on December 1, Taylor Otwell wrote that for Laravel "today, that means PHP and Rust". Go followed the next day.

The reasoning is the same as for Rust. Both are fast, type-safe, compiled languages, and Laravel expects coding agents to write more and more of the code. Every new app ships with instructions and skills for agents. According to Otwell, the Rust version has a bit more "magic" (macros, terser syntax) and slightly higher top-end speed, but in practice the two are similarly fast, while Go compiles much faster and uses much less disk space.

Go or Rust?

Laravel says Laravel Go is an order of magnitude faster than Laravel PHP, but it hasn't published a benchmark for Laravel Go. The benchmark from December 1 does include a Go app, but it is built on Beego, a different Go framework. Its numbers say nothing about Laravel Go.

Flavio Copes built the same app in both (Laravel Go 0.1.0, Laravel Rust 0.1.3). The release build took 1.53 seconds in Go with default settings (0.97 seconds with debug information stripped) and 54.98 seconds in Rust. He also load-tested an API endpoint backed by SQLite on his own machine (2,000 requests, 32 workers, three queries per request): Go served 7,631 requests per second and Rust 6,019. That's one machine, so expect different results under real production load.

The more important difference is when mistakes show up. If you mistype a column or relationship name in a Laravel Go query, it panics when that code runs. A test that exercises the code will catch it; otherwise the first live request that reaches it will. Laravel Rust's models have their column names and relationships checked by the compiler. The Go compiler does catch some typos too (field names in validation structs, for example), but for queries your tests carry more of the weight.

If your team already writes Go, or a long build would slow down your CI and deploys, I'd start with Go. If you'd rather have the compiler catch as much as possible, Rust is the better fit. For a PHP team that wants neither, nothing in these announcements is a reason to switch.

What to watch for

These come from the documentation. They are the spots where Laravel PHP habits won't carry over:

  • No lazy loading. Reading a relationship field never runs a query in the background. Load relations up front with With, the way you would to avoid N+1 queries in Eloquent.
  • Build the frontend separately. The app compiles to a single executable, and migrations are compiled into it too, so the server can run migrate without the source code. The frontend still has to be built with npm run build, and if you use Inertia server-side rendering, a Node.js process (node bootstrap/ssr/app.js) runs next to the app.
  • The module is always called app, whatever you name the project, so imports look like app/models.
  • Changing the database is a code change. For SQLite or MySQL, swap postgres.Driver for the other driver in bootstrap/app.go, change the import (go.laravel.com/db/sqlite or go.laravel.com/db/mysql), run go mod tidy and set DATABASE_URL in .env.

How do you try it?

According to the installation guide, you need Go 1.27 or later, the Node.js LTS release and Git. The command-line tool is the same one Laravel Rust uses. If you installed it for Rust, run the installer again to get a version that supports --go (Copes used 0.4.0). On macOS or Linux:

bash
curl -fsSL https://laravel.com/install.sh | sh

This runs a downloaded script. To inspect it first, download it with curl -fsSL https://laravel.com/install.sh -o install.sh, read it, then run sh install.sh. In a new terminal, laravel --version should print a line starting with Laravel CLI. If it prints another installer's version, Laravel Herd or the older Composer-based installer is ahead of ~/.laravel/bin on your PATH. I described the fix in the Laravel Rust article.

bash
laravel new example-app --go
cd example-app

Without --go, the installer asks which language you want. The app expects a local PostgreSQL server and a database named laravel (DATABASE_URL=postgres://[email protected]/laravel in .env). If the database doesn't exist yet, migrate offers to create it. For that to work, the database user in DATABASE_URL needs permission to create databases.

bash
laravel migrate
laravel dev

laravel dev starts the app, a queue worker and Vite Plus together, and the app is at http://127.0.0.1:8000. For production, stop laravel dev, set APP_ENV=production and APP_DEBUG=false in .env, and build it like this:

bash
npm run build
go build -o app .
./app

If you use Inertia server-side rendering, build with npm run build:ssr instead, set INERTIA_SSR=true, and run node bootstrap/ssr/app.js next to ./app. Point your load balancer's health check at /up. I took these commands from the documentation and haven't run them myself.

What happens to Laravel PHP?

Taylor Otwell's letter is clear: Laravel PHP "is not going anywhere, and it is not entering maintenance mode", and weekly releases continue. I found no tool that converts a PHP app to Go. Any PHP backend code you move has to be rewritten, and you'll need replacements for the PHP packages you use, such as Filament, Livewire, Cashier or packages from Spatie. If you have a React, Vue or Svelte frontend on Inertia, check separately how much of it carries over.

Laravel hasn't announced a release date for Laravel Go 1.0. Until then, read what changed before every upgrade.

Need a hand?

If your Laravel app is slow, I can help you measure where requests get stuck and decide whether it needs Go, Rust or just a new database index. Get in touch.


Sources

All articles →