Share
We’re thrilled to announce that DigitalOcean App Platform now supports applications that serve HTTP/2 and therefore gRPC as well! This opens up exciting possibilities for developers looking to build faster, more efficient, and highly scalable cloud-native apps.
HTTP/2 is a major revision of the HTTP protocol, designed to be faster and more efficient. It introduces multiplexing, where multiple requests can be sent over a single connection, significantly improving performance and reducing latency. HTTP/2 is particularly beneficial for web services and microservices architectures that need to handle many requests simultaneously.
gRPC (gRPC Remote Procedure Call) is an open-source, high-performance RPC framework that works over HTTP/2. It allows applications to communicate across different environments and programming languages with speed and efficiency. gRPC is especially useful in distributed systems and microservices due to its low-latency and real-time streaming capabilities.
gRPC is the go-to solution for developers building high-performance, distributed systems. Here’s why it stands out:
High performance: gRPC takes full advantage of HTTP/2 technology, allowing multiple requests to be multiplexed over a single connection. This results in reduced latency and faster data transmission between services.
Efficiency: gRPC uses Protocol Buffers (Protobuf) for serializing structured data, which produces compact message sizes that are perfect for environments with limited bandwidth, such as mobile and IoT devices.
Streaming capabilities: With gRPC, you can send continuous streams of data between the client and server. This makes it ideal for real-time applications, such as video streaming, chat services, or live data feeds.
Cross-language support: gRPC is designed for interoperability, allowing you to build services in different languages (Go, Python, Java, etc.) and have them communicate seamlessly. This is especially useful in microservices architectures where each service may be written in a different language.
At DigitalOcean, we trust gRPC to build many of our own internal APIs. Its speed, efficiency, and ability to handle large-scale distributed services make it the perfect fit for our needs. By adopting gRPC for your apps on DigitalOcean App Platform, you’ll be using the same technology that powers the services you use every day.
To run your gRPC app on DigitalOcean App Platform, you need to configure your application to use HTTP/2 transport. To do that, set the new protocol field in the respective service to HTTP2. Note that this is a field to-be-set per service, so different services in the same app can use either HTTP or HTTP2.
name: sample-grpc
services:
- name: sample-grpc
protocol: HTTP2
github:
repo: your_org/your_repo
The service itself has to serve HTTP/2 over cleartext (h2c), which might require a bit of setup in the respective code as opposed to a “standard” HTTP/2 setup.
For example, in Golang you can setup the server like this to be able to handle HTTP/2 and gRPC workloads:
package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
"google.golang.org/grpc"
)
func main() {
g := grpc.NewServer()
// gRPC server setup...
handler := func(w http.ResponseWriter, r *http.Request) {
if r.ProtoMajor == 2 {
if strings.HasPrefix(r.Header.Get("Content-Type"), "application/grpc") {
g.ServeHTTP(w, r)
return
}
io.WriteString(w, "Hello HTTP/2")
return
}
io.WriteString(w, "Hello HTTP/1.1")
}
server := &http.Server{
Addr: fmt.Sprintf(":%s", os.Getenv("PORT")),
Handler: h2c.NewHandler(http.HandlerFunc(handler), &http2.Server{}),
}
server.ListenAndServe()
}
And that’s it! You can now deploy your app to App Platform and it will serve your HTTP/2 or gRPC-based APIs just fine.
By leveraging gRPC and HTTP/2 on DigitalOcean App Platform, you’ll support enjoy improved performance, lower latency, and seamless scaling for your distributed services. Whether you’re building microservices, real-time APIs, or cross-platform apps, gRPC provides the perfect foundation for building modern, cloud-native systems.
Get started today and bring the power of HTTP/2 and gRPC to your applications!
Share