Building true distributed systems with RoadRunner and Laravel

I've been developing PHP applications for over 15 years now, working with various PHP frameworks. Throughout this journey, I've witnessed many projects that began as monoliths eventually need to evolve into microservices. That's when interesting architectural challenges emerge. While I'd successfully used RoadRunner (RR) with Spiral and Symfony before, I wanted to bring these same capabilities to my Laravel projects. Yes, Laravel Octane does provide RR integration but only for HTTP. I needed the full ecosystem of plugins that make RR truly powerful for distributed systems. If you're looking to build microservices where components communicate using gRPC, implement durable workflows with Temporal, or integrate your application with services written in other languages, you may have encountered certain limitations. Laravel excels at building robust applications, but when it comes to distributed systems with services written in multiple languages, additional tools can enhance its capabilities. Laravel is an exceptional framework, and to extend its already impressive feature set, I wanted to create an integration with RR that goes beyond what Octane offers. This integration has transformed how I approach microservice architecture with Laravel, allowing me to build truly distributed systems while continuing to use the framework I often need for client projects. With dozens of services written in Go and Python, I've been able to seamlessly communicate with them from services written in Spiral and Symfony. Now, we can also use Laravel in this same ecosystem. The challenge of building distributed systems Before diving into solutions, let's understand the core challenges of distributed systems and microservices: Laravel's queue system uses PHP's serialization under the hood, which means jobs serialized by Laravel are designed to be deserialized by PHP applications. This creates a consideration to address when building a microservice architecture with services written in different languages like Go, Python, or Node.js, as these services can't directly consume messages from Laravel queues without additional adapters. Laravel's approach provides excellent developer convenience. It allows you to serialize virtually anything - objects, closures, functions, and complex structures - without having to think about format conversion. This is tremendously convenient when working within a PHP ecosystem, as you can queue complex objects with minimal effort. However, when communicating with non-PHP services in a distributed architecture, additional approaches can be beneficial. Performance optimization opportunities Traditional PHP implementations of queue systems often have certain characteristics to consider: Connection Management: PHP queue workers establish their own connection to the queue broker. The more workers you have, the more connections you need, increasing the load on your queue broker. Task Distribution: PHP workers independently poll the queue broker for tasks, essentially competing with each other. This leads to inefficient task distribution and wasted resources. Scaling Considerations: As you scale up PHP queue workers, the connection overhead and competition for tasks grows proportionally, limiting effective scaling. RR takes a different approach to queue processing that can offer performance benefits: Centralized Connection Management: RR establishes a single connection to the queue broker. Intelligent Task Distribution: It fetches batches of tasks from the queue and efficiently distributes them among available PHP workers. Lightweight Communication: PHP workers communicate with RR using pipes rather than connecting directly to the queue broker, creating a more efficient system. Let's dive into RoadRunner At its core, RR is a complete application server written in Go. Where it truly shines is its plugin ecosystem that enhances PHP's capabilities while maintaining the development experience you already know and love. Get started with RoadRunner by visiting the official RoadRunner documentation. Let's explore some of the key plugins that make RR particularly valuable for developers:

May 10, 2025 - 18:04
 0
Building true distributed systems with RoadRunner and Laravel

I've been developing PHP applications for over 15 years now, working with various PHP frameworks. Throughout this journey, I've witnessed many projects that began as monoliths eventually need to evolve into microservices. That's when interesting architectural challenges emerge.

While I'd successfully used RoadRunner (RR) with Spiral and Symfony before, I wanted to bring these same capabilities to my Laravel projects. Yes, Laravel Octane does provide RR integration but only for HTTP. I needed the full ecosystem of plugins that make RR truly powerful for distributed systems.

If you're looking to build microservices where components communicate using gRPC, implement durable workflows with Temporal, or integrate your application with services written in other languages, you may have encountered certain limitations. Laravel excels at building robust applications, but when it comes to distributed systems with services written in multiple languages, additional tools can enhance its capabilities.

Laravel is an exceptional framework, and to extend its already impressive feature set, I wanted to create an integration with RR that goes beyond what Octane offers. This integration has transformed how I approach microservice architecture with Laravel, allowing me to build truly distributed systems while continuing to use the framework I often need for client projects. With dozens of services written in Go and Python, I've been able to seamlessly communicate with them from services written in Spiral and Symfony. Now, we can also use Laravel in this same ecosystem.

The challenge of building distributed systems

Before diving into solutions, let's understand the core challenges of distributed systems and microservices:

Laravel's queue system uses PHP's serialization under the hood, which means jobs serialized by Laravel are designed to be deserialized by PHP applications. This creates a consideration to address when building a microservice architecture with services written in different languages like Go, Python, or Node.js, as these services can't directly consume messages from Laravel queues without additional adapters.

Laravel's approach provides excellent developer convenience. It allows you to serialize virtually anything - objects, closures, functions, and complex structures - without having to think about format conversion. This is tremendously convenient when working within a PHP ecosystem, as you can queue complex objects with minimal effort. However, when communicating with non-PHP services in a distributed architecture, additional approaches can be beneficial.

Performance optimization opportunities

Traditional PHP implementations of queue systems often have certain characteristics to consider:

  1. Connection Management: PHP queue workers establish their own connection to the queue broker. The more workers you have, the more connections you need, increasing the load on your queue broker.
  2. Task Distribution: PHP workers independently poll the queue broker for tasks, essentially competing with each other. This leads to inefficient task distribution and wasted resources.
  3. Scaling Considerations: As you scale up PHP queue workers, the connection overhead and competition for tasks grows proportionally, limiting effective scaling.

RR takes a different approach to queue processing that can offer performance benefits:

  1. Centralized Connection Management: RR establishes a single connection to the queue broker.
  2. Intelligent Task Distribution: It fetches batches of tasks from the queue and efficiently distributes them among available PHP workers.
  3. Lightweight Communication: PHP workers communicate with RR using pipes rather than connecting directly to the queue broker, creating a more efficient system.

Let's dive into RoadRunner

At its core, RR is a complete application server written in Go. Where it truly shines is its plugin ecosystem that enhances PHP's capabilities while maintaining the development experience you already know and love.

RoadRunner plugins

Get started with RoadRunner by visiting the official RoadRunner documentation.

Let's explore some of the key plugins that make RR particularly valuable for developers: