gRPC Flaws​ – The Illusion of Safety & Frustrating DevEx in Proto3’s Type-Safe Contracts​

By Naresh Jain
Share this page

Understanding the Shortcomings of gRPC and How Contract Testing Can Bridge the Gap 

In the ever-evolving world of API design, development, and testing, the pursuit of a seamless developer experience (DevEx) remains a constant. This article sheds light on some of the overlooked pitfalls of gRPC, a popular choice for its performance capabilities and type-safe contracts. Discover the significant benefits of contract testing in addressing common issues and enhancing developer experience. 

Understanding gRPC and Its Promises – Type-Safety and Schema Enforcement 

gRPC has gained traction in the development landscape due to its promise of performance and the enforcement of type-safe contracts via protocol buffers (protobuf). It leverages proto files to define schemas, ensuring that data types and structures remain consistent across different services and platforms. This theoretically eradicates a multitude of problems, promoting backward and forward compatibility while automatically generating client and server code in various languages. 

The Reality Check: Identifying gRPC’s Flaws – Handling Requests and Responses 

Despite gRPC’s promise, we can demonstrate several important flaws in its operation. For example, let’s use a proto file called order BFF proto, that exhibits three RPC methods: FindAvailableProducts, CreateOrder, and CreateProduct. We can seamlessly create a product using the gRPC web UI. However, omitting crucial information prompts an unexpected response— the product is created successfully despite missing mandatory details. This revelation underscores an overlooked pitfall in gRPC: the lack of built-in support for mandatory parameters enforcement. 

Employing Validation Libraries 

Proto 3 dropped required fields here is the link to the related Github discussion. However, we can leverage external libraries such as buf.validate to define mandatory parameters. Updating the proto file to validate mandatory fields ensures that requests lacking essential information trigger appropriate validation errors. However, the scenario evolves in our demonstration when a product manager imposes a new constraint: inventory can only be in multiples of three. 

The Developer’s Dilemma – Code Changes and Proto File Mismatch 

A developer can incorporate this constraint directly into the code, checking if the inventory value adheres to the new rule. While the immediate implementation seems effective, a discrepancy arises—the constraint is absent from the proto file. This highlights a critical issue: the proto file is now out of sync with the actual implementation, leading to potential misunderstandings and errors for downstream consumers. 

The Role of Contract Testing 

Contract Test Implementation 

Contract testing is an effective remedy for such issues. Using the Specmatic framework, developers can write executable contract tests that verify the alignment between the proto file and the actual implementation. Specmatic automatically generates these tests, and upon execution in our demonstration, it reveals two critical test failures. One involves sending a request with an inventory not being a multiple of three, highlighting the previously unnoticed mismatch. 

Immediate Feedback and Resolution 

Specmatic’s feedback loop proves invaluable, instantly notifying developers of the discrepancy. This immediate feedback ensures that the proto file is updated in tandem with the implementation, preventing downstream misunderstandings and ensuring a consistent developer experience across the board. 

Conclusion: Embracing Contract-Driven Development 

A Better Developer Experience 

So, it is evident that while gRPC offers advantages, it is not without its flaws. The manual nature of validating mandatory fields and the potential misalignment between proto files and implementation can lead to a subpar developer experience. However, integrating contract-driven development practices, exemplified by Specmatic, can bridge these gaps. 

Collaboration and Consistency 

Maintaining a central Git repository for API specifications is essential. This ensures that all stakeholders—be they providers or consumers—operate with an up-to-date version of the specification. This approach eradicates discrepancies and fosters a culture of collaboration and consistency. 

The Path Forward 

Ultimately, embracing contract testing in conjunction with gRPC’s strengths paves the way for a more robust and developer-friendly API ecosystem. By addressing the flaws we have highlighted, developers can build more reliable, consistent, and efficient microservices, leading to enhanced productivity and faster deployment. 

Final Thoughts 

This demonstration serves as a reminder that even the most promising technologies can benefit from supplementary practices. Contract testing is not just a tool; it’s a paradigm that aligns implementation with intent, transforming gRPC’s potential into a reality that developers can rely on. 

Related Posts

api days revised 1920x1080

By John

New features and a BIG Announcement! Specmatic is bringing apidays to India!

In the past few months, we have launched a flurry of exciting features, presented at several global conferences and onboarded several new team members. We
Read More
Speakers presenting on API Governance at tech conference.

Update: See how Specmatic is transforming API testing & development

We've been hard at work, rolling out exciting new features and sharing the power of Specmatic and Contract Driven Development around the globe! Let's explore
Read More

By Joel Rosario

Build Apps from API specs using AI: Self-Correcting Contract-Driven Agentic Workflows with Specmatic

Harnessing the Power of API Specifications for Robust Microservices  Modern microservice architecture hinges on precise and dependable communication between services. This is where API specifications
Read More

OpenAPI Examples Simplified: Visualize and Generate Domain-Specific Test Data​

Streamlining API Development: An Interactive Guide to Example Generation and Validation using Specmatic  A robust, streamlined approach to API development is crucial for maintaining efficiency,
Read More

By Hari Krishnan

Pact’s Dependency Drag​: Why Consumer-Driven Contracts Don’t Support Parallel Development

Exploring the challenges and limitations of using Pact for contract testing in a microservices environment.  In the domain of microservices, ensuring seamless communication between different
Read More

By Naresh Jain

OpenAPI’s Broken Tooling: Roundtrip Fidelity Failure with CodeGen and DocGen​

Exploring the Strengths and Weaknesses of Automated API Development  Maintaining well-documented and reliable APIs is essential for any microservices development pipelines. At the heart of
Read More

By Naresh Jain

gRPC Flaws​ – The Illusion of Safety & Frustrating DevEx in Proto3’s Type-Safe Contracts​

Understanding the Shortcomings of gRPC and How Contract Testing Can Bridge the Gap  In the ever-evolving world of API design, development, and testing, the pursuit
Read More

By Hari Krishnan

WireMock’s Dirty Secret: Ignoring API Specs & Letting Invalid Examples Slip Through 

Overcoming the Challenges of Hand-Rolled Mocks with Contract-Driven Development  APIs and microservices have transformed the way software systems are built and maintained. However, developing a
Read More
specmatic challenge – winners announced! 1536x865

By John

Specmatic Challenge – winners announced!

The Specmatic challenge is over and we are pleased to announce the winners! Congratulations to Mohd Zaid and Himanshu Singal for successfully completing the challenge
Read More

By Yogesh Nikam

Contract Testing using gRPC Specs as Executable Contracts

Transform your gRPC API specs into executable contracts in seconds Now you can easily leverage your gRPC APIs for contract testing, intelligent service virtualisation and
Read More