Today, Twitch released an RPC framework for communicating between back-end services written by Go. The framework is called Twirp and is now available under the Apache 2 open Source license.

Twirp has been a huge success on Twitch — its usage is doubling, roughly tripling every three months, as more and more internal teams adopt it, and this is due to its advantages over the 2 closest competitors “REST” or gRPC.

Structured RPCS are easier to design and maintain than URL-oriented REST apis because they let you focus on business logic rather than routing schemes. It’s much easier to change the API to add new fields or methods, and you can hide serialization features (for example, JSON missing 64-bit numbers). GRPC implemented structured RPC, but we found that it was complex and introduced an unacceptable number of bugs – and we couldn’t verify its strong http2 requirements. Twirp is a structured RPC framework with an emphasis on simplicity. Twirp works on top of HTTP1.1, choosing stability and modularity on an extended feature set and then avoiding it.

Twirp is so simple, in fact, that you can use the curl command to make a valid request without much thought. It has a Content-Type header, a request data payload, a correct URL- all very standardized. Such as:

# This is a valid Twirp request:
curl \
 -header 'Content-Type:application/json' \
 -data '{"user": "spencer", "email": "[email protected]"}' \
 http://localhost:9090/twirp/twitch.example.EmailBoss/UpdateEmail
Copy the code

We think that if you work in a service-oriented architecture and application using Go, you will want to use Twirp. We also think that even if you don’t use Go, you can apply it to the system’s services. The core design of Twirp is language agnostic, and we plan to expand to other languages, but the implementation on GO is stable enough to be applied to production environments.

Start learning can now access: github.com/twitchtv/twirp.

But let’s go back. What does RPC framework mean, and why do you need to use RPC? Read more technical details. This article will cover the following:

  • Why do you need RPC
  • An example of building an API using Twirp
  • Low-level details of the Twirp protocol
  • Why not gPRC?
  • Application of Twirp in production environment
  • How do you get involved

We’ll start by describing the typical way an engineer writes a back-end service API: by hand, with a set of urls that provide a JSON response.

Why do you need RPC

Unfinished. The original address: https://blog.twitch.tv/twirp-a-sweet-new-rpc-framework-for-go-5f2febbf35f