0% found this document useful (0 votes)
14 views32 pages

Translated GRPC API Connect

Uploaded by

team.gammeurs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views32 pages

Translated GRPC API Connect

Uploaded by

team.gammeurs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

How to Utilize Connect for gRPC API Development

Naoki Kishi / @p1ass


© DeNA Co., Ltd.
Self Introduction
Naoki Kishi / @p1ass

- Joined in 2021 as a new graduate


- Engaged in backend development and infrastructure for new service launches
- Favorite programming language: Go
Solution Business Division
Through This Session
I hope you’ll think:
“Connect looks good, I want to try it.”
Session Outline
1. Technology Selection Leading to Connect
2. What is Connect?
3. Tips for Using Connect Effectively
4. Conclusion
1. Technology Selection Leading to Connect
A team developing a new product not yet released.
Just entering the development phase.

Situation when I joined the team:


- Writing APIs for Unity and Web browsers using Go.
- Architecture mostly undecided.
- Only the second backend engineer.
- Backend code had 0 lines written.
Time to select the technology!
API Communication Method Candidates

gRPC:
- An RPC framework under CNCF.
- Uses HTTP/2 and Protocol Buffers for serialization.

JSON:
- Widely used API method using JSON serialization.
- The typical “Web API” you imagine.
How to Decide on Communication Method?
Key Differentiators | gRPC | JSON
-------------------|------|------
Performance | Excellent | Good
Ease of API Spec Writing | |
Browser Compatibility | |
Operational Effort | |
How to Decide on Communication Method?
Key Differentiators | gRPC | JSON
-------------------|------|------
Performance | Excellent | Good
Ease of API Spec Writing | |
Browser Compatibility | |
Operational Effort | |

Efficient communication using HTTP/2 and binary data.


How to Decide on Communication Method?
Key Differentiators | gRPC | JSON
-------------------|------|------
Performance | Excellent | Good
Ease of API Spec Writing | Excellent | Moderate
Browser Compatibility | |
Operational Effort | |

Managing large OpenAPI YAML files can be difficult...


How to Decide on Communication Method?
Key Differentiators | gRPC | JSON
-------------------|------|------
Performance | Excellent | Good
Ease of API Spec Writing | Excellent | Moderate
Browser Compatibility | ? | ?
Operational Effort |? |?

Let’s dive deeper here.


Web Browser Compatibility

- JSON APIs can be used without issues.


- gRPC requires effort to use in web due to its HTTP/2-based protocol.
gRPC-Web: gRPC for Web Browsers

- JavaScript client library for web browsers.


- Proxy required to relay gRPC-Web communication to gRPC services.

[Diagram of Web Browser -> Proxy (Envoy) -> gRPC Server]


Challenges of gRPC-Web

- Operating a proxy solely for gRPC-Web.


- Originally, no need for a reverse proxy (managed load balancer was sufficient).
- Running a proxy server just for gRPC-Web increases operational burden.
Results So Far

gRPC has many advantages, but increased operational effort is a concern.

Key Differentiators | gRPC | JSON


-------------------|------|------
Performance | Excellent | Good
Ease of API Spec Writing | Excellent | Moderate
Browser Compatibility | Moderate | Excellent
Operational Effort | Moderate | Good
Enter Connect

“Is this what you were looking for?”


2. What is Connect?
Connect Overview

- Library to create gRPC-compatible APIs.


- Supports Go and Node.js.
- Recently started providing client libraries for iOS and Android.

https://connectrpc.com/
Supports Multiple Protocols

- Connect Protocol (Connect’s original HTTP/1.1-based API)


- gRPC
- gRPC-Web

No need for external proxies!


Protocol-Agnostic Interface

- Concept: “Protocol details are secondary.”


- Develop servers without worrying about which protocol the client uses.
Protocol-Agnostic Interface Example

Protobuf service definition and auto-generated interface.

Easily switch protocols without code changes.


Implementing Your Own Interface

Example Go handler implementation.

No protocol-dependent code, enabling seamless protocol switching.


Decision to Use Connect

Connect Chosen.

Key Differentiators | Connect (gRPC) | JSON


-------------------|------|------
Performance | Excellent | Good
Ease of API Spec Writing | Excellent | Moderate
Browser Compatibility | Excellent | Excellent
Operational Effort | Good | Good
3. Tips for Using Connect Effectively
Auto-Detecting Authentication Requirements

- Protobuf lacks a field for indicating required authentication.


- Ideally, detect authentication needs automatically from API specs.
Desired Implementation Example

Example interceptor to automatically determine if authentication is required.


Define API Specs Using Custom Options

Example of defining custom Protobuf options to specify authentication requirement.


Retrieving Custom Option Values with Connect

Example code to retrieve authentication flag using Connect.

Complex, but achievable.


Connect Update Simplifies This

Latest Connect update simplifies fetching method options.

Much easier than before.


4. Conclusion
Conclusion

- Connect is a library for creating gRPC-compatible APIs.


- Solves gRPC-Web’s weaknesses.
- Easy-to-use interface and strong ecosystem compatibility are advantages even for standard gRPC serve
- Showcased custom API spec definitions using Custom Options.
Session Recap

I hope you’ll think:


“Connect looks good, I want to try it.”

You might also like