Why Rewriting a Laravel App in Go Boosted Performance and Simplicity

The author rewrote a Laravel‑based Boxzilla application in Go, detailing migration steps, code‑size reduction, benchmark results, and testing advantages, showing how Go delivers faster response times, lower latency, and a more maintainable backend.

21CTO
21CTO
21CTO
Why Rewriting a Laravel App in Go Boosted Performance and Simplicity

Background

The author decided to rewrite the Boxzilla application, originally built with PHP Laravel, using Go to demonstrate the language's flexibility and efficiency.

Motivation

Frequent Laravel releases and perceived complexity prompted the search for a simpler, faster solution that could be deployed more easily.

Why Go?

Go is a compiled language offering superior performance, rapid development, and the author expects more developers to migrate from dynamic languages such as PHP, Python, and JavaScript to Go in the coming years.

Porting the Codebase

Key migration tasks included moving database interactions, replacing Blade templates with Go‑compatible templates, and using an ORM (Meddler) to map query results to structs. The author created an open‑source HTML template engine called Grender (https://github.com/dannyvankooten/grender) and integrated payment gateways via stripe-go and braintree-go. A Go client for Moneybird invoices ( moneybird-go) was also released.

Performance Comparison

Benchmarks using wrk on the login page showed that Go handles high concurrency with dramatically lower latency and higher request throughput than Laravel/PHP‑FPM.

Laravel (1 concurrency): 3.87 ms latency, 261.48 req/s, 1.27 MB/s

Laravel (100 concurrency): 108.86 ms latency, 917.27 req/s, 6.04 MB/s

Go (1 concurrency): 0.325 ms latency, 7 365.48 req/s, 34.27 MB/s

Go (100 concurrency): 11.63 ms latency, 19 967.31 req/s, 92.91 MB/s

Go (200 concurrency): 37.68 ms latency, 22 653.22 req/s, 105.41 MB/s

NetData graphs (illustrated below) show server resource usage under load for both Go and Laravel.

Code Size

The Laravel codebase totals about 156 k lines (including vendor files), whereas the Go version contains roughly 33 k lines—about one‑fifth the size.

find . -name '*.php' | xargs wc -l
156289 total

find . -name '*.go' | xargs wc -l
33624 total

find . -name '*.php' -not -path "./vendor/*" | xargs wc -l
13921 total

find . -name '*.go' -not -path "./vendor/*" | xargs wc -l
6750 total

Testing

Go’s built‑in testing framework uses four files (license.go, license_test.go, subscription.go, subscription_test.go), making unit testing straightforward. Laravel relies mainly on integration tests, which often achieve lower coverage due to tighter coupling.

Conclusion

Rewriting the application in Go proved enjoyable and resulted in a smaller, faster, and easier‑to‑deploy backend, demonstrating the practical benefits of choosing Go over a traditional PHP framework for similar projects.

GoWeb APIperformance benchmarkingCode size reductionLaravel migration
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.