The Rise of Hybrid PHP: Blending PHP with Go and Rust

https://news.ycombinator.com/rss Hits: 8
Summary

We used to develop our application as a single DDD monolith (let’s call it the mother) with several smaller microservices around it (the children) to gain some specific advantages. Most of these microservices were built in Go, while the core monolithic service was developed in PHP 8.3.This stack served us well for a long time. The Go microservices efficiently handled our high-throughput requests, and the carefully designed monolith allowed our relatively small backend team to deliver features quickly and with confidence. It was a good balance: speed where we needed it most, and stability and productivity everywhere else.As many of you may have experienced, 80% of your traffic often targets only 20% of your APIs—the well-known Pareto principle. And unsurprisingly, those hot 20% endpoints are usually the ones where performance matters the most. In the past, our strategies included writing highly optimized code, adding extreme caching layers, or extracting certain parts into Go-based microservices. While effective, these approaches added complexity and operational overhead.But now, thanks to new capabilities in the PHP ecosystem and the rise of powerful libraries and runtimes, it’s becoming much easier to keep more logic inside the monolith while still achieving excellent performance. Let’s look at a few exciting options:1. FFI (Foreign Function Interface)PHP’s FFI feature allows you to call C code directly from PHP. This opens the door to system-level operations or performance-critical logic without leaving your PHP project. Of course, you need to be mindful of context switching costs, but for the right use cases, it’s a game-changer.2. Rust-Based ExtensionsIf writing raw C isn’t your cup of tea, you can now write PHP extensions in Rust (or even Zig). This lets you offload heavy, performance-sensitive parts of your application to safe, memory-efficient, compiled code. Rust, in particular, offers memory safety guarantees without sacrificing speed, which makes it a grea...

First seen: 2025-08-30 20:41

Last seen: 2025-08-31 03:42