Beyond Rest - Contract Testing in the Age of gRPC, Kafka and GraphQL

Rate this content
Bookmark

Modern distributed architectures are more complex than ever before, with a majority of companies operating multiple languages, protocols and architectural styles. This poses significant challenges for engineering teams increasingly asked to deliver more at speed. Whilst the practice of contract testing rose to prominence during the RESTful microservices boom to address similar challenges, the problem statement has evolved. In this talk, we'll discuss these new challenges and demonstrate how contract testing is still as relevant as it has ever been in helping to solve them.

This talk has been presented at TestJS Summit 2022, check out the latest edition of this Tech Conference.

FAQ

Contract testing is a technique used to ensure that two systems can communicate effectively by validating the interactions between their APIs. It involves mocking out dependencies and testing integration points independently, which is crucial for environments with microservices and multiple protocols, allowing for faster and more reliable feedback.

Matt Fellowes is a Principal Product Manager at SmartBear and a core maintainer of PACT, a consumer-driven contract testing framework. He has extensive experience in consulting and has worked with some of Australia's largest organizations on their distributed systems.

Contract testing addresses challenges in multi-protocol environments by providing a way to test API communications independently of the full system. This reduces the need for complex, flaky end-to-end tests, decreases feedback time, and supports independent deployment of services, thus managing complexity and improving delivery speed.

A common misconception is that newer technologies or specifications like Protobufs or OpenAPI can eliminate the need for contract testing. However, these technologies still face issues with semantic understanding and managing optional fields, which contract testing addresses by focusing on the actual data exchange and interaction between systems.

PACT is an open-source tool that facilitates consumer-driven contract testing, ensuring that APIs from different systems interact as expected. By capturing and replaying specific interactions, PACT helps validate that changes in APIs do not break existing contracts, thus supporting continuous integration and deployment in a controlled manner.

Mature organizations often face challenges related to the complexity and scaling of microservices, including maintaining multiple versions and ensuring consistent functionality across services. This leads to increased development and maintenance costs, which contract testing can help mitigate by streamlining the testing process and reducing dependencies.

Contract testing improves efficiency by allowing teams to test integrations early in the development cycle, reducing the reliance on end-to-end testing. This approach speeds up feedback loops, minimizes deployment risks, and enables independent service deployments, which are crucial for agile and DevOps practices.

Matt Fellows
Matt Fellows
22 min
03 Nov, 2022

Comments

Sign in or register to post your comment.

Video Summary and Transcription

This talk explores the challenges of API communication in a multi-protocol environment and the limitations of REST. It discusses how contract testing can address these challenges by focusing on API communications and reducing reliance on end-to-end tests. The talk also examines the limitations of specifications like OpenAPI and JSON schema and the challenges of endpoint evolution and versioning. It highlights the benefits of consumer-driven contract testing in ensuring API compatibility and provides an overview of the PACT framework as a standardized solution.

1. Introduction to Beyond REST and Contract Testing

Short description:

Thank you for joining my talk on Beyond REST, contract testing in the age of gRPC, Kafka, and GraphQL. Today, we will examine whether REST is the problem and if there are superior technologies for API communication. We'll explore different classes of technologies, such as OAS, ASIN KPI, GraphQL, and IDLs like Protobufs and Avroans. Using PACT as a concrete implementation, we'll understand how contract testing fits into these technologies. Let's understand why contract testing exists and the context in which it operates. Research shows that internal microservices are a major focus for teams.

OK, well, thank you, everybody, for coming to my talk on Beyond REST, contract testing in the age of gRPC, Kafka, and GraphQL. My name is Matt Fellowes. I'm a Principal Product Manager at SmartBear. I was a co-founder of Pactflow, which joined the SmartBear family back in April this year. And I'm a core maintainer of PACT, which is a consumer driven contract testing framework, an open source one. And the subject, or the course, up until much of today's talk.

Prior to working at Pactflow, I was a consultant. I'm a recovering consultant, and I was lucky enough to work at some of Australia's biggest and largest well known organizations and their distributed systems, and really seen them evolve over my career. There have been, of course, a huge amount of technological change since the days where SOAP, which was the predominant technology when I joined the industry, over the years. And in my relatively short career, I've worked from that SOA, SOAP starting point to rest and microservices, the rise of public cloud and IOT, event sourcing, events framing, modern data pipelines, and of course serverless architectures. And I found in many of these situations and contexts that contract testing was still really relevant and would often look to introduce contract testing into places where there was benefits we had in shifting left, moving faster and solving those problems in itself. But of course during those rollouts or often, I would be on the receiving end of some kind of snarky comment, usually from another competing consultancy of course, that had the following shaped argument. If we just used insert blank technology, then we wouldn't need contract testing. But is it true? Well, today we're going to examine that statement. We're going to ask the question is REST really the problem? And could we save ourselves the trouble of having to think about contract testing, running tests by using a superior technology to API communication? We're going to learn briefly what contract testing is, why it exists in the problem that it solves. And we're going to look into, you know, to see if history is repeating itself or if these new technologies and architectural trends really do solve the problem. Specifically, we're going to look at a few classes of technologies. We're going to look at specifications such as OAS and ASIN KPI to a degree, GraphQL and also IDLs and things like Protobufs and Avroans, Rift. There are of course others, but these are by far the most common alternatives suggested to me by my consultant interlocutors. We'll look at these from a general contract testing lens, but of course we'll use PACT, which is obviously a tool that I work on, as a concrete implementation to help us understand and how it works in practice. And hopefully you'll see that, you know, while PACT has evolved to meet some of these needs, we'll also see that the problem and solution is much more general than any specific technology or language that we've discussed today.

Let's quickly talk about, you know, or understand why contract testing exists and the context in which it operates. I think starting with a customer quote is a good way to set the scene, just to help us, you know, feel the problem. This is a quote from a PACT flow prospect reaching out for some help and for argument sake and to protect the innocent, let's call him Bill. And Bill is a leader of a testing organization for over 40 teams in a very large banking institution. And you can see here, he's basically describing working in this big environment with a highly volatile, sort of, you know, testing environment, which makes it challenging, and he's trying to work out how he can use contract testing to test, you know, all the things he's got. He's got RESTful services, GraphQL, Kafka, third party systems, you know, all these things, right? And where you can take away from this, he works in this chaotic environment, it's complex, and he's looking for ways to bring some process and control to that situation. Now, if it sounds anything at all like your company or architecture, you're not alone. Research from SmartBear's state of quality, as well as Postman's API report, really back this up. And we can see that, for one, internal microservices are becoming a massive focus for teams.

2. Challenges and Solutions for Microservices Testing

Short description:

You can see that most companies operate in a multi-protocol environment, and many face challenges with the speed of delivery, complexity of systems, and the scalability of their ecosystem. Mature organizations are particularly affected by these issues. The traditional approach of end-to-end integrated testing for microservices can be slow, flaky, and difficult to debug. However, contract testing offers a solution by reducing the reliance on end-to-end tests and focusing on API communications. By mocking out dependencies and validating mocks, contract testing ensures that systems can communicate effectively.

You can see here that 61% said they're going to see the most growth for microservices. But actually behind the scenes, you'll read that there's actually internal services about making data available internally to other teams to create more value, which is really interesting. But you can see that also most companies operate in a multi-protocol environment, 81% or so, and almost 60% have three or more protocols.

Now, of course, while microservices aren't new, and many lessons have been learned, there's these issues we're starting to see, you know, really a decade on that we're still emerging from this new way of doing things. In the report, or both these reports, we can see that 50% of people stated that experience or skills were a barrier to getting microservices going, and 35% stated that complexity of systems, this is the second issue, is becoming the problem. And the obstacles are around the speed of delivery, or the expected speed of delivery, versus the time to actually test and build stuff is really at odds with one another. And what I found most interesting of all was that mature organizations are ones feeling the pain. And so you think, why is it counterintuitive? If they're mature, they've probably got all these practices and technology and whatnot to deal with it, but I actually think the reasons are well understood.

The first reason, or one of those reasons, is how we test microservices today. Most companies rely on test and aid distributed systems using a form of integration testing called end-to-end integrated tests. This involves basically taking all your applications and deploying them all into one big shared environment and then running a battery of tests against the whole system, so all the layers of your system, right? And then, if that works, you can then deploy. Now, this might give you a high degree of confidence. They do, if they pass, they do tend to be quite slow, and they also tend to be very flaky, and they tend to be very hard to debug. And because of all this, they give you feedback much further down the lifecycle, right? Because you've had to deploy them before you can get that feedback. It also means they're very difficult to deploy. You probably can't deploy things independently, and you probably have a distributed monolith rather than a nice coherent set of cooperative components working towards a single end in mind.

This creates a problem when you start to scale the size of your ecosystem, both people and software. As you do this, as you add new components and people into the system, you see this nonlinear response to things like the cost complexity time or number of environments, build time, the cost associated with change, and developer idle time. But if you look really carefully, you'll notice that you only really start to feel the pain a bit further down. That inflection point is not there at the start, so you sort of come into the system thinking it's easy to use, but then as you scale, you eventually hit this tipping point where it becomes real painful. And so no wonder Bill's having a bad time. This is kind of explaining what is going on there.

Okay, so what's the solution? Well, one of the solutions is using things like contract testing. Contract testing can help by reducing a lot of the end-to-end tests and replacing them with a way of testing your API communications, which is often what end-to-end testing aims to do. Contract testing is a technique to ensure that two systems are able to communicate. And we look at those integration points and we do it by mocking out the dependencies. So, if you're an API consumer, you mock out the provider and you replay those mocks against it later on in real life against the real provider. And if those mocks have been validated, we're feeling confident that these two systems are able to communicate. And the benefit of this way of working is that it's much simpler to understand. You're just testing a single integration point at a time.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Scaling Up with Remix and Micro Frontends
Remix Conf Europe 2022Remix Conf Europe 2022
23 min
Scaling Up with Remix and Micro Frontends
Top Content
This talk discusses the usage of Microfrontends in Remix and introduces the Tiny Frontend library. Kazoo, a used car buying platform, follows a domain-driven design approach and encountered issues with granular slicing. Tiny Frontend aims to solve the slicing problem and promotes type safety and compatibility of shared dependencies. The speaker demonstrates how Tiny Frontend works with server-side rendering and how Remix can consume and update components without redeploying the app. The talk also explores the usage of micro frontends and the future support for Webpack Module Federation in Remix.
Network Requests with Cypress
TestJS Summit 2021TestJS Summit 2021
33 min
Network Requests with Cypress
Top Content
Cecilia Martinez, a technical account manager at Cypress, discusses network requests in Cypress and demonstrates commands like cydot request and SCI.INTERCEPT. She also explains dynamic matching and aliasing, network stubbing, and the pros and cons of using real server responses versus stubbing. The talk covers logging request responses, testing front-end and backend API, handling list length and DOM traversal, lazy loading, and provides resources for beginners to learn Cypress.
Testing Pyramid Makes Little Sense, What We Can Use Instead
TestJS Summit 2021TestJS Summit 2021
38 min
Testing Pyramid Makes Little Sense, What We Can Use Instead
Top Content
Featured Video
Gleb Bahmutov
Roman Sandler
2 authors
The testing pyramid - the canonical shape of tests that defined what types of tests we need to write to make sure the app works - is ... obsolete. In this presentation, Roman Sandler and Gleb Bahmutov argue what the testing shape works better for today's web applications.
Full Stack Components
Remix Conf Europe 2022Remix Conf Europe 2022
37 min
Full Stack Components
Top Content
RemixConf EU discussed full stack components and their benefits, such as marrying the backend and UI in the same file. The talk demonstrated the implementation of a combo box with search functionality using Remix and the Downshift library. It also highlighted the ease of creating resource routes in Remix and the importance of code organization and maintainability in full stack components. The speaker expressed gratitude towards the audience and discussed the future of Remix, including its acquisition by Shopify and the potential for collaboration with Hydrogen.
Debugging JS
React Summit 2023React Summit 2023
24 min
Debugging JS
Top Content
Watch video: Debugging JS
Debugging JavaScript is a crucial skill that is often overlooked in the industry. It is important to understand the problem, reproduce the issue, and identify the root cause. Having a variety of debugging tools and techniques, such as console methods and graphical debuggers, is beneficial. Replay is a time-traveling debugger for JavaScript that allows users to record and inspect bugs. It works with Redux, plain React, and even minified code with the help of source maps.
Making JavaScript on WebAssembly Fast
JSNation Live 2021JSNation Live 2021
29 min
Making JavaScript on WebAssembly Fast
Top Content
WebAssembly enables optimizing JavaScript performance for different environments by deploying the JavaScript engine as a portable WebAssembly module. By making JavaScript on WebAssembly fast, instances can be created for each request, reducing latency and security risks. Initialization and runtime phases can be improved with tools like Wiser and snapshotting, resulting in faster startup times. Optimizing JavaScript performance in WebAssembly can be achieved through techniques like ahead-of-time compilation and inline caching. WebAssembly usage is growing outside the web, offering benefits like isolation and portability. Build sizes and snapshotting in WebAssembly depend on the application, and more information can be found on the Mozilla Hacks website and Bike Reliance site.

Workshops on related topic

Designing Effective Tests With React Testing Library
React Summit 2023React Summit 2023
151 min
Designing Effective Tests With React Testing Library
Top Content
Featured Workshop
Josh Justice
Josh Justice
React Testing Library is a great framework for React component tests because there are a lot of questions it answers for you, so you don’t need to worry about those questions. But that doesn’t mean testing is easy. There are still a lot of questions you have to figure out for yourself: How many component tests should you write vs end-to-end tests or lower-level unit tests? How can you test a certain line of code that is tricky to test? And what in the world are you supposed to do about that persistent act() warning?
In this three-hour workshop we’ll introduce React Testing Library along with a mental model for how to think about designing your component tests. This mental model will help you see how to test each bit of logic, whether or not to mock dependencies, and will help improve the design of your components. You’ll walk away with the tools, techniques, and principles you need to implement low-cost, high-value component tests.
Table of contents- The different kinds of React application tests, and where component tests fit in- A mental model for thinking about the inputs and outputs of the components you test- Options for selecting DOM elements to verify and interact with them- The value of mocks and why they shouldn’t be avoided- The challenges with asynchrony in RTL tests and how to handle them
Prerequisites- Familiarity with building applications with React- Basic experience writing automated tests with Jest or another unit testing framework- You do not need any experience with React Testing Library- Machine setup: Node LTS, Yarn
Master JavaScript Patterns
JSNation 2024JSNation 2024
145 min
Master JavaScript Patterns
Featured Workshop
Adrian Hajdin
Adrian Hajdin
During this workshop, participants will review the essential JavaScript patterns that every developer should know. Through hands-on exercises, real-world examples, and interactive discussions, attendees will deepen their understanding of best practices for organizing code, solving common challenges, and designing scalable architectures. By the end of the workshop, participants will gain newfound confidence in their ability to write high-quality JavaScript code that stands the test of time.
Points Covered:
1. Introduction to JavaScript Patterns2. Foundational Patterns3. Object Creation Patterns4. Behavioral Patterns5. Architectural Patterns6. Hands-On Exercises and Case Studies
How It Will Help Developers:
- Gain a deep understanding of JavaScript patterns and their applications in real-world scenarios- Learn best practices for organizing code, solving common challenges, and designing scalable architectures- Enhance problem-solving skills and code readability- Improve collaboration and communication within development teams- Accelerate career growth and opportunities for advancement in the software industry
How to Start With Cypress
TestJS Summit 2022TestJS Summit 2022
146 min
How to Start With Cypress
Featured WorkshopFree
Filip Hric
Filip Hric
The web has evolved. Finally, testing has also. Cypress is a modern testing tool that answers the testing needs of modern web applications. It has been gaining a lot of traction in the last couple of years, gaining worldwide popularity. If you have been waiting to learn Cypress, wait no more! Filip Hric will guide you through the first steps on how to start using Cypress and set up a project on your own. The good news is, learning Cypress is incredibly easy. You'll write your first test in no time, and then you'll discover how to write a full end-to-end test for a modern web application. You'll learn the core concepts like retry-ability. Discover how to work and interact with your application and learn how to combine API and UI tests. Throughout this whole workshop, we will write code and do practical exercises. You will leave with a hands-on experience that you can translate to your own project.
Integrating LangChain with JavaScript for Web Developers
React Summit 2024React Summit 2024
92 min
Integrating LangChain with JavaScript for Web Developers
Featured Workshop
Vivek Nayyar
Vivek Nayyar
Dive into the world of AI with our interactive workshop designed specifically for web developers. "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" offers a unique opportunity to bridge the gap between AI and web development. Despite the prominence of Python in AI development, the vast potential of JavaScript remains largely untapped. This workshop aims to change that.Throughout this hands-on session, participants will learn how to leverage LangChain—a tool designed to make large language models more accessible and useful—to build dynamic AI agents directly within JavaScript environments. This approach opens up new possibilities for enhancing web applications with intelligent features, from automated customer support to content generation and beyond.We'll start with the basics of LangChain and AI models, ensuring a solid foundation even for those new to AI. From there, we'll dive into practical exercises that demonstrate how to integrate these technologies into real-world JavaScript projects. Participants will work through examples, facing and overcoming the challenges of making AI work seamlessly on the web.This workshop is more than just a learning experience; it's a chance to be at the forefront of an emerging field. By the end, attendees will not only have gained valuable skills but also created AI-enhanced features they can take back to their projects or workplaces.Whether you're a seasoned web developer curious about AI or looking to expand your skillset into new and exciting areas, "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" is your gateway to the future of web development. Join us to unlock the potential of AI in your web projects, making them smarter, more interactive, and more engaging for users.
Detox 101: How to write stable end-to-end tests for your React Native application
React Summit 2022React Summit 2022
117 min
Detox 101: How to write stable end-to-end tests for your React Native application
Top Content
WorkshopFree
Yevheniia Hlovatska
Yevheniia Hlovatska
Compared to unit testing, end-to-end testing aims to interact with your application just like a real user. And as we all know it can be pretty challenging. Especially when we talk about Mobile applications.
Tests rely on many conditions and are considered to be slow and flaky. On the other hand - end-to-end tests can give the greatest confidence that your app is working. And if done right - can become an amazing tool for boosting developer velocity.
Detox is a gray-box end-to-end testing framework for mobile apps. Developed by Wix to solve the problem of slowness and flakiness and used by React Native itself as its E2E testing tool.
Join me on this workshop to learn how to make your mobile end-to-end tests with Detox rock.
Prerequisites- iOS/Android: MacOS Catalina or newer- Android only: Linux- Install before the workshop
Using CodeMirror to Build a JavaScript Editor with Linting and AutoComplete
React Day Berlin 2022React Day Berlin 2022
86 min
Using CodeMirror to Build a JavaScript Editor with Linting and AutoComplete
Top Content
WorkshopFree
Hussien Khayoon
Kahvi Patel
2 authors
Using a library might seem easy at first glance, but how do you choose the right library? How do you upgrade an existing one? And how do you wade through the documentation to find what you want?
In this workshop, we’ll discuss all these finer points while going through a general example of building a code editor using CodeMirror in React. All while sharing some of the nuances our team learned about using this library and some problems we encountered.