Before we go deep into benchmarking APIs, let’s liken the process to selling lemonade. Say you want to get into the business of selling lemonade in the spring and summer. Aside from buying lemons, water, sugar, and equipment for your stall, what are the things you need to do so that your product can succeed?
It makes sense that one of the first things you should do is calculate the average price per glass in order to profit. Your selling price shouldn’t deviate from that of your competitors unless you sell a really fancy product with lots of special ingredients. Another insight may be that you have to adjust your lemonade recipe to be as sweet or as tangy as the average customer prefers. You may also want to guess how much lemonade you’d sell in summertime as opposed to springtime, when demand for a cool drink is lower.
Believe it or not, simple processes like these relate to benchmarking—and you may already be doing some variation of them for your API. Like in the example above, it’s important to study your competition in the API industry and figure out the correct formula for your own product. You won’t get it right on the first try, and you’ll have to go through several rounds of trial and error before you’re satisfied. But when you’ve tried out all the possibilities, your idea of the API’s success should eventually become clearer to you.
Now let’s talk about what benchmarking is and what benchmarking means in the context of API development. Let’s also brush up on some quick tips for benchmarking APIs and testing them purposefully on a toolset like Stoplight. Reading up on these should help you set the right benchmarks for your API and truly get it off the ground.
What is Benchmarking APIs?
In the context of business, to “benchmark” something means to see whether it is performing according to a certain standard. When you benchmark something, like a product or a service, you draw a line in the sand and you figure out what’s needed to cross that line.
For application programming interfaces or APIs, it means getting them to perform the best that they can for their intended type of service. You should craft expectations for your API based on how similar APIs in your home industry work. Being too ambitious and over-expectant of your API is a bad thing, but so is under-expecting and setting too low a standard.
Some API developers think that benchmarking can wait until the testing phase. But in truth, the earlier in the design process that you can start benchmarking APIs, the better. Benchmark-setting for your API should ideally include the following:
- What the ideal performance level is for your API.
- What factors can cause your API stress and obstruct its desired performance level.
- The exact metrics you want your API to meet.
- How testable your API is, or how easy the testing process will be for the developer team.
- The tools you use for API testing and evaluating your API’s performance against its benchmarks.
What You Should Remember When Setting Benchmarks for Your API Project
After you’ve considered the abovementioned factors for benchmark-setting, it’s time to embark on the process. Here are some tips that you’ll find useful when it’s time to test, troubleshoot, and monitor your API.
You Should Decide on Your Goals in Advance
Before anything, you must decide on the exact key performance indicators (KPIs) that you’d like for your API to meet. One example is your desired average response time for a particular call. When setting benchmarks like these, consider well-respected API products in your home industry and how they fulfill expectations for their end users. Then, you can consider these as models for your own product.
You Should Look for Performance Benchmarks in Your Chosen Language
Another consideration you have to make is how well your API performs in your preferred programming language. Say for example that you’re building your API with JSON. Consequently, you may want to use a benchmarking tool that allows performance comparison for key tasks like serializing JSON objects.
You Should Simulate the Load of Real Users in Your System
To see if your API will perform up to its benchmarks, try simulating the load it will receive for its intended purpose. During testing, simulate the traffic that you can expect to happen between the client and the server in real-life. Customize your test accordingly so that you get a clear answer on whether your API can perform under the strain.
You Should Test Different Routes
When testing your API, it’s not enough to find just one route that satisfies the benchmark and leave it at that. To unlock an even better experience with your product, test all possible routes that meet the benchmark and look at variations in response length. Take note of the routes that are the fastest and most efficient, and not just a single one that works.
You Should Monitor Your API Project Closely
Don’t forget, benchmarking APIs is not a substitute for monitoring your API. Just because the API hit all its benchmarks doesn’t mean it’ll work seamlessly off the bat. After benchmarking, make sure that you and your fellow developers have monitoring protocols in place. Pay attention not only to your averages, but also to peaks and unpredictable events that result in unpredictable numbers. It would help to make these numbers available on a dashboard for the whole team to see.
Benchmarking will start off with a fairly simple question: “Is my API working the way I want it to?” But there’s a complicated process to arriving at the answer you want. Let this article remind you that benchmarking and testing require a lot of focus, but will increase your chances of launching an excellent API product.
What happens when life gives you the challenge of an API project instead of lemons? As with lemonade, the next logical step is to make the best of what you have.