Migrating API from REST to gRPC in WePay

service mesh , , service mesh .





, service mesh . , . Representational State Transfer (REST) Remote Procedure Call (gRPC) , , gRPC.





RESTful gRPC

, Google Kubernetes Engine (GKE), , , -:





 1.               API
1. API

, , . , X, N , N , , . , 1, RESTful , HTTP/1.1.





, , . , gRPC,   , , ( HTTP/2 Linkerd) gRPC.





 2.
2.

, REST API, gRPC. 2 , REST gRPC. , , API gRPC.





, gRPC , , . gRPC gRPC. , gRPC, , , .





gRPC?

WePay REST JSON. REST :





  • JSON- .





  • REST-.





  • REST — , .





, REST:





  • , 1, X, X, , .





  • REST- SSL handshake. .





  • , API.





  • JSON — , .





, gRPC .





gRPC , , .





 3.  gRPC  proto-  gRPC-   proto-
3. gRPC proto- gRPC- proto-

()





gRPC:





  • RPC-, gRPC , .





  • .





  • Protocol Buffers, JSON.





  • , .





Protobuf

Protobufs — ".proto", . , . , .





1. gRPC- HelloWorld RPC- "SayHello".





Protobufs / . JSON. , , JSON- .





 4. JSON vs Protocol Buffers
4. JSON vs Protocol Buffers

protobuf-, proto- . , "" , 1, Java, :





  1. , RPC-.





2. HelloWorld Java,





  1. (), .





3. HelloWorld Java-





  1. , .





4. Java protobuf- 





gRPC HTTP/2. HTTP/2 , . gRPC (channel) (call). , gRPC , REST.





REST gRPC?

, REST- gRPC. . gRPC grpc-gateway -, RESTful JSON API gRPC. gRPC protobufs -.





gRPC:





  1. .





  2. .





  3. REST, gRPC gRPC. , REST, .





  4. gRPC- , REST-. , REST- , . gRPC- .





gRPC- REST-.





 5.  gRPC-    WePay
5. gRPC- WePay

, . , RPC- gRPC-. "GrpcServerBuilder", :





  1. "" (interceptor) , /, . .





  2. , RPC- .





GrpcServerBuilder gRPC-. .





Service Mesh

Linkerd service mesh WePay, Linkerd HTTP/2 gRPC. gRPC- Kubernetes . service mesh REST- , Kubernetes, (path). , Kubernetes "foo", Linkerd , "foo/".





gRPC HTTP/2. gRPC- — "path". Path :





<package_name>.<grpc_service_name>/<method_name>







Linkerd path . gRPC :





  1. Kubernetes gRPC. , Kubernetes "greeter", gRPC- "GreeterService".





  2. , gRPC, gRPC-. , gRPC- gRPC- .





(path) . , "service" Kubernetes Linkerd "service" gRPC.





 6.   gRPC       .
6. gRPC .

, , Kubernetes. Linkerd .





CI/CD gRPC-

gRPC- :





  1. , protobufs.





  2. protobuf-, .





  3. ().





:





  • protobuf-?





  • ?





  • proto-, , ?





, gRPC-.





 7.   gRPC  WePay.
7. gRPC WePay.

WePay - (Service Oriented Architecture), protobuf- . protobuf- gRPC- git-.





protos/
  |-<service-x>/
     |- **/*.proto
  |-<service-y>/
     |- **/*.proto
  |-commons/
     |- **/*.proto
      
      



proto- prototool , git- release-.





gRPC- protobufs. , protobufs- release-, protoc .





REST API RAML, Swagger . . gRPC protoc-gen-doc.





gRPC

gRPC , REST-, gRPC. , , REST API.





REST- gRPC , gRPC. .





gRPC. gRPC- — grpc-web. gRPC- . grpc-web, GA- , . JSON- , proto . SDK.





Protobuf

API :









  • null





  • null





proto3, . , , google wrappers. null , , update null.





gRPC HTTP-

, REST-, , HTTP- , , / , ..





gRPC-, HTTP-, . gRPC "Interceptors" () . , gRPC-, , .





Protobuf

Protocol buffers : Proto2 Proto3. gRPC . Proto2 Proto3 , .





1. proto2 proto3









Proto2





Proto3





NULL

































. .





JSON 





. protobuf





JSON





UTF-8













,









. Proto3, , , . , (wrappers, ) .





, protocol buffers . 1, proto2 proto3. , gRPC- proto2, . , , , , proto2. proto3, , proto2.





, , gRPC , gRPC.





:





  1. / , .





  2. HTTP/2 .





  3. .





  4. .





, , , , .






OTUS 2 Java- c . :





- Java Developer. Professional





- Java Developer. Basic





- , 19 . :





- (, , );





- gRPC REST- .








All Articles