← Writing

Why every new feature I write is in Go.

One rule for a codebase in the middle of a migration: nothing new goes into Laravel. Where each kind of feature lives now, and what the rule costs.

Sakshyam Baral··5 min readgolaayoinfra

Laayo's backend is partway through a move from Laravel to Go. The case study covers how the migration works: per-route switches, shadow comparison, write diffs. This post is about a smaller decision that made the migration finishable. Every new feature I write is in Go, and any screens it needs are in Next.js. Nothing new goes into PHP.

A migration that runs next to normal feature work has a built-in problem. Every new Laravel controller, job or Blade view is one more item on the list to port later. If I keep shipping features in the old stack, the list grows about as fast as I shrink it, and the end date keeps moving. With the rule, the PHP side can only get smaller.

There is a second reason. While I am porting, I am deep in the Go side every day: its database users, its token handling, its route switches, its deploy scripts. A new feature written there uses the checks and the release path I am already watching. A new feature in Laravel would mean keeping a second set of habits sharp for code I plan to delete.

Where each kind of feature goes

The rule is only useful if it is specific, so I wrote down where each kind of thing lives:

  • An endpoint for the customer, restaurant or rider apps goes into the Go API, behind the same nginx switch as the ported routes.
  • An operations screen is a page in the Next.js console, backed by a Go admin API.
  • A restaurant panel screen is a page in the Next.js vendor panel, backed by its own Go API.
  • A background job is an outbox row written in the same transaction as the change that caused it. A Go worker picks it up from NATS.
  • A schedule goes into the Go scheduler.
  • Mail and PDFs are built by Go packages.

No new Laravel controllers, routes, jobs, console commands or Blade views. I also don't write a database migration whose only purpose is to serve PHP.

The Next.js apps are screens. They get their data from the Go APIs, and the access checks live in Go. So there is one place to audit for "who may see this", not two.

Changing something that is still in PHP

The hard case is a change to a feature that exists only in Laravel. The rule there is: port that route to Go first, prove it matches the old one, and then make the change in Go.

That makes small changes slower. A one-line tweak to an old screen can turn into porting the route behind it, with shadow comparison and all. I accept it, because the alternative is worse in a quiet way. A fix that lands in PHP lands in code I am about to delete, and the person doing the port later (me) has to rediscover it from a diff or lose it.

There is one exception, and I say so out loud when I use it: an urgent production fix. If something is broken for customers right now and the code is in PHP, I fix it in PHP. Then I make sure the port carries the same fix, so the two stacks don't disagree.

Both stacks share one MariaDB database until Laravel is turned off, so schema changes have their own rule. A new table or column has to keep both sides working. In practice that means additive changes, no renames that one side doesn't know about, and defaults that the older code tolerates. When a Go endpoint writes a row that a Laravel screen still reads, the row has to look exactly like one Laravel would have written.

The same checklist every time

Writing in Go is not a security feature by itself. What the rule gives me is that every new endpoint goes through one checklist:

  • the zone or owner filter is applied unconditionally (more on that in the owner filter)
  • roles fail closed: a missing role or zone means no access
  • staff actions write an audit row
  • the endpoint's database user has column-level grants, and the read user cannot select secret columns
  • money moves only through the ledger package, with idempotency keys

And one path to production: build and prove it in the test environment, do a security pass, put it on staging where I use it by hand against a copy of production data, then release to production with a rollback ready. The staging setup has its own post.

What the rule costs

Small changes get bigger. Covered above. It is the main cost and it does not go away until the last route is ported.

The console has to be complete. The new operations console is meant to replace the old Laravel panel entirely, so I can't add a new admin feature to the old panel and "move it later". If the page a feature belongs to hasn't been rebuilt, either the feature waits or the page gets rebuilt first. I keep a parity list generated from the old routes and views, and a screen is not done until every item from the old one exists somewhere in the new console.

It changed how the console is organised. The old panel grew by bolting each feature on as its own menu entry wherever it fit at the time. Rebuilding page by page let me fix that. There is one navigation map now, and a new feature goes into the page it belongs to, as a tab, a filter or an action, rather than a new sidebar item.

Builds got heavier. A PHP edit goes live when the file is saved. A Go binary and a Next.js app have to be built, and building on the same server that serves production turned out to be a bad idea. That story is in a separate post.

Because of the rule, the list of PHP that remains only shrinks, and what is left on it is the hardest part on purpose: the money paths, the remaining jobs and the restaurant web panel.

Get new posts by email

One email when something new goes up. No tracking pixels, unsubscribe in one click.