gRPC in Symfony: Building Type-Safe Microservices with RoadRunner

Liya Shereef By Liya Shereef on December 3, 2026
gRPC architecture for Symfony microservices

Every microservice setup eventually comes down to one question: how should the services talk to each other? Most of us reach for REST and JSON by default, and for browsers and public APIs that is still a great choice. But when one backend service is calling another all day long, it is worth asking whether there is a better fit.

That question led me to gRPC in Symfony. You describe your API once in a proto file, generate typed code for both sides, and let compact binary messages travel over HTTP/2. The catch? PHP has never been the obvious place to run it. RoadRunner changes that by keeping Symfony workers alive and serving gRPC directly, which makes a real Symfony gRPC integration practical.

Here is what I learned along the way: how gRPC works, how to set it up with RoadRunner, what happens when things fail, and when it makes more sense than REST.

What Is gRPC and How Does It Work?

gRPC is a remote procedure call framework. Instead of requesting a URL, a client calls a named method, such as GetClub, that runs in another service. The methods and their messages are described up front in a .proto file, and code for both the client and the server is generated from that same file. Messages travel as compact binary Protocol Buffers over HTTP/2.
 

gRPC vs REST: Why Choose gRPC for Internal Microservices?

With REST between services, the shape of a JSON response is an informal agreement. If one service renames a field, the other still builds, still deploys, and still receives HTTP 200. The problem only appears at runtime, usually as a null where a value used to be.
 

On top of that, every consuming service writes its own client code, OpenAPI files slowly drift from the real responses, and every message repeats its field names as text. None of this is a problem for a public API. Between services that call each other constantly, it adds up.

Building a Practical Symfony Microservices Example

To test gRPC in a realistic PHP microservices architecture while keeping the focus on the communication itself, I kept the example deliberately small:

  • Club service: owns three football clubs and offers them over gRPC with two calls, ListClubs and GetClub.
  • Contact service: owns five contacts, each storing only the id of its club. It answers REST requests from the browser and fetches each contact's club from the Club service over gRPC.

One contact deliberately points at a club that does not exist, so I could see how a "not found" answer should be handled.
 

How gRPC Works: HTTP/2 and Protocol Buffers

Before writing any code, it helped me to see what actually travels between the services. Calls run over HTTP/2, which can carry many requests on one connection at the same time:
 

Messages are Protocol Buffers instead of JSON. Field names stay in the contract and only field numbers travel, so the same club is roughly half the size:
 

Each message travels in a small length-prefixed frame, and the outcome of the call comes back in a gRPC-status trailer rather than in the body:
 

What Is RoadRunner and Why Use It with Symfony?

There is one obstacle for PHP: PHP-FPM cannot serve gRPC. It handles one request per process lifecycle and does not accept gRPC over HTTP/2. RoadRunner fills that gap. It is an application server written in Go that owns the network ports, speaks HTTP/2, decodes each gRPC call, and hands it to a PHP worker that stays in memory between calls. That is what makes gRPC with RoadRunner a practical choice for Symfony applications.

In my setup, one instance of the RoadRunner PHP application server runs two worker pools: an HTTP pool for the Contact service and a gRPC pool for the Club service.
 

How to Implement gRPC in Symfony with RoadRunner

Here is the whole path, from the contract to a working call between the two services.

1. Define the Protocol Buffers Contract

The first file I wrote was not a controller or a client, but the contract. An excerpt from proto/club.proto: 

 

syntax = "proto3";
package club;

message Club {
  int32 id = 1;
  string name = 2;
  string city = 3;
}

service ClubService {
  rpc ListClubs (ListClubsRequest) returns (ListClubsResponse);
  rpc GetClub (GetClubRequest) returns (GetClubResponse);
}

 

2. Generate the PHP Code

protoc --plugin=protoc-gen-php-grpc \
  --php_out=src --php-grpc_out=src \
  --proto_path=proto proto/club.proto

One thing worth knowing early: RoadRunner's plugin only generates the server side. The official PHP client requires the gRPC extension, so for this proof of concept I wrote a small client on top of curl instead.

3. Configure RoadRunner

In rr.yaml: 

grpc:
  listen: "tcp://127.0.0.1:50051"
  proto:
    - "proto/club.proto"
  pool:
    command: "php worker.php"
    num_workers: 2

The first problem I hit was here. RoadRunner uses each worker's standard output for its own protocol, and a PHP 8.3 deprecation notice printed there made RoadRunner reject the worker. A narrow error handler fixed it, and the lesson stuck: logs and warnings belong on stderr.

4. Implement the Club Service

Each RPC is simply a method on the generated interface:

public function GetClub(ContextInterface $ctx, GetClubRequest $in): GetClubResponse
{
    foreach ($this->clubs as $club) {
        if ($club['id'] === $in->getId()) {
            return (new GetClubResponse())->setClub($this->message($club));
        }
    }

    throw NotFoundException::create('Club not found.');
}

 

Throwing NotFoundException sends the gRPC status NOT_FOUND, so the caller can tell a missing club apart from a broken service without parsing an error message.

5. Connect the Contact Service Using gRPC

The Contact service reaches the Club service through one small class, ClubGateway. Every call has a 2-second deadline, and each failure arrives as a gRPC status code:

public function getClub(int $id): ?array
{
    try {
        $response = $this->client->unary(
            '/club.ClubService/GetClub',
            (new GetClubRequest())->setId($id),
            GetClubResponse::class
        );
    } catch (GrpcStatusException $e) {
        if ($e->getStatus() === GrpcStatusException::NOT_FOUND) {
            return null;    // the club does not exist
        }
        throw $e;           // UNAVAILABLE or DEADLINE_EXCEEDED
    }

    return $this->toArray($response->getClub());
}

For a list of contacts, the gateway makes a single ListClubs call rather than one call per contact. Requesting a contact now returns it together with its club:
 

GET /contacts/2
{"id":2,"name":"Lars Berg","club":{"id":2,"name":"Harbor United","city":"Bergen"}}

Handling gRPC Errors and Service Failures

The part I found most valuable was deciding, up front, what each outcome means for the user:

gRPC resultContact service returns
OK200, the contact with its club
NOT_FOUND200, the contact with "club": null
UNAVAILABLE503, the Club service cannot be reached
DEADLINE_EXCEEDED504, the Club service did not answer in time

I tested these against the running services: the contact with the missing club came back with "club": null, and pointing the client at an address with no server returned UNAVAILABLE, which the Contact service turned into a 503.
 

Key Use Cases of gRPC in Microservices

Once the pattern was in place, it was easy to see where PHP gRPC services fit beyond clubs and contacts:

  • Lookups between services: one service enriching its data with another's, exactly as the Contact service does.
  • High-frequency internal APIs: calls made thousands of times a day, where smaller payloads and warm workers add up.
  • Shared contracts across teams: several services depending on the same data, all generated from one versioned file.
  • Services in different languages: the same .proto generates clients for PHP, Go, Java, and others.
  • Streaming between services: long-running imports or data feeds, using gRPC's built-in streaming.
     

gRPC vs REST: Choosing the Right Communication Approach

This was never a "gRPC wins" exercise. The two solve different problems, and choosing the wrong one in either direction has a cost:

 RESTgRPC
Typical callerBrowsers, mobile apps, partnersYour own backend services
ContractDocumentation or OpenAPI.proto file, code generated for both sides
PayloadJSON text, easy to readBinary Protocol Buffers, smaller
TransportHTTP/1.1 or HTTP/2HTTP/2 only
Browser supportNativeNeeds a proxy such as gRPC-Web
HTTP cachingBuilt inNot available
StreamingLimitedBuilt in, in both directions
Debuggingcurl, browsergrpcurl, generated clients

The question I now ask is simple: is the caller a service that I control?

Reach for gRPC when:

  • You control both the calling service and the called service.
  • Services call each other frequently and latency matters.
  • Several services depend on one typed, versioned contract.
  • You need streaming between services.

Stay with REST when:

  • Browsers, mobile apps, or partners call the API.
  • Responses should be cached, bookmarked, or easy to inspect.
  • You publish a public API or receive webhooks.
  • The integration is simple and infrequent.

And it does not have to be one or the other. My Contact service speaks REST to the browser and gRPC to the Club service.
 

Conclusion: When to Use gRPC with Symfony

None of this makes REST outdated. For browsers, partners, and public APIs, it remains the right tool. What this exercise showed is that, for communication between services, gRPC in Symfony is a strong option to have alongside it.

Going back to where I started: the contract is what made the difference. One .proto file now describes how the two services talk, and both sides are generated from it, so a renamed field becomes a reviewed change instead of a production surprise. RoadRunner made it practical in Symfony, and deadlines with clear status codes kept the Contact service predictable when the Club service was not. Before taking this to production, I would deploy the services separately, version the contract, and keep gRPC behind TLS and an HTTP/2-aware load balancer.
 

Need Help Building Symfony Microservices?

As applications grow into separate services, the way those services talk to each other becomes as important as the services themselves. Loose JSON agreements, hand-written clients, and missing error handling tend to surface only when something breaks in production.

At PIT Solutions, our enterprise web application development and custom web development teams design service communication as part of the architecture from the start, choosing REST, gRPC, or event-driven messaging based on what each boundary actually needs. From the first service boundary to a full custom software development project, we support you end to end.

If you are planning a move to microservices, struggling with fragile integrations between Symfony services, or unsure whether gRPC is the right fit for your system, Get in Touch with PIT Solutions. Our team can review your architecture and help you build service communication that holds up in production.