Will JavaScript type annotations kill TypeScript?
The creators of Svelte and Turbo 8 both dropped TS recently saying that "it's not worth it".
Yes: If JavaScript gets type annotations then there's no reason for TypeScript to exist.
No: TypeScript remains the best language for structuring large enterprise applications.
TBD: The existing user base and its corpensource owner means that TypeScript isn’t likely to reach EOL without a putting up a fight.
I hope they both die. I mean, if you really need strong types in the browser then you could leverage WASM and use a real programming language.
I don’t know and I don’t care.
API Management / Observability

Monitoring API Latencies After Releases: 4 Mistakes to Avoid

Ensuring that your APIs are meeting performance requirements as you release new updates depends on correctly monitoring API latencies.
Jul 23rd, 2021 7:14am by
Featued image for: Monitoring API Latencies After Releases: 4 Mistakes to Avoid
Featured image via Pixabay.

Theo Schlossnagle
Theo founded Circonus in 2010, and continues to be its principal architect. He has been architecting, coding, building and operating scalable systems for 20 years. As a serial entrepreneur, he has founded four companies and helped grow countless engineering organizations. Theo is the author of Scalable Internet Architectures (Sams), a contributor to Web Operations (O’Reilly) and Seeking SRE (O’Reilly), and a frequent speaker at worldwide IT conferences. He is a member of the IEEE and a Distinguished Member of the ACM.

In our era of rapid release cycles, engineers make frequent API updates in an effort to constantly improve user experiences. But while updates are designed with user benefits in mind, they can also create new performance issues.

Ensuring that your APIs are meeting performance requirements and service-level objectives (SLOs) as you release new updates depends on correctly monitoring API latencies. In the most basic sense, an API is a programming interface that issues user requests against a remote service, and the API latency is the amount of time required to service each user request.

Monitoring API latencies is complex because thousands, or even millions, of users are making multiple different requests. Engineers must collect and analyze all of this data ongoing — and particularly after each new release — to ensure that updates do not hamper performance. Histograms are the best tool for monitoring API latencies and are commonly used by engineers. Unfortunately, they’re often used incorrectly, leading to incorrect analysis. In this article, I share four common mistakes engineers make when using histograms to monitor API latencies from release to release.

Mistake No. 1: Not Asking the Right Questions

An engineer has several considerations when deciding how to track API latencies. How do you define what’s considered a different or similar request? Should different requests take different amounts of time? Was the request response successful, or was there an error?

You may have a million of these API requests that you have latency numbers for, and you also have other dimensions or subgroups around them. If you’re not a statistician, which most engineers are not, it’s challenging to know which questions to even ask to begin gleaning insights from all of this latency information you’re collecting.

Too often, when comparing API latencies to detect changes between releases, engineers may examine data like the average difference of speed in the 99th percentile. However, this is not providing the type of insight you need. In fact, averages many times result in incorrect conclusions because a few outliers skew the result. When comparing histograms of API latency data from one release to another, more sophisticated questions to ask include:

  • Are the shapes different?
  • Are the concentrations of data different?
  • Do the concentrations of data move?
  • How many concentrations of data does the histogram have?
  • Where are the concentrations of data?

New concentrations of data signal that your new release may have created new workloads because users started making a different request. Or, you have an implementation change in your release that causes certain requests to be serviced in a different way or slower, and so you have a new “bump,” or concentration of data, in your histogram. Whether this workload change was caused by the end user or caused by some lower-level system, it’s a workload change you now need to account for. In the below histogram, the Y-axis represents the sample size and the X-axis represents the sample value (microseconds). The highest point of the “bump” represents the largest concentration of data.

Mistake No. 2: Counting Errors in Overall Latency

New API releases often result in new errors, and errors often occur very fast. A common error we see is that engineers include errors in their latency statistics, and these errors can therefore result in an artificially small latency, leading you to believe you’re meeting service level requirements when in fact you’re not. After all, your SLO is not to serve 99% of all requests under 1 second, but rather all successful requests in under 1 second.

To prevent this error, you should create several histograms: one that includes everything, one that stores only successful requests and one that stores only failed requests, or errors. You may also want histograms that store successful requests for a specific endpoint. This way, you can ensure accuracy of your API latency analysis, then slice and dice your data as needed.

Mistake No. 3: Incorrectly Setting Bin Boundaries

Histograms divide all sample data into a series of intervals called bins. Unfortunately, poor histogram binning is one of the most common mistakes in measuring API latencies and often causes grossly inaccurate analysis.

When analyzing latencies for new API releases, you want to be able to compare current data to historical latency data from previous releases. To do this, all of your histograms across your organization need common bin boundaries. This way, you can aggregate histograms and easily identify changes.

However, it’s common for organizations to use different bin boundaries across their histograms and even change them between releases. Aggregating histograms with different binning degrades the quality of your histograms and therefore the analysis of your data.

At Circonus, we use log linear histograms, which often have logarithmically increasing bin sizes. However, we use this same binning boundary scheme across all of our histograms.

Mistake No. 4: Sampling Rather than Collecting All Data

The hardest problem with measuring API latencies is that people don’t record the data essential for monitoring and analytics. There’s an ongoing argument in the monitoring industry about sampling — that there’s no need to collect all the data. While sampling is OK, it’s not perfect. Obviously if you don’t collect data, then it’s lost forever. Collecting all data is going to enable more accuracy, and with histograms, you can do 100% sampling with relatively no overhead, so there’s no reason not to do so.

For every API you serve, you should measure the latency of every single request on every exposed endpoint. The microservice you talked to? Measure the latency there. The network protocol over which you communicated? Measure the size of every single package sent in each direction. That Cassandra cluster? Measure the client-facing latency, but also measure the I/O latency of every single disk operation on each spindle (or EBS volume, or ephemeral SSD) on each node. It sounds like a lot of data, sure. But we live in the future, and analytics systems are capable of handling a billion measurements per second these days, all the while remaining economical.

The above graph shows the full distribution of every I/O operation on one of our core database nodes at Circonus. The histogram in the breakout box shows three distinct modes: two tightly coupled in the left peak and one smaller mode further out in the latency spectrum. We can also see a radical divergence in behavior immediately following Feb 14 at 9 a.m. As we’re looking at one week of data, each time slice vertically is one hour, 30 minutes. The slice highlighted by the vertical grey hairline is displayed in the upper-left breakout box; it represents nearly 12 million data points alone. The full graph represents about 1.2 billion measurements and fetching that from the Circonus time-series database took just 48 minutes.

Have Confidence in Your Analysis

API updates are designed to make your users happier, but they can often result in new performance issues. Monitoring API latencies after new releases is meant to address this issue, but all too often these mistakes result in inaccurate analysis. As a result, you may have a latency issue and be unaware of it, or think you have a latency issue when in fact you do not. By addressing the above four common issues, you can have more confidence in the accuracy of your analysis and the decisions you make based on it.

Group Created with Sketch.
TNS owner Insight Partners is an investor in: Pragma.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.