Hosting gRPC in Azure

How to host a gRPC service in Azure? gRPC on Linux?

When it comes to hosting a gRPC service to Azure, things are pretty straightforward, but there are a few tips and tricks that we will cover.

If you have, like me, a not-so-complicated system, or you simply want to play around with the gRPC service deployed in the cloud, then this is for you.

Make sure you have an app Service plan ready and a Web App with Linux. Currently, only Linux is supported for gRPC.

So, first, a gRPC service is nothing more than a regular API with a few particularities, that need to be set in the Azure Web App prior to deployment:

  • uses HTTP/2
  • uses a binary serialization

How you get your code source in the Cloud it's up to you. You can publish directly from the IDE, or have a pipeline that runs when you push to GitHub. As long as you will be able to move your source code to the cloud, then you are all set.

Since we are dealing with a gRPC service, we need to ensure that we have HTTP version 2, and that the HTTP 2.0 Proxy is enabled, as shown in the picture below.

The next thing we will need to do is to add an application setting named HTTP20_ONLY_PORT with the value of 8585.

With these things done, we should be able to test our service, from our local machine, by instantiating a client. But if we want to use Postman, for example, is advisable to install Grpc.AspNetCore.Server.Reflection package and enable the middlewares.


builder.Services.AddGrpcReflection();
...

app.MapGrpcReflectionService();

Make sure the application is up and running, by accessing the URL provided in Azure: e.g: https://yourgrpcwebiste.azurewebsites.net/, and now you can use Postman for example to make requests.

In Postman, select the 'use server reflection` option to make sure the operations are discoverable. After that, we can make requests, just as we would do with a regular Web API.