How to monitor asynchronous 3rd party integrations proactively?
Tags: devops, monitoring
Published: 2023-04-21 04:15:20

> If you'd like to try Dr Droid, [click here](https://app.drdroid.io/signup).

In today's landscape, third-party integrations have become a crucial part of software development. These integrations offer helpful features, new capabilities, and a mashup of services to create useful products. For instance, using SaaS products like [Twilio](https://www.twilio.com/) or [Stripe](https://stripe.com/) saves significant time and resources, and is also non-trivial to be built in-house from scratch. (If you know any tech startup that built these in-house, let me know 😬)

> Leading startups today have upwards of 50+ business critical integrations and an average of 350+ [overall integrations](https://www.saastr.com/the-top-saas-companies-have-an-average-of-350-integrations/).

Microservices rely on external API calls to connect to these services - most of which are asynchronous or moving towards being async. If an external API call is in the flow of a critical business journey or customer experience, it needs proactive monitoring.

To address these issues, businesses need to implement effective third-party integration monitoring strategies. In this article, we will focus on how third-party integration monitoring can help businesses ensure the reliability and availability of services. Furthermore, we will discuss how [Dr Droid](https://drdroid.io) enables you to monitor the functioning of these services and take necessary steps in case of any potential problems.

To understand with an **example**, we are discussing a **food delivery application** use case that you probably use every day.

## Use case: Food Delivery Application

Food delivery services often rely on timely and efficient communication between drivers, dispatchers, and customers. To ensure that deliveries are made on time, it's important to have a reliable and efficient system in place. This is where third-party integrations like IVR can be useful. IVR is an automated interactive voice response system, you often see deployed in call centres.

For instance, imagine a customer who orders a pizza for delivery and waits for it to be delivered piping hot. Timely delivery is important for a good customer experience. Everything is going fine but let’s say the delivery agent is stuck and unresponsive for any reason. This event would risk the timely pizza delivery and the customer will have a poor experience.

## A Sample Third-Party Integration

For the above scenario, a simple flow for this integration could include steps such as detecting the anomaly (i.e., driver not moving from their location), triggering an automated IVR call, prompting the driver to input their reason for the delay, suggesting appropriate actions based on the driver's input, and logging the outcome of the call for future reference.


![Figure 1: Ideal scenario](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zqq0s44k9be0wgixpb75.png)

This is the ideal scenario where the call is initiated and the response is received and required actions are taken but what if no response is received? This will result in delays in taking action and a bad customer experience.

For this, we need monitoring where we can take action even if the response is not received and the entire process would not be affected.

### Monitoring using a Cron Task


![Figure 2: Monitoring using a cron task](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0sclxyso5d7abkzlglg.png)

Let’s understand how we can monitor such integrations effectively to reduce business risk.

The setup described involves a delivery service using an Interactive Voice Response (IVR) system and a Redis database to manage requests. A cron job is set up to trigger a specific action after 20 seconds.

When a customer initiates a delivery request through the IVR system, the request ID and state are stored in the Redis database. This allows the delivery service to keep track of all active delivery requests. Once the request is initiated, a cron job is set up to trigger after 20 seconds.

After 20 seconds, a signal is sent to the delivery service. The delivery service checks the Redis database to see if the request ID is still in the initiated state. If the request ID is still in the initiated state, the delivery service takes appropriate actions, such as updating the request status or sending a notification to the customer.

This setup does have some potential drawbacks while cron jobs can be useful for automating tasks and reducing the need for manual intervention, they do add an additional component to the architecture and increase the overall complexity of the system. This can increase the risk of failure and make it more difficult to identify and troubleshoot issues when they occur.

## How does Dr Droid make the process easier?


![Figure 3: Doing the above process using Dr Droid](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n02kbsgxoo7z789m85xj.png)

The above flow describes a scenario in which a delivery service is using an IVR provider and Dr Droid to monitor the external integration we discussed above using Redis.

When it is found that there is some delay in delivery, the Delivery Service makes an external API call to the IVR provider to take inputs from the Delivery Executive about the reason for the delay and sends a "call initiated" event to Dr Droid. This event notifies Dr Droid that a new call has been initiated.

When the response is received from the Delivery Executive, the IVR provider sends the response back to the Delivery Service and sends a "callback received" event to Dr Droid, which notifies Dr Droid that a callback has been received for the call.

If a callback is not received within 20 seconds, you can set up alerts and webhooks on Dr Droid and it will take care of tracking and executing the recovery flow for delivery service.

Overall, this flow allows the Delivery Service to efficiently manage requests by leveraging the capabilities of the IVR provider and Dr Droid. With Dr Droid, businesses can monitor the performance and anomalies of their business process, receive alerts in case of any disruptions, and set up necessary actions to resolve the issues. The use of event notifications and decision-making processes enables the Delivery Service to handle calls promptly and effectively, while also providing visibility into the call process for monitoring and optimization purposes.

### Setting up the monitoring using Dr Droid

We are using the [API specs](https://docs.drdroid.io/reference/events) and showing how to interact with Dr Droid using the REST API.

An event called `call_initiated` is created.

![](https://lh3.googleusercontent.com/99uVUKJm0A1Q51b32SFSxr1JnDHoLQrVKGJYbqJqBiajYESa2DN9QeAVCT9lHtA04Z_TLHjGi9iaVmc6GXIlJ4QV8foxHTn7wI5HBnLwJKj2vXiCou1smSCneViv_42TwIffUTO1rmWgOYx8kX8ByHs align="left")

<table><tbody><tr><td colspan="1" rowspan="1"><p><em>Figure 3: </em><code>call_initiated</code><em> event created</em></p></td></tr></tbody></table>

Following that, we created another event `callback_received`:

![](https://lh3.googleusercontent.com/-4eVa3fT0xqcMmOQ6FPuj-6aLr4yQx3jNEaFd5TmSqhju3mg-cJU-fOm9bRWGRKHLErVlU3ov2nbUEhskyQMo7QqwpuAHr4rSJcyPmFgmWqxK6XfeRYo8Z7vWnmVs8tcJBRjij033TPlTLD7mx9_qK4 align="left")

<table><tbody><tr><td colspan="1" rowspan="1"><p><em>Figure 4: </em><code>callback_received</code><em> event created</em></p></td></tr></tbody></table>

After creating the event, you can notice in the dashboard:

![](https://lh6.googleusercontent.com/1iW7TPUJu7O1PPxsi6MOkI_i1LUvzIGK6TUCJmeMjAvSd4CSF2GgyBxSU5QbNC2gytYEXNzFE2FzJulludmPdXjDd_7rrzNalbCJyW6pQVW4NbbLjGyJ82vCxzFSw2y6-x5n0zGY_e1uQ2Dg0-YlSH4 align="left")

<table><tbody><tr><td colspan="1" rowspan="1"><p><em>Figure 5: Events on Dr Droid’s dashboard</em></p></td></tr></tbody></table>

We can then set up monitoring in the console to track if a callback is received in x seconds after the call is initiated.

![](https://lh3.googleusercontent.com/D0SiFwkd4i_ugcy-JmZZpEgrftFje2KKvNUC3Co4Evpq6Rb2nm8HSE9DOCuCydtelGnmFurNK6pv-A06yBj2O3awgHNtsu0GqebVkZ7VjFoyrQTe7W9MW5t1fZAAgihUYK-WDkjC7hX0rfYCu7WH-8M align="left")

<table><tbody><tr><td colspan="1" rowspan="1"><p><em>Figure 6: Monitor Dashboard</em></p></td></tr></tbody></table>

![](https://lh4.googleusercontent.com/KSHWT3USugxHActITcI2c2YxF_tS8umASOujfAlJdhy4R0PwvJdmBIgfWv-Z0ljH-oLiD2yxAuN6aK20aT8k4sg4cyHSsdtXjUAtmM8ocgaYKIoXK3RfiFdGXbSIlQZf6ZjZCw-7B-W-iA4blR_OEFY align="left")

<table><tbody><tr><td colspan="1" rowspan="1"><p><em>Figure 7: Selecting primary and secondary events</em></p></td></tr></tbody></table>

Configuring a notification to be triggered if there is a delay in the occurrence of the secondary event despite the primary event being initiated.

![](https://lh4.googleusercontent.com/RcKDlgdvWVp9P7shL8f_m8kPFm4BtoSBHrAbzkj9PQtUMoKYufk0POuvG_L82W2xR4raPhP-81q4zLqBZbZEqx-Whb7L19zAU4B9LN8PLXnMZBrnxaxZMaV1qx0WlbKwNkJwV0zpdI5bkOYE52Idbrw align="left")

<table><tbody><tr><td colspan="1" rowspan="1"><p><em>Figure 8: Setting up an alert</em></p></td></tr></tbody></table>

![](https://lh4.googleusercontent.com/C_d-KSeHai6_-vPI1qPgExN6kY14Fq6R3BUowUB-1ZDwdAKBvdaM45sVIqfhOQjIly44bjvBrzVzm_hUFFeDmepOvJLTFwZ-r_GJB0TmXuZmia4mlzZxN22fpOobeJGA24Xa7oXD_lxxHCCWSKwcWCY align="left")

<table><tbody><tr><td colspan="1" rowspan="1"><p><em>Figure 9: Setting up email notification</em></p></td></tr></tbody></table>

![](https://lh6.googleusercontent.com/AMuqY2bgXbS2cJJ7xbWG8dJ2DRqeFhKefELgsYhQaVlRewhT7cwHK5WtEJntsNz-DZzWtgQd9vSmKwodHhQXL6ZLJYGB6_1a_VT6SeTJk0KVVneOSucmjCJxl3ThOtoeapEqEk-DTqbNnMjBh_5HEwM align="left")

<table><tbody><tr><td colspan="1" rowspan="1"><p><em>Figure 10: Monitoring setup is done</em></p></td></tr></tbody></table>

We are now ready to perform a test.

We will proceed by creating a new event called `call_initiated`

![](https://lh5.googleusercontent.com/3RGB3B6zElpGRxfnQ3x8j1E-VqyQmaYg-trRPF4R3fTv1DVeFuR_UMZWAgnYzpjyRGO1hC9q513Oep_h3z5QGD3CSTZXCAcid9d9QIK8wn5ZkseeVp3EmmnRnKNQGWOrQZYxFMIY2PKoBvuPOMhnY7E align="left")

<table><tbody><tr><td colspan="1" rowspan="1"><p><em>Figure 11: A new event created </em><code>call_initiated</code></p></td></tr></tbody></table>

The primary event was initiated but as we have not yet created the secondary event, `callback_recieved`, an alert notification has been sent.

![](https://lh6.googleusercontent.com/cz-UKQpApYaTcz0F1SidZB3S06oU9rLuIfkzUASszW4_bbKySOy1zSxDYjLPVTnm3-4_UH5ax9G9X_YQv02GJohcNoC6KJEgWJl1jvZFI8HUwNUV2Ky3cv06g4Xa4gsu00FhG0VUB54xL0C9r-F_7I4 align="left")

<table><tbody><tr><td colspan="1" rowspan="1"><p><em>Figure 12: Monitoring dashboard</em></p></td></tr></tbody></table>

An email notification was received stating that the secondary event, "callback\_received", has not been created within a timeframe of 20 seconds.

![](https://lh3.googleusercontent.com/eEoSVnJ9sxVB5lyxxR8lRwRnVWpV4_LPRlg7RPniSaytiLbnmN5MiP3SvjCpX5A3WNorNfI0MCgcIN2J9zZV4h2bL4ZPEALDuUIoSdjzh_q4iaWZ6OYNgR9JMjUtBh0rPo8_SjWMhkkCQ5OEJzkwceI align="left")

<table><tbody><tr><td colspan="1" rowspan="1"><p><em>Figure 13: Email Notification</em></p></td></tr></tbody></table>

![](https://lh3.googleusercontent.com/hdxvc_vsQREggEPGo5s4ZJF_RruuysTFLCpRHFAReNMmG9bnFY1MNxnQ8sb8K9r6zdslglQoMNf-m3jRZhxz7EckyJsanZ5Xh75g42lNrj33j1UnS2MN0smZsHxre5uU1z0tLmLJVZWnzlRHQfm6PGA align="left")

<table><tbody><tr><td colspan="1" rowspan="1"><p><em>Figure 14: Notification on the dashboard</em></p></td></tr></tbody></table>

This makes monitoring the calls easier. If the event is delayed Dr Droid sends notifications via Email/Slack or triggers the configured webhook to take appropriate actions.

## Summary

I hope you have learned the importance of using third-party tools and monitoring them to make the system work reliably and efficiently with some use cases.

Do let us know through comments, how you monitor the external APIs. We will be happy to learn about your use case.

[Sign up](https://app.drdroid.io/signup?ref=blog) for Dr Droid today - it's free up to 1M events/month!