DialogFlow Cost Optimization for CX
DialogFlow Cost Optimization for CX
A guide on how to reduce cost for Google’s Dialogflow CX Conversational Agent.
Chatbots help businesses improve their customer experience without having to hire additional support staff to disperse information that can be easily made available through a conversational chatbot 24/7 and instead focus on effectively utilizing their support staff to deal with important customer problems or grievances that need human attention.
More importantly, chatbots capable of delivering natural life-like conversational experiences have become far more accessible today with the help of industry-leading AI and NLP-powered solution DialogFlow. The initial version of Dialogflow known as Dialogflow Essentials has been the name of the game since its release in 2017. With foundational building blocks such as agents, intents, context, events, parameters and a host of powerful features one can design an intelligent chatbot catered to their own domain and business needs. In September of 2020, a powerful version of DialogFlow was released known as Dialogflow CX providing a new way of designing and developing conversational chatbots.
In this article, we will talk about common developer pitfalls that you may face while deploying chatbots through Dialogflow CX and solutions that you can adopt to significantly decrease the costs.
What is Dialogflow CX? and How is it Different from Diagflow ES?
DialogFlow CX has brought a breath of fresh air in designing conversational chatbots. The new UI dashboard and the nature of features for designing chatbot agents, such as Flows and Pages make it easier to not only develop a feature-rich and complex chatbot but also visualize the chatbot agent as a graph of connected dots. Dialogflow CX also provides pre-built agents out of the box catering to popular industry domains and use cases. These can be used as-is or modified to one’s own unique business needs. Dialogflow CX is ideal for designing complex chat solutions whereas DialogFlow ES is better suited for simple chatbot use cases.
DialogFlow CX is expensive when compared to Dialogflow ES - that should be expected as you’re also getting access to more powerful features. However, developers, especially when migrating from CX, tend to underestimate the importance of cost optimization from the get-go, only noticing after there is already a significant increase in cloud expenditure. This means, when migrating to Dialogflow CX from ES, it’s important to pay extra attention to resource usage and react quickly. Otherwise, you might have to foot an expensive bill not only when the chatbot solution is live on production but also while developing and testing the chatbot.
Developer Pitfalls We Faced While Designing Chatbots Using CX
At D3V, we have been building and deploying chatbot solutions for our own company. And recently, while making changes to our website, a decision was made - we would migrate from Dialogflow ES to Dialogflow CX for our chatbot solution (which can be found on our website at www.d3vtech.com with orange Dialogflow chatbot icon to the bottom right of the website).
As we were building and testing our chatbot with Dialogflow CX integration, we noticed that our Google Cloud Platform (GCP) costs had skyrocketed. We were made aware of this change very early on in our development thanks to the automation of Programmatic Budget Notifications set up by our DevOps engineering team with integration to send alerts directly to our Slack channel.
One of the most common pitfalls when migrating from Dialogflow ES to CX is not taking the time to understand the different pricing and billing structures in these two services. Because Dialogflow ES is cheaper than Dialogflow CX and does not take up a huge part of our GCP expenditure, we did not notice the change in billing instantly. Due to this, we were creating, on average, 100 DialogFlow CX sessions every day which totalled at least $20 per day. This may seem like a relatively “small” increase in cost but it can quickly compound over time and become quite a big chunk of your total cloud spend.
For instance, the following are two examples of less-than-ideal design choices developers tend to make when they do not fully understand the pricing structure of Dialogflow CX:
Creating new sessions anomalously by sending new session IDs for every request made to Dialogflow CX from the chatbot application
Creating a new session with Dialogflow CX as soon as the website page is loaded even if the user chooses not to engage with the chatbot on the website. For example, on average, we have about 100 unique user traffic to our website every day and that would mean creating about 100 sessions every day which would cost about a minimum of 20$ per day for Dialogflow CX.
Understanding Dialogflow CX Pricing for Text Chat Sessions.
We’ve mentioned that the differences in pricing between Dialogflow ES and CX often takes developers by surprise. However, that’s not to say that Google doesn’t make the differences clear, it does. But there are a few price-related nuances that most developers only realize once they’ve already migrated to CX and their cloud spend has begun rising. Let’s take a quick look at these things.
First of all, each request to Dialogflow CX should have a session ID as the context for the conversation is wrapped around this session ID. Any request that sends a new session ID counts as a new session in Dialogflow CX. And as per the pricing guide for text conversation on Dialogflow CX, it costs $20 for 100 sessions.
Second, a session can have up to 40 requests to Dialogflow CX. This means that the 41st request, even for the same session ID (that was sent for the previous 40 requests), will count as another session with Dialogflow.
Third, a session stays alive for up to 30 minutes from the last request. For example for a given session ID, if only 3 requests were made to Dialogflow initially and a 4th request was made 45 minutes after the initial 3 requests, the fourth request will count towards a new session.
Note: Please review the pricing guide for the latest information on the limits, text and voice chat session Dialogflow CX pricing
Best Practices for Optimizing Dialogflow CX
When migrating from Dialogflow ES to CX, developers might find it hard to adapt their workflow according to CX’s pricing structure. That said, it can be done. We’ve compiled a list of some of the most effective best practices that developers can adopt to build powerful chatbot agents in Dialogflow without breaking the bank:
Only allow the chatbot to create a session with Dialogflow CX once the user intends to use the chatbot by clicking on the chatbot icon.
Associate a user with a session ID. Based on your preference you can choose to save the session ID in the browser’s local storage or session storage. And use the same session ID for each request made by that user to Dialogflow CX. Associating a session ID with a user will also provide you with ammunition to drive analytical information from the user chat data, for instance, you can identify what is the most popular conversational topic among your users.
Associating Session ID per chatbot user also allowed us to gather metrics about our chatbot. For instance, at D3V, we have developed a pipeline to stream information into BigQuery and create an analytics dashboard on Data Studio to gain valuable insights on our chatbot usage.
Adding new features to the chatbots for example integration with Google Calendar or Slack notification etc, always needs frequent testing, updates from the tests and retests of those updates. In such a case it is always better to control the sessionID for the dev or test environment with an environmental variable. This way you ensure that a single session ID is maintained for the dev environment and the session constraints for DialogFlow CX are utilized to the limit to get the maximum value.
Finally, setting up alerts about the costs of GCP services being used will help you identify anomalies and spikes in your expenditure early on and you can make decisions to reduce over-provisioned resources and take actions to optimize utilization of GCP services before the expenditure gets out of hand.
Notification alerts, in general, are useful for keeping a close eye on GCP Services usage costs, especially when you’re using a new service and are wary of excessive costs. It has become a vital tool in our organization where we spin up and down various GCP services on a daily basis.
To put into perspective the importance of these best practices, here at D3V, we managed to reduce our Dialogflow CX expenditure by about 90 percent.
Dialogflow CX offers powerful functionality and control over chatbot agents at an acceptable increase in price. But at the same time, a lack of attention to pricing structure and costs early on in development can lead to hard to spot dev pitfalls. While developers could be more lenient with ES and not see any major changes in their cloud spend, they cannot do the same with CX because it can be less forgiving.
Fortunately, these pitfalls can be dealt with early on while developing the Dialgoflow chatbot. In this article, we have explored the pricing of Dialogflow CX text sessions and best practices that can be adopted to identify these pitfalls early on and ensure a more cost-optimized production setup for your Dialogflow CX while not sacrificing any functionality.
All of this can be achieved and more through taking on an in-house specialist, contractor, consultant or by training your team through different methods - such as technical articles of this sort or free GCP Workshops.