gRPC vs HTTPS+JSON with the Clarifai API
Blog post from Clarifai
Clarifai chose to build its API on gRPC due to its cutting-edge performance, enabling lightweight microservices that efficiently manage thousands of machine learning model instances and deliver scalable MLOps. The use of gRPC, which leverages the Protobuf message format and is designed for HTTP/2, ensures low latency and high throughput communications, significantly reducing network constraints compared to JSON. This setup facilitates clean code and resource management, as gRPC’s specifications provide consistency across platforms, and the protocol allows clients to set request deadlines, promoting efficient resource management. Clarifai's API is polyglot, supporting multiple languages, and automatically generates RESTful JSON Web APIs from gRPC services, thus accommodating both gRPC and JSON interfaces without duplicating efforts. gRPC's bi-directional streaming capabilities support real-time communication, vital for many machine learning applications, although not all streaming functionalities are currently utilized. While the gRPC channel is recommended for most use cases, the HTTP+JSON channel offers familiarity for developers and better browser support, albeit at the cost of performance, given that gRPC messages are more compact but not human-readable.