Be alerted when your authentication API is slow with Monika: A guide for chaining request

Denny Pradipta
Hyperjump Tech
Published in
4 min readOct 13, 2021
Photo by Cedrik Wesche on Unsplash

Picture this: You are currently maintaining a codebase of one of the largest Telco providers. Every day, people log in to your app to buy their prepaid monthly internet package, redeem their points to get some rewards, or maybe check their monthly bills. Suddenly, your authentication service fails for some reason. Some people managed to log in before it happens, but some didn’t. Logging in takes a long time until your users decided to leave the app. Half of the users just leave quietly, but the rest leaves a one-star rating and a bad review in App Store/Play Store because your users couldn’t log in.

The story is so real it frightens me

Of course, we wouldn’t let that happen if we have some monitoring tools to monitor our service performances. We want to make sure that we have an alert if our authentication service is slow. Even worse, your authentication service is down. That’s where Monika comes in.

Monika always got your back

I have written lots of articles about Monika, but there are always new readers around the block. Monika is an open-source and free synthetic monitoring command-line application. The name Monika stands for “Monitoring Berkala”, which means “periodic monitoring” in the Indonesian language.

With Monika, you can add as many websites as you want to monitor. You can monitor several undesirable events such as service outages or slow services. In addition, you can configure Monika to send notifications of the incidents on your services through your favorite communication tools like SMTP mail, Telegram, WhatsApp (It’s free!), etc.

Without further ado, let’s get started. First, make sure you have installed Monika. As an example, we’re going to be using https://reqres.in to simulate user’s log in flow.

  • We want to hit the /login endpoint with a JSON request body
  • After that, we want to hit an API using the token from the previous request’s response in the Authorization header.

With that said, let’s create the Monika configuration file!

In this configuration, we are going to hit the “login” API and if there are no alerts triggered, it will hit the “get user by user ID” API. Each request will have their own alerts (this is a new feature, by the way) and one global alert to check if hitting any of the API takes you more than ten seconds, then it’s probably your internet. Save the configuration as monika.yml, and run it using monika -c monika.yml

Nicely done.

If you look closely at the screenshot, there was an incident alert sent to the desktop when the login API response time is larger than 600 milliseconds. Then, it sent you the recovery alert sent to the desktop when the login API is back to normal, and it continues to hit the get user by ID API. In this example, I only use Desktop notifications. But you can use another channel such as Microsoft Teams:

Microsoft Teams

But that’s another story for later. Leave a comment if you want to see how I configured Microsoft Teams notifications 😉

Congratulations! You can now keep an eye on your authentication API performance and get alerted when it’s slow using Monika!

Closing

Authentication is a critical service that needs to be online 24/7 without any failures. If you fail to maintain the performance of your authentication service, it could affect your business big time. So, better safe than sorry.

If you’re having a problem with using Monika, don’t hesitate to create an issue on Monika’s Github Issue Page. If you like this article, don’t forget to clap and share this article with your friends!

Also, we are participating in Hacktoberfest 2021 as a maintainer! Feel free to contribute to Monika this month by helping us resolving open issues with the “hacktoberfest” label on it.

That’s it for today, see you next time!

Hyperjump is an open-source-first company providing engineering excellence service. We aim to build and commercialize open-source tools to help companies streamline, simplify, and secure the most important aspects of its modern DevOps practices.

--

--

Denny Pradipta
Hyperjump Tech

Full-stack developer who loves to explore new technologies. Uses MongoDB, Express, React, and Node daily. Regularly writing for Hyperjump Technologies.