<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mahesh Mahadevan on Medium]]></title>
        <description><![CDATA[Stories by Mahesh Mahadevan on Medium]]></description>
        <link>https://medium.com/@mahesh-mahadevan?source=rss-c8611f2cdfad------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2U32GmdYbJnzBj_m8a4xog.jpeg</url>
            <title>Stories by Mahesh Mahadevan on Medium</title>
            <link>https://medium.com/@mahesh-mahadevan?source=rss-c8611f2cdfad------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 03:41:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mahesh-mahadevan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A multi-tenant chatbot with Dialogflow — Part 2 ( Implementation)]]></title>
            <link>https://blog.chatbotslife.com/a-multi-tenant-chatbot-with-dialogflow-part-2-implementation-79c049393f89?source=rss-c8611f2cdfad------2</link>
            <guid isPermaLink="false">https://medium.com/p/79c049393f89</guid>
            <category><![CDATA[dialogflow]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[conversational-ai]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Mahesh Mahadevan]]></dc:creator>
            <pubDate>Tue, 30 Mar 2021 06:52:07 GMT</pubDate>
            <atom:updated>2021-04-05T13:44:31.643Z</atom:updated>
            <content:encoded><![CDATA[<h3>A multi-tenant chatbot with Dialogflow — Part 2 ( Implementation)</h3><p>This article is a follow-up on my previous <a href="https://blog.maheshmahadevan.com/a-multi-tenant-chatbot-with-dialogflow-aee0d9af77e1">article</a> on multi-tenant-<a href="https://chatbotslife.com/smart-chatbots-and-virtual-assistants-are-coming-591638108933">chatbot </a>with Dialogflow. Here, I am going to describe a step-by-step implementation of a multi-tenant <em>Smart Attendant</em> using Dialogflow described in my previous article.</p><h3>Step 0: Clone my Github repo</h3><p><a href="https://github.com/maheshmahadevan/multi-tenant-chatbot.git">maheshmahadevan/multi-tenant-chatbot</a></p><pre>git clone <a href="https://github.com/maheshmahadevan/multi-tenant-chatbot.git">https://github.com/maheshmahadevan/multi-tenant-chatbot</a></pre><h3><strong>Step 1: Get a Dialogflow account</strong></h3><p>Go and sign up for Dialogflow ES services which offer basic Dialogflow features for free. Details on different offerings, pricing, and link to sign up are present <a href="https://cloud.google.com/dialogflow/docs/editions#es-agent">here</a>.</p><figure><a href="https://www.chatbotconference.com/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e2_KzP64Cta52NyCG5Uwgw.png" /></a></figure><h3>Step 2: Setup Agent and Intents</h3><p>Once you have an account, you will need to set up an Agent, Intents, and Fulfillment webhook to get this working. In this step, we will cover the creation of the Agent and different Intents required for <em>Smart Attendant</em>.</p><blockquote>Create a new agent and name it. This will also create a new GCP project for you which we will need to use in the future to call our agent via API</blockquote><figure><img alt="Create a new agent and name it." src="https://cdn-images-1.medium.com/max/670/1*Ut1GNtt4h6T7aM6CuEa8wQ.png" /></figure><blockquote>Create a New Intent and name it <em>“SmartAttendant”</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*dypZbUkwPWc6648lhPKlTA.png" /></figure><blockquote>Add an outgoing context to this called <em>“smartattendant-level1”. </em>This context will help initiate our follow up intent.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*NHvD3oKh_Hqd_H0B2Q1vkQ.png" /></figure><blockquote>Fill in an event and training phrase to trigger this Intent. You only need one of them, but for the purposes of this exercise and testing we will add both.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*q-RGN8bqD2P3jNbzGTzVpg.png" /></figure><blockquote>Add a default response to the Intent, ideally if we pass the right data this response should never be returned. Enable webhook call which will invoke the fulfillment API to add the tenant-specific response to this Intent. Details on how to setup fulfillment API are below.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*4jlCTcTfyyqlkU8A3rAeDA.png" /></figure><blockquote>Save the Intent. We need to add two more follow-up Intents. This Intent will serve as an entry point for the caller.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*SQzHne9dhhonl-0c1Wm2jQ.png" /></figure><blockquote>Before creating additional follow-up Intents, let’s create an <strong><em>Entity</em></strong> for Department. <strong><em>Entities</em></strong> are types in Dialogflow that help us extract Parameters from user inputs. In this scenario, we are looking to extract department names such as Sales, Service, etc from user input.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*8g6itCgA--hx-CnWU5uPVw.png" /></figure><blockquote>Next, create another Intent and update the input and output context as shown. Please note the input context for this Intent is same as output context from previous Intent.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*vDJVljgOF5bO9yFG2Jw4Dw.png" /></figure><blockquote>Create two parameters called <strong>level1_dept</strong> and <strong>level2_dept</strong> and link them to the entity <strong>department</strong> we created previously. You can also mark <strong>level1_dept</strong> as a required field and add a default prompt in case it is not provided by user</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*fMqwPUo4FxQPIT96FRG6Tg.png" /></figure><blockquote>Add few training phrases for this Intent and suggest what the department names could be in those phrases. Also, Enable fulfillment webhook for this Intent</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*6mPg8_iIhfWilcHr4aYt2w.png" /></figure><blockquote>Create the next Intent to capture second-level departments when needed. Update the input context accordingly. There is no need for an output context here as this is supposedly our final Intent</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*KwTHKgh0sEu5QQRywgg5Tg.png" /></figure><blockquote>Add the Training phrase and parameters. Please note, in order to carry forward the parameters from previous contexts, Dialogflow expects a “special syntax” in the value field as seen in the screenshot below. You can read in detail about this syntax <a href="https://cloud.google.com/dialogflow/es/docs/intents-actions-parameters#context">here</a>. Just like previous two Intenets, Enable fulfillment webhook on this Intent as well.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*lYNTWIvBIy8cs09ehFSuDQ.png" /></figure><h3>Trending Bot Articles:</h3><blockquote><a href="https://chatbotslife.com/chatbot-trends-report-2021-4181eef67dcc">1. Chatbot Trends Report 2021</a></blockquote><blockquote><a href="https://chatbotslife.com/4-dos-and-3-don-ts-for-training-a-chatbot-nlp-model-536f949e21ae">2. 4 DO’s and 3 DON’Ts for Training a Chatbot NLP Model</a></blockquote><blockquote><a href="https://chatbotslife.com/concierge-bot-handle-multiple-chatbots-from-one-chat-screen-3321f785b32a">3. Concierge Bot: Handle Multiple Chatbots from One Chat Screen</a></blockquote><blockquote><a href="https://chatbotslife.com/an-expert-system-conversational-ai-vs-chatbots-6b7c17c99258">4. An expert system: Conversational AI Vs Chatbots</a></blockquote><h3>Step 3: Set up Authentication</h3><p>Please follow the steps mentioned in this <a href="https://cloud.google.com/docs/authentication/getting-started">article</a> to setup GCP authentication for the project. This is required to call <em>Dialogflow</em> agent via REST API from your local machine. You can get the name of the project from the Dialogflow agent dashboard.</p><h3>Step 4: Set up Fulfillment Webhook</h3><p>Enable fulfillment webhook by using the Inline editor checkbox. You can also create a webhook outside of Dialogflow, but this is outside the scope of this article.</p><p>As soon as you enable the Inline Editor on Fulfillment, you will notice a pop-up as illustrated below. What this means is that you will have to set up your billing on the corresponding google cloud project in order to use this functionality. If you only intend to use this project for learning/development purposes, the first 2 million invocations of cloud functions every month are free ( as of 26th March 2021), so you should be covered unless you decide to go beyond that number of invocations. Please refer to their official <a href="https://cloud.google.com/functions/pricinghttps://cloud.google.com/functions/pricing">pricing</a> information page for more details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wd60yHC9ML1pX4VVefvuWw.png" /></figure><p>Once the billing is enabled, copy the <strong>fulfillment-index.js </strong>and <strong>package.json </strong>from <em>multi-tenant-</em><a href="https://chatbotslife.com/10-tips-on-creating-an-addictive-chatbot-experience-b796ea6d1178"><em>chatbot</em></a><em>/fulfillment-api</em> folder of the cloned repository.</p><p>Press Deploy and wait for it to finish the deployment on the GCP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PA7I4seVZFtOH9BIaIMLrg.png" /></figure><h3>Step 5: Invoke Intent Detection Rest API</h3><blockquote>Go to the cloned repository of multi-tenant-chatbot and run <strong><em>npm install </em></strong>command</blockquote><blockquote>Start the server once the <strong><em>npm install </em></strong>command is finished</blockquote><pre>&gt; npm install<br>... ** Wait for the install to finish **</pre><pre>&gt; node server.js<br>Started listening at port - 3000</pre><blockquote>Call the rest end-point to initiate conversation with SmartAttendant.</blockquote><p>The first call will invoke the <em>Smart Attendant </em>using the <em>event</em>. In addition, you will need to also pass a couple of custom payload information for customer identification and the time of the day when this call is initiated. These payload data are in turn forwarded to fulfillment-api webhook which uses them to identify the correct response to be sent back to the user as per the configuration.</p><pre>---<em>First call to initiate Smart Attendant for customer </em><strong><em>abc_car</em></strong><em> during the </em><strong><em>afternoon</em></strong><em> time. Feel free to change the time to </em><strong><em>evening</em></strong><em> to see the response</em>---</pre><pre>curl -X POST -H &#39;Content-Type: application/json&#39; <a href="http://localhost:3000/intent/detectintent">http://localhost:3000/intent/detectintent</a> -d &#39;{ &quot;projectId&quot;: &quot;<strong>&lt;YOUR_GCP_PROJECT&gt;</strong>&quot;, &quot;event&quot;: &quot;SMART_ATTENDANT&quot;, &quot;languageCode&quot; : &quot;en-US&quot;, &quot;payload&quot; : { &quot;fields&quot; : { &quot;customer&quot; : { &quot;stringValue&quot;: &quot;abc_car&quot;, &quot;kind&quot;: &quot;stringValue&quot; }, &quot;time&quot; : { &quot;stringValue&quot;: &quot;afternoon&quot;, &quot;kind&quot;: &quot;stringValue&quot; } } } }&#39;</pre><pre><em>---Response---</em><br>{<br>    &quot;sessionId&quot;: &quot;dfeaacwf-6d7f-4a05-ab3e-da2b98f72c2b&quot;,<br>    &quot;responseText&quot;: &quot;Welcome to ABC Car Dealership, please say in words where you want to redirect your call , for example , say Sales or Connect me to Service&quot;<br>}</pre><p>I am sure you might be wondering what is the relevance of <em>sessionId</em> in the response. <em>SessionId</em> field in the <em>Intent Detection API</em> manages and binds the contexts of Intents over multiple calls. In short, we will need to pass this context in our subsequent call for Dialogflow to bind the query to this session. Any contexts and their parameters stored in the session will be available for fulfillment of the query bound with that specific session.</p><pre><em>---Second call.User wishes to speak to a Sales agent, use the sessionId from first response in the input json. ---</em></pre><pre>curl -X POST -H &#39;Content-Type: application/json&#39; <a href="http://localhost:3000/intent/detectintent">http://localhost:3000/intent/detectintent</a> -d &#39;{ &quot;sessionId&quot;: &quot;<strong>&lt;SESSION_ID_FROM_PREVIOUS_RESPONSE&gt;</strong>&quot;, &quot;projectId&quot;: &quot;<strong>&lt;YOUR_GCP_PROJECT&gt;</strong>&quot;, &quot;query&quot;: &quot;Sales please&quot;, &quot;languageCode&quot; : &quot;en-US&quot;, &quot;payload&quot; : { &quot;fields&quot; : { &quot;customer&quot; : { &quot;stringValue&quot;: &quot;abc_car&quot;, &quot;kind&quot;: &quot;stringValue&quot; }, &quot;time&quot; : { &quot;stringValue&quot;: &quot;afternoon&quot;, &quot;kind&quot;: &quot;stringValue&quot; } } } }&#39;</pre><pre><em>--Response. Since this particular Departments has sub-departments, the intent responds back asking to which specific Sales department does User wish to speak---</em></pre><pre>{&quot;sessionId&quot;:&quot;<strong>&lt;SESSION_ID_FROM_PREVIOUS_RESPONSE&gt;</strong>&quot;,<br>&quot;responseText&quot;:&quot;BMW , Audi or Mercedes&quot;}</pre><pre><em>---Third Call ... User wishes to speak to a Mercedes agent.---</em></pre><pre>curl -X POST -H &#39;Content-Type: application/json&#39; <a href="http://localhost:3000/intent/detectintent">http://localhost:3000/intent/detectintent</a> -d &#39;{ &quot;sessionId&quot;: &quot;<strong>&lt;SESSION_ID_FROM_PREVIOUS_RESPONSE&gt;</strong>&quot;, &quot;projectId&quot;: &quot;<strong>&lt;YOUR_GCP_PROJECT&gt;</strong>&quot;, &quot;query&quot;: &quot;Mercedes&quot;, &quot;languageCode&quot; : &quot;en-US&quot;, &quot;payload&quot; : { &quot;fields&quot; : { &quot;customer&quot; : { &quot;stringValue&quot;: &quot;abc_car&quot;, &quot;kind&quot;: &quot;stringValue&quot; }, &quot;time&quot; : { &quot;stringValue&quot;: &quot;afternoon&quot;, &quot;kind&quot;: &quot;stringValue&quot; } } } }&#39;</pre><pre><em>--- Final Response and completion of Intent, User will be redirected to Mercedes Sales agent. As you can notice, Dialogflow made use of the session data to fill in the level1_dept i.e &quot;Sales&quot; passed in the previous query, in its response. ---</em></pre><pre>{&quot;sessionId&quot;:&quot;<strong>&lt;SESSION_ID_FROM_PREVIOUS_RESPONSE&gt;</strong>&quot;,<br>&quot;responseText&quot;:&quot;Trying to contact someone from Sales in Mercedes&quot;</pre><p>That&#39;s all folks. I hope you liked the above implementation and can find some good use-cases for it. Drop me a note or create a GitHub issue if you see any problems or bugs with the above setup. Enjoy !!</p><h3>Don’t forget to give us your 👏 !</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*ZxaGcKC3UQEydQIX" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F3e59ef%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F3e59ef&amp;image=http%3A%2F%2Fapi.screenshotlayer.com%2Fapi%2Fcapture%3Faccess_key%3Dfe59908dad3baab69ffab249a2224b03%26viewport%3D1024x612%26width%3D1000%26url%3Dhttps%253A%252F%252Fupscri.be%252F3e59ef%253Fscreenshot&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/7078d8ad19192c4c53d3bf199468e4ab/href">https://medium.com/media/7078d8ad19192c4c53d3bf199468e4ab/href</a></iframe><figure><a href="https://chatbotslife.com/bot-communities-mastermind-group-d2dae9876709#.53x0py6ou"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*6XUspT9JOSq0w0Fi35HIaA.png" /></a></figure><figure><a href="https://m.me/ChatbotsLife"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*c1LDMH5vbnIz9rmAka8Hwg.png" /></a></figure><figure><a href="https://chatbotslife.com/chatbot-development-hire-top-ai-chatbot-developers-c8b45ef7f207"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*D0Jf3dI6ZThtqcfwDYY7mg.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79c049393f89" width="1" height="1" alt=""><hr><p><a href="https://blog.chatbotslife.com/a-multi-tenant-chatbot-with-dialogflow-part-2-implementation-79c049393f89">A multi-tenant chatbot with Dialogflow — Part 2 ( Implementation)</a> was originally published in <a href="https://blog.chatbotslife.com/">Chatbots Life</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A multi-tenant chatbot with Dialogflow]]></title>
            <link>https://blog.chatbotslife.com/a-multi-tenant-chatbot-with-dialogflow-aee0d9af77e1?source=rss-c8611f2cdfad------2</link>
            <guid isPermaLink="false">https://medium.com/p/aee0d9af77e1</guid>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[customer-service]]></category>
            <category><![CDATA[dialogflow]]></category>
            <dc:creator><![CDATA[Mahesh Mahadevan]]></dc:creator>
            <pubDate>Wed, 17 Mar 2021 11:40:05 GMT</pubDate>
            <atom:updated>2021-04-05T13:44:28.364Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://chatbotslife.com/smart-chatbots-and-virtual-assistants-are-coming-591638108933">Chatbots </a>and natural language conversational engines are quite ubiquitous nowadays. The success or failure of a business to an extent hinges on the quality of its support teams. Running a 24 x 7 customer support team is a challenging task, in fact, many businesses would prefer to reduce the load on their support teams by offloading frequently asked questions and repetitive support tasks to machines. This can be achieved in numerous ways, ranging from redirecting customers to a FAQ page on their website to using more sophisticated ways like <a href="https://chatbotslife.com/10-tips-on-creating-an-addictive-chatbot-experience-b796ea6d1178">chatbots </a>that can understand human speech, the latter being the subject of this article.</p><p>Everyday support teams end up addressing a wide range of customer queries. Most of the time, these customers are usually looking for something quick and to the point. Eight times out of ten, a simple FAQ page might not be able to cover every scenario that customers end up facing while availing of the service. All of this has to be done on a very tight budget too. Also, it is important to mention the fact that it is in human nature to hear or read a response as if it were coming from another human even if the same response might be illustrated pretty clearly elsewhere. This is where conversational bot engines like Dialogflow can help.</p><p>In this article, I am going to pass on some of my learnings working with Dialogflow. Dialogflow is Google’s NLU platform that can be used to design conversational user interfaces. Dialogflow is quite simple to understand and use if you are familiar with NLU and Intent classification. If you are not too familiar with Intent classification then I suggest reading the following <a href="https://cloud.google.com/dialogflow/docs/basics">articles</a>, but here is a quick introduction of concepts that you will need to understand what is discussed in this article.</p><figure><a href="https://www.chatbotconference.com/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e2_KzP64Cta52NyCG5Uwgw.png" /></a></figure><h3>Keywords</h3><p><a href="https://cloud.google.com/dialogflow/docs/intents-overview"><strong>Intent</strong></a><strong>: </strong>As the article suggests, intent describes the end-users intention for the conversation to take a turn. For example, “What is the weather <strong><em>today</em></strong>?” can be described as a user’s intent to know <strong><em>Today’s</em></strong> weather. Please note, in the above phrase the word <strong><em>today </em></strong>is quite significant as it is a <strong>Parameter</strong> onto which the Intent’s <strong>Action</strong> will be performed and a suitable <strong>Response</strong> will be generated and presented back to the User.</p><p><a href="https://cloud.google.com/dialogflow/docs/contexts-overview"><strong>Contexts</strong></a><strong>: </strong>As the name would suggest, context describes the context for Intent Matching. Contexts help to control the flow of conversations, by setting the <a href="https://cloud.google.com/dialogflow/docs/contexts-input-output">input and output contexts</a>. For example, on matching an intent, you can set an output context which in turn activates the next set of intent in the course of conversation. The application which will be discussing in the article makes use of this concept as well.</p><p><a href="https://cloud.google.com/dialogflow/docs/fulfillment-overview"><strong>Fulfillment</strong></a><strong>: </strong>Dialogflow provides a way to generate a more dynamic response by integrating custom APIs. Intents in Dialogflow have the ability to enable fulfillment, which basically allows routing the intent response generation part to a customized API that you can build and deploy.</p><h3>Trending Bot Articles:</h3><blockquote><a href="https://chatbotslife.com/chatbot-trends-report-2021-4181eef67dcc">1. Chatbot Trends Report 2021</a></blockquote><blockquote><a href="https://chatbotslife.com/4-dos-and-3-don-ts-for-training-a-chatbot-nlp-model-536f949e21ae">2. 4 DO’s and 3 DON’Ts for Training a Chatbot NLP Model</a></blockquote><blockquote><a href="https://chatbotslife.com/concierge-bot-handle-multiple-chatbots-from-one-chat-screen-3321f785b32a">3. Concierge Bot: Handle Multiple Chatbots from One Chat Screen</a></blockquote><blockquote><a href="https://chatbotslife.com/an-expert-system-conversational-ai-vs-chatbots-6b7c17c99258">4. An expert system: Conversational AI Vs Chatbots</a></blockquote><h3>What were we building?</h3><p>So we intended to build a conversational bot using Dialogflow’s NLU platform that could listen to incoming voice calls and redirect them appropriately. Think of this as a replacement for your in-person front desk operator. In addition, this was required to serve multiple tenants at the same time. You could think of this platform as something similar to an IVR that kicks in when you call a company board line but without the irritating <em>“Press 1 for Sales…”</em> but rather relying on NLP to route the call to the correct destination. Let’s call this <strong><em>Smart Attendant</em></strong> for the purposes of the current discussion.</p><p>Let me illustrate how this would work with help of the below <strong>use-case</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*M2y6LJiM-20xB0EjHToCvA.jpeg" /></figure><ul><li>An incoming call comes to the company’s main board line, the call gets routed magically to Smart Attendant <em>( How we route this to Smart Attendant is not really important for the scope of this discussion but it is important to note that the tenant information is passed and available to Smart Attendant )</em></li><li>Smart Attendant kicks off the “event” with a <strong>Welcome Message</strong> and using Dialogflow’s native text-to-speech(TTS) engine this is relayed back on the line. So it could be something like this</li></ul><blockquote>Welcome to ABC Car Dealership, please say the department to which you would like the call to be transferred</blockquote><ul><li>The person on the other end might be interested in purchasing a new car, so they might say something like</li></ul><blockquote>Please connect me to Sales</blockquote><ul><li>Assuming that the ABC Car Dealership has a Sales Department and an extension for connecting to a Sales Executive, Smart Attendant would satisfy the “intent” by redirecting the call to their extension</li><li>We can take this few more levels if needed, for example, if ABC Car Dealership had multiple Sales Departments and each having its own extensions, Smart Attendant would then try to hint customer to provide more information</li></ul><blockquote>Please say which Sales Department would you like to be connected with , Audi , BMW or Mercedes</blockquote><blockquote>Connect me to Audi please</blockquote><blockquote>Sure, Connecting to Audi Sales Department</blockquote><ul><li>This would be the end of our intent and Smart Attendant would redirect the call to Audi’s Sales Department. Please note how Dialogflow remembered the context of the conversation and remembered that caller had requested to be connected to a Sales Department</li><li>As an alternative, you could also imagine if the caller is really familiar with ABC Car Dealership’s departmental structure and wants to be connected to Audi Sales Department, they might probably not want to waste time by exchanging conversations at multiple levels and rather prefer saying something like this</li></ul><blockquote>Please connect me to Audi Sales department</blockquote><blockquote>Sure, Connecting to Audi Sales Department</blockquote><ul><li>Dialogflow received all the required parameters to fulfill the intent in one go and this time it did not respond back to the caller hinting to provide any further information</li></ul><h3>The <strong>Challenge</strong></h3><p>If you take a closer look at the above intent, it heavily relied on some training data specific to <em>“ABC Car Dealership”. </em>Dialogflow must be trained with specific department names of this company and phrases such as <em>“Sales” “Audi” “BMW” “Mercedes”</em> so that it can correctly classify the intent and fill in the parameters. If this was an <em>ABC University</em>, the departments could be something like <em>“Engineering&quot; “Medical” “Computer Science&quot;</em> etc. If you extrapolate this to hundreds of customers and each having their unique data sets and phrases to be fed into the training model, this could easily become a quite daunting task.</p><p>Just to set the context right, <strong>Smart Attendant</strong> was to cater to multiple single-tenanted applications providing <em>Voice Communication as a Service (VCaaS)</em> running on a Kubernetes Cluster. For simplicity, you can imagine each of these <em>VCaaS</em> running as a pod and each pod mapped to a single tenant. Our Smart Attendant solution was supposed to cater to all these tenants.</p><p>Now it could have been possible to create multiple agents in <em>Dialogflow</em>, one for each tenant but then all our <em>VCaaS</em> pod and <em>K8s</em> cluster were part of the same GCP project and for some reason, <em>Dialogflow</em> does not let multiple agents map to the same GCP project.</p><blockquote>On the other hand, it would have been cumbersome to maintain one agent for every customer given the fact that most of our intents would have remained the same for all of them, <strong>so we had to find a way to detect the same intent for multiple customers but vary the responses based on the choice of the tenant.</strong></blockquote><h3>The Solution</h3><p>Adding the training data is not much of a challenge since <em>Dialogflow</em> provides multiple ways of adding the training data to its model. The main challenge was how to ensure accurate classification of intents and their fulfillment specific to each tenant.</p><p>In order to achieve the above, we ended up creating a configuration data model that maps information specific to each tenant and then use this configuration data during intent fulfillment by calling our custom API from <em>Dialogflow</em>. When the call gets routed to <em>Smart Attendant</em>, it is accompanied by the tenant information which in turn is used to fetch the tenant-specific configuration. This configuration would contain all the data required to fulfill the intent. This configuration can be stored in any persistent storage like a backend database or any other configuration solution. Below is an example YAML file of a configuration for a single tenant.</p><pre><strong>- customerName</strong>: ABC Car Dearlership<br>  <strong>message</strong>: Welcome to ABC Car Dealership, please say the department   to which you would like the call to be transferred<br>  <strong>departments</strong>:<br>  - sales<br>  - service<br>  - finance<br>  <strong>department_configuration</strong>:<br>    <strong>sales</strong>:<br>      <strong>message</strong>: Please say which Sales Department would you like to be connected with , Audi , BMW or Mercedes<br>      <strong>departments</strong>:<br>      - <strong>bmw</strong><br>      - <strong>audi</strong><br>      - <strong>mercedes</strong><br>      <strong>department_configuration</strong>:<br>        <strong>bmw</strong>:<br>          <strong>action</strong>: TRANSFER CALL TO extension 1001<br>        <strong>audi</strong>:<br>          <strong>action</strong>: TRANSFER CALL TO extension 1002<br>        <strong>mercedes</strong>:<br>          <strong>action: </strong>TRANSFER CALL to extension 1003<br>    <strong>service</strong>:<br>      <strong>action</strong>: TRANSFER CALL to extension 2001<br>    <strong>finance</strong>:<br>      <strong>action</strong>: TRANSFER CALL to extension 3001</pre><pre>- <strong>customerName</strong> : ABC Health Care<br>  <strong>message</strong>: Welcome to ABC Health Care, please say the department   to which you would like the call to be transferred<br>  <strong>departments</strong>:<br>  - radiology<br>  - oncology<br>  - trauma<br>  - cardio<br>  <strong>department_configuration</strong>: ...</pre><p>The above configuration maintains the following details for every tenant</p><ol><li>Welcome messages</li><li>Department names</li><li>Sub-departments if any</li><li>Action to be taken once the intent is classified</li></ol><p><strong>Smart Attendant </strong>exposes two rest endpoints</p><ol><li>Intent Detection API</li><li>Intent Fulfillment API</li></ol><p>The <em>Intent Detection API </em>is called “magically” by the <em>VCaaS</em> service when a call is received on the respective company board line, whereas the <em>Intent Fulfillment API</em> gets called via Dialogflow’s fulfillment webhook. The detailed flow of events can be understood easily by referring to the below illustration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*74z-a7Z_IUpA-rrsCxLBBA.png" /><figcaption>Image Credit: From <a href="https://cloud.google.com/dialogflow/es/docs/fulfillment-overview">Dialogflow</a> is licensed under <a href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></figcaption></figure><p><em>Intent Detection API</em> call also includes tenant information along with the required details to classify the intent. On a successful match of the intent, Dialogflow will additionally check if there is a fulfillment webhook present on this intent and pass all the relevant data along with tenant details to the fulfillment webhook. Once <em>Intent Fulfillment API </em>receives the tenant information along with other details for intent fulfillment, it uses this to generate tenant-specific responses or actions based on the configuration stored in our database for each tenant.</p><h3>Summary</h3><p>In this article, I have tried to cover how impactful conversational bots can be for a business and the challenges we had to face designing such a conversational NLP engine for multiple tenants leveraging a single <em>Dialogflow</em> agent, and how we addressed it. This concept can be easily extended to any other type of solutions where there are similarities in nature of communication but only the parameters differ, for example — this can be adopted to look into the company directory and re-direct the call to that person or read out a custom message if the person is unavailable, all of this to be mapped uniquely to each tenant.</p><p>Let me know if you do have any feedback or suggestions to improve on this concept or the article itself. Thanks for reading!</p><blockquote><strong>Note</strong>: If you are interested in understanding the implementation of this multi-tenant-<a href="https://chatbotslife.com/10-tips-on-creating-an-addictive-chatbot-experience-b796ea6d1178">chatbot</a>, please take a look at my follow-up <a href="https://blog.maheshmahadevan.com/a-multi-tenant-chatbot-with-dialogflow-part-2-implementation-79c049393f89">article</a> which describes its implementation in detail</blockquote><h3>Don’t forget to give us your 👏 !</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*ZxaGcKC3UQEydQIX" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F3e59ef%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F3e59ef&amp;image=http%3A%2F%2Fapi.screenshotlayer.com%2Fapi%2Fcapture%3Faccess_key%3Dfe59908dad3baab69ffab249a2224b03%26viewport%3D1024x612%26width%3D1000%26url%3Dhttps%253A%252F%252Fupscri.be%252F3e59ef%253Fscreenshot&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/7078d8ad19192c4c53d3bf199468e4ab/href">https://medium.com/media/7078d8ad19192c4c53d3bf199468e4ab/href</a></iframe><figure><a href="https://chatbotslife.com/bot-communities-mastermind-group-d2dae9876709#.53x0py6ou"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*6XUspT9JOSq0w0Fi35HIaA.png" /></a></figure><figure><a href="https://m.me/ChatbotsLife"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*c1LDMH5vbnIz9rmAka8Hwg.png" /></a></figure><figure><a href="https://chatbotslife.com/chatbot-development-hire-top-ai-chatbot-developers-c8b45ef7f207"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*D0Jf3dI6ZThtqcfwDYY7mg.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aee0d9af77e1" width="1" height="1" alt=""><hr><p><a href="https://blog.chatbotslife.com/a-multi-tenant-chatbot-with-dialogflow-aee0d9af77e1">A multi-tenant chatbot with Dialogflow</a> was originally published in <a href="https://blog.chatbotslife.com/">Chatbots Life</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My experiences with API gateways…]]></title>
            <link>https://mahesh-mahadevan.medium.com/my-experiences-with-api-gateways-8a93ad17c4c4?source=rss-c8611f2cdfad------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a93ad17c4c4</guid>
            <category><![CDATA[compare]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[api-gateway]]></category>
            <category><![CDATA[kong]]></category>
            <category><![CDATA[service-mesh]]></category>
            <dc:creator><![CDATA[Mahesh Mahadevan]]></dc:creator>
            <pubDate>Sun, 07 Apr 2019 18:14:16 GMT</pubDate>
            <atom:updated>2019-12-23T13:55:49.290Z</atom:updated>
            <content:encoded><![CDATA[<p>A while back, I was working on a project to implement API gateway for our product’s cloud offering. The main motivation behind it was to have a single point of entry for all the external traffic and safeguarding the back-end services, but there were other reasons too :). I will assume that you have stumbled over this link with prior knowledge on API gateways, if not, you should read about them <a href="https://microservices.io/patterns/apigateway.html">here</a> and <a href="https://www.nginx.com/learn/api-gateway/">here</a> before you go any further into this article.</p><p>Finding an API Gateway that matches your requirement is an <a href="https://en.wikipedia.org/wiki/Overchoice">overchoice</a>, you might eventually suffer a psychological breakdown if you take it personally. Like so many other software stacks prevalent in the industry today, even API gateway comes with a variety of choices and flavors. To be honest, it is quite a struggle when it comes to making this decision without digging a bit deeper into each of these possible options and matching it to your specific requirements. This article is my humble attempt in making this task a little simpler, and provide you with a flowchart at the end of it all, to hopefully arrive at a decision.</p><p>As we began our search, we started evaluating a few options that came up based on our research. To do this, we mainly relied on various comparisons that already exist on the internet, then we shortlisted a few of them based on their current popularity and the feature sets they had to offer.</p><p><strong><em>Disclaimer</em></strong><em> — This article does not provide any sort of performance comparison of API gateways, even though, this was also a criterion on which we based our selection. I do not claim that implementations discussed here are the only options available, but these implementations were the most popular choices based on our product requirements at the time of writing this article.</em></p><h3>Lets list Requirements…</h3><p>First, lets quickly list down what was the minimum that we expected from an API gateway solution. Please note, this is not an exhaustive list or something that might match a solution that you are looking for, but it should cover most of the scenarios where API Gateways are applicable.</p><ol><li><a href="https://en.wikipedia.org/wiki/Reverse_proxy">Reverse Proxy</a> — This is the single most important reason why most projects adopt a gateway sort of a solution. Any mature project, which has opened its APIs to the outside world would avoid exposing its back-end URLs for security reasons and abstracting the complexity of back-end services to client applications. This also gives a single point of entry to all clients accessing back-end APIs.</li><li><a href="https://www.nginx.com/resources/glossary/load-balancing/">Load balancing</a> — Gateways can route a single incoming URL to multiple back-end destinations. This is often useful in micro-services architecture when you want to scale up your application for high-availability or even other-wise if you are running some sort of cluster server setup.</li><li>Authentication and Authorization — Gateways should be able to successfully authenticate and allow only trusted clients to access APIs and also able to provide some sort of authorization layer using something like <a href="https://en.wikipedia.org/wiki/Role-based_access_control">RBACs</a>.</li><li>IP Listing — Allow or Block certain IP addresses to pass through. Provides an additional layer of security to your ecosystem, useful when you discover a malicious set of addresses trying to bring down your application by using DDoS sort of attacks.</li><li>Analytics — Provide a way to log usage and other useful metrics related to API calls. Should be able to disintegrate the API usages made per client for possible monetization.</li><li>Rate-Limiting — Ability to throttle API calls, for example, you only want to allow 10000 calls per minute for all consumers or 1000 calls per month for a particular consumer.</li><li>Transformation — Ability to transform either request and responses<em>(including header and body)</em> before forwarding them further.</li><li>Versioning — An option to use different versions of API at the same time or possibly provide a slow rollout of API in form of <a href="https://martinfowler.com/bliki/CanaryRelease.html">Canary release</a> or <a href="https://martinfowler.com/bliki/BlueGreenDeployment.html">Blue/Green deployments</a></li><li><a href="https://martinfowler.com/bliki/CircuitBreaker.html">Circuit Breaker</a> — Useful with micro-services architecture pattern to avoid disruption in service</li><li><a href="https://en.wikipedia.org/wiki/WebSocket">WebSocket</a> support — Many dynamic and real-time capabilities can be addressed by using WebSockets, providing a WebSocket interface to end clients can really reduce overheads of multiple HTTP calls for frequent data transfers</li><li><a href="https://grpc.io/">gRPC</a> support — Google’s gRPC promises to further reduce load by making use of HTTP/2, can be used efficiently for inter-communication between services. I would recommend this is something you should definitely add to your list of requirements to make your solution future proof</li><li>Caching — Will further reduce the network bandwidth and round trip time consumption and improve performance if frequently requested data can be cached</li><li>Documentation — If you plan to expose your APIs to developers outside of your organization, then you must think about using API documentation such as <a href="https://swagger.io/docs/specification/about/">Swagger or OpenAPI</a>.</li></ol><h3>API Gateways and Service Mesh</h3><p>Before going into comparisons on actual implementations, I must also talk about another pattern which you might run into while looking for gateways, <a href="https://www.nginx.com/blog/what-is-a-service-mesh/">Service Mesh</a>. It might be confusing at first to know the difference between API gateway and Service Mesh and each of their purpose, so I am going to describe them in a little detail before we proceed.</p><p>API gateways are applied on Layer 7 of <a href="https://en.wikipedia.org/wiki/OSI_model">OSI model</a> or you can say to manage traffic coming from outside network ( sometimes also called north/south traffic), whereas Service Mesh is applied to Layer 4 of OSI model or to manage inter-services communications ( sometimes also called as east/west traffic). Some examples of API Gateway features are Reverse Proxy, Load Balancing, Authentication and Authorization, IP Listing, Rate-Limiting, etc.</p><p>Service Mesh, on the other hand, works like a proxy or a side-car pattern which de-couples the communication responsibility of the service and handles other concerns such as Circuit breaker, timeouts, retries, service-discovery, etc. <a href="https://istio.io/docs/concepts/what-is-istio/">Istio </a>is a very well known implementation of service mesh at the time of this article being published.</p><p>You must have noticed that I have included in my list requirements some of the features provided by Service Mesh as well. Quite a few of API gateway implementations today can work at both Layer 4 and 7 and handle requirements of service mesh as well. It would be nice if we could get an implementation which can also handle some of the service mesh requirements even though it is not a must. Here is a good <a href="https://dzone.com/articles/api-gateway-vs-service-mesh">article</a> citing differences between the two in little detail.</p><h3>Comparisons</h3><h3>TL;DR;</h3><p>I am going to compare the following API gateways …<em>(read disclaimer)</em></p><ol><li>NGINX</li><li>Kong</li><li>Tyk</li><li>Ambassador</li><li>AWS API gateway</li></ol><h3>Nginx</h3><p><a href="https://www.nginx.com/">Nginx </a>has been one of the best choices for L7 proxy, load-balancing and creating a single point entry for your back-end applications for quite some time now. It has already been used and tested in many different production environments and has replaced many existing hardware load-balancers with very low footprint and reducing a lot of cost to companies. Lot of <a href="https://en.wikipedia.org/wiki/Content_delivery_network">CDNs</a> use Nginx as their engine for caching data at edge locations.</p><p>The biggest advantage of using Nginx as a gateway is its ability to range from simple to complex features, allowing you to cherry-pick only the required features as you progress. For example, if you only need load-balancing and reverse-proxy, to begin with, Nginx does this very easily with minimal overheads and you can eventually upgrade to other features as your product matures. You can also start with a full blown API gateway using their commercial offering, <a href="https://www.nginx.com/blog/whats-difference-nginx-foss-nginx-plus/">NGINX Plus</a>, even though it is possible to achieve this with its open source offering using its wide range of available plugins.</p><p>Nginx is known for its small footprint and ability to meet high performance with low latency. You also get a lot of <a href="https://www.nginx.com/resources/wiki/modules/">3rd party custom Nginx plugins</a> which can cover a wide range of custom scenarios, and of course, you could always seek help from a huge network of its developer community in case you are stuck somewhere. The only possible cons that you might encounter while working with Nginx is the configuration might be a little difficult to get hang of until and unless you have got your hands dirty working with it, you will have to go over few pages of their documentation till you can claim your mastery over it.</p><h3><strong>Kong</strong></h3><p><a href="https://konghq.com/">Kong</a> is an Nginx and <a href="https://openresty.org/en/">OpenResty</a> based API gateway plus Service Mesh which caters for most of our requirements listed above. It was quite an easy install following the provided <a href="https://docs.konghq.com/install/docker/?_ga=2.29592831.1315225771.1553575126-343588371.1553575126">docker installation instructions</a>.</p><p>Kong architecture is quite simple to understand and is made up of a few components…</p><ul><li>Kong base-module which wraps OpenResty and Nginx and is the engine which does the actual work</li><li>Database layer with choice of Cassandra or Postgres to store all the configuration so it can be retrieved easily in case of failures</li><li>Dashboard which provides User-Interface for API administration and viewing analytics <em>(part of the enterprise offering only, though kong provides REST APIs for managing services, upstream APIs and its consumers )</em></li></ul><p>Kong has both Open-source and Enterprise versions of its implementation, both work very well with sub-millisecond latency as it is powered by nginx itself. Imagine using Nginx for your gateway operations but with REST APIs and database layer for managing configurations easily.</p><p>Kong comes with a variety of <a href="https://docs.konghq.com/hub/?_ga=2.135887729.1315225771.1553575126-343588371.1553575126">plugins</a>, which can cater for most of your crosscutting concerns ranging from access controls, security, caching to documentation. It also lets you write and use custom plugins using Lua language. Kong open-source is a good start to get familiar with their stack. Though it does not come with a Web-UI dashboard, there are few open source dashboards available which help you manage its configuration, otherwise if you are quite comfortable with REST you can work with their <a href="https://docs.konghq.com/1.1.x/admin-api/">admin APIs</a> directly.</p><p>Kong can also be deployed as <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/">Kubernetes Ingress</a> and supports gRPC and Websockets proxy. Kong’s advantage is its underlying engine is made up of lightweight yet powerful Nginx + OpenResty engine, which in itself can be built as a full-fledged API gateway. You can think of Kong as an auto-shift version of Nginx. A possible disadvantage of their implementation is not all the features come out-of-box, rather has to be manually configured by activating each of its respective plugins, which might need initial setup time and resources, but then this might not really a big hurdle for a lot of mature engineering teams.</p><h3>Tyk</h3><p><a href="https://tyk.io/">Tyk</a> is another open-source gateway which promises excellent performance and is created in Go programming language. Tyk offers multiple features which are part of our requirements list and beyond. Tyk’s web dashboard is one of the best in class and lets you control almost all aspects of API configuration provides excellent analytics of API usages.</p><p>Tyk has a rich feature set along with nice Web-UI dashboard making it a good choice for projects having a complicated API management scheme. What makes Tyk stand out is it includes API dashboard, analytics, security, versioning, developer portal, rate-limiting and other gateway features out-of-box for free if you only intend to use this for non-commercial purpose. However, for commercial usage, you will need to buy their commercial license which also includes support.</p><p>Tyk can be really a good fit for projects looking for these features out-of-box from day one and are ready to spend for it<em>(i.e you are planning to use it for commercial purpose)</em>, rather than explore options such as Nginx and Kong which can take little bit of your developers time to get all the required features working. Where Tyk falls short in comparison to the previous two implementations, are ease of installation and cost. Tyk has too many components which do not make it that easy to install and manage on-premise. It also has a cloud and hybrid installation options which decreases installation and management overheads, but then it comes with its own pricing and increases your project costs.</p><h3>Ambassador</h3><p><a href="https://www.getambassador.io/">Ambassador</a> is an open-source, Kubernetes native microservices gateway built on top of <a href="https://www.envoyproxy.io/">Envoy</a>. It can be used as Kubernetes Ingress and load balancer and is built to publish and test microservices easily and rapidly on top on Kubernetes environment.</p><p>Ambassador is very lightweight and all of its states is stored in Kubernetes, so there is no need for a database. Ambassador was built keeping the developer in mind, so all of its operations and concepts are more developer-centric, for example - the most recommended technique for adding a route on Ambassador is via annotations on Kubernetes services yamls. Its free version comes with features such as versioning, gRPC, and WebSockets support, Authentication, Rate-Limiting and Integration with Istio to work as Service Mesh, whereas features such as OAuth, single sign-on, JWT authentication, access control policies, and filtering are part of its paid version called <a href="https://www.getambassador.io/pro/">Ambassador Pro</a>.</p><p>Its advantages are its ability to serve large traffic with low footprint and minimal setup configuration on Kubernetes environments, whereas where it lacks is not being as feature rich in comparison to previously discussed gateways as it is missing out-of-box dashboard and integration with analytics which will require some setup.</p><h3>Amazon API Gateway</h3><p><a href="https://aws.amazon.com/api-gateway/">Amazon API gateway</a> is an AWS cloud offering of managed API management which lets you create, publish and manage APIs in a matter of few clicks. You can currently expose REST or WebSocket endpoint, import new APIs using Swagger or Open API, Route your URL to various back-ends including AWS EC2, AWS lambda or even your in premise endpoints. The cost of routing million APIs through the gateway is very low and predictable as there is fixed <a href="https://aws.amazon.com/api-gateway/pricing/">pricing model</a> for a given number of requests <em>(though you should be careful about costs incurred due to external data transfers)</em>.</p><p>AWS API gateway requires no setup as it is all managed, you can quickly create or route APIs in few clicks, secure them using SSL, provide Authentication and Authorization, create API Keys for external clients of your APIs, manage versioning of your APIs and also generate client SDKs if you wish to do so. AWS API gateway really packs a punch with its offering, making it really easy to setup an API gateway in a matter of few minutes. So if you are already on AWS or planning to go to AWS, you must really think about using this gateway as your first choice unless you have some mandatory feature requirements that it cannot fulfill as of yet. The obvious disadvantage being that you might get locked in with AWS service and this dependency might make your migration task to some other framework difficult at a later point in time.</p><h3>Comparison Matrix</h3><p>Here is a summary of feature comparison in the form of a table for above five API gateways.</p><ul><li>Green Tick: Feature is part of its open source version</li><li>Yellow Tick: Feature is only part of its paid version</li><li>Red Cross: Feature not present <strong>yet </strong><em>(visit their respective portals for the current set of supported features)</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*0m4LXv5VZAl2sDzQT-jXGA.png" /><figcaption>Comparison matrix</figcaption></figure><ol><li>Basic features include reverse proxy, load balancing.</li><li>Tyk comes with developer license for non-commercial usages which includes all the features, for production usage, you need to buy their commercial license and it can be installed as Saas or a Hybrid approach.</li><li>Kong Open source edition does not come with its dashboard, but there are <a href="https://github.com/pantsel/konga">third party open source dashboards</a> available which let you manage API and plugins through Web-UI.</li><li><a href="https://www.getambassador.io/user-guide/with-istio/">Ambassador can be installed along with Istio</a> to cover roles of service mesh.</li></ol><h3>Time for Decision</h3><p>Finally, here is a flowchart, I have kept it simplistic on purpose. You should use the below chart alongside the above feature comparison matrix to narrow down your choice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*96rrH7-cdgGxKWmFzLPPNw.jpeg" /></figure><h3>Implementations that are worth mentioning</h3><ul><li><a href="https://docs.apigee.com/">Apigee</a></li><li><a href="https://wso2.com/">WSO2</a></li><li><a href="https://github.com/Netflix/zuul">Zuul</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a93ad17c4c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monitoring docker containers on Windows using Prometheus + Grafana]]></title>
            <link>https://mahesh-mahadevan.medium.com/monitoring-docker-containers-on-windows-using-prometheus-grafana-c32bbb7ed04?source=rss-c8611f2cdfad------2</link>
            <guid isPermaLink="false">https://medium.com/p/c32bbb7ed04</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[grafana]]></category>
            <dc:creator><![CDATA[Mahesh Mahadevan]]></dc:creator>
            <pubDate>Tue, 27 Nov 2018 06:36:56 GMT</pubDate>
            <atom:updated>2018-11-28T06:05:11.004Z</atom:updated>
            <content:encoded><![CDATA[<p>I guess most of us are fans of Docker. But if you happen to be working for an enterprise whose IT department only lends out Windows OS installed laptops, I am sure you have at some point of time gone through the pain of getting Docker installed and working on your windows laptops and possibly failed at it and switched to using a Linux VM or VirtualBox.</p><p>Well, you don’t have to do that anymore. Docker has made its installation really simple on latest Windows OS which contains Hyper-V functionality , i.e either 8 or 10 , only side-effect is that VirtualBox can no longer be used if Hyper-V is functioning. The “cherry on top” is the Enable Kubernetes option shipped with latest Docker CE that lets you get your hands dirty with those kubectl operations you always wanted to try.<em>(Although , you might want to be very careful with the amount of resources that you give for such a setup, as running an single k8s cluster can be resource intensive)</em></p><p>If your experience has been anything close to above and always wanted to get most of your container development stuff working on your local windows environment instead of shared linux VMs <em>( or any other reason that lets you sleep well at night ) </em>, go ahead and get latest Docker setup along with Kubernetes and get going with your development locally.</p><p>Once you have successfully achieved the above, you might also want to monitor your containers and get some feedback on your container performance like cpu and memory consumption. There are many articles and github repos providing various ways of doing this. Some of the most comprehensive ones are listed below. But, if you try to run these as is you will face some issues with Windows environment.Through rest of the blog , I will be sharing my experiences of getting this monitoring setup up and running on windows environment along with few other tweaks required to get that dashboard on your Grafana page.</p><p>If you are only interested in getting this monitoring dashboard up , here is the Github repository which lets you setup dashboard using docker-compose.</p><p><a href="https://github.com/maheshmahadevan/docker-monitoring-windows">maheshmahadevan/docker-monitoring-windows</a></p><h3><strong>TL;DR;</strong></h3><p>Still here … Ok , lets start then</p><p>There are four basic components that could make up Docker Monitoring framework on Windows environment. Stefan Prodan’s blog <em>( in credits section)</em> has an excellent diagram which explains the architecture and flow between these components. I suggest you to read this blog to get a better understanding how these components work together. Until then you can also refer to my humble diagram which attempts to provide a similar understanding of these components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*jYmnFuSH9GHH-vCWP5aZvw.png" /><figcaption>Monitoring framework components and its relation</figcaption></figure><p><a href="https://github.com/google/cadvisor"><strong>cAdvisor </strong></a>is a daemon and monitoring tool which collects and aggregates the resource usage data from containers. But it does not have its own DB to present a time-series information on the resource utilization. This is where <em>prometheus </em>comes in picture.</p><p><a href="https://github.com/prometheus/node_exporter"><strong>node-exporter</strong></a> is similar to <em>cAdvisor </em>, but collects the metrics of hardware and OS from the host machines itself.</p><p><a href="https://prometheus.io/"><strong>prometheus</strong></a><strong> </strong>is an excellent metrics db collection tool which also provides time-series representation of your metrics data with powerful queries and good visualization. Prometheus scrapes ( collects metrics data at regular interval ) data from exposed cAdvisor and node-exporter ports and stores it in its persistent storage. You can also alternatively configure alerts based on your metrics, we will not be going into this part.</p><p><a href="https://grafana.com/"><strong>grafana </strong></a>provides excellent visualization and querying dashboard with lot of pre-existing built dashboards for most of common metrics visualizations. <em>Prometheus </em>also comes with its own visualizations but <em>Grafana </em>takes the visualization and monitoring to the next level and is quite easy to setup.</p><ol><li>In my setup , I have skipped Alert Manager as I had no need for it at the moment. But you can very well follow the instructions in the above links on how to set them up.</li><li>Some of the blogs would suggest mounting “<em>rootfs</em>” volume for <em>cAdvisor </em>and <em>node-exporter </em>containers. Remember , docker in Windows runs inside a Hyper-V MobyLinux VM , If you keep “<em>rootfs</em>” volume mapping on Windows, you will end up with a failure on running your <strong><em>docker-compose up</em></strong> command since <em>rootfs </em>is not available on the Windows docker env. You can safely skip this volume map setting in your docker-compose file for both <em>cAdvisor </em>and <em>node-exporter</em>.</li><li>When using <em>docker-compose</em> you will also need to set another Env variable from your Windows powershell to convert your windows paths present in your docker-compose volume mappings. On your Powershell run this command <em>$Env:COMPOSE_CONVERT_WINDOWS_PATHS=1</em></li><li>I have included couple of Dashboards <em>( updated and customized for windows to receive data from prometheus )</em> for displaying Container and Host metrics. You can find them present inside Grafana folder in my Github project</li></ol><p>Once ready just run <strong><em>docker-compose up</em></strong> on your path. Once all the containers are up and running go-to <a href="http://localhost:3000/">http://localhost:3000</a> for Grafana home <em>( default user/pass : admin/admin)</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*etFu4k3NGOFvG2pjlDd0fg.png" /><figcaption>Grafana Home</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4DoZrcx2zyMl-2OFCQ9R8Q.png" /><figcaption>Grafana Docker Container Dashboard</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NAEO6b_87XkoCGzo42jO7g.png" /><figcaption>Grafana Docker Host Dashboard</figcaption></figure><p>Enjoy…</p><p><strong>Credits</strong></p><p>I went through quite a few blogs and github projects before I could complete this project. But these are some of the projects/blogs which influenced this project the most.</p><ul><li><a href="https://github.com/vegasbrianc/prometheus">vegasbrianc/prometheus</a></li><li><a href="https://stefanprodan.com/2016/a-monitoring-solution-for-docker-hosts-containers-and-containerized-services/">A monitoring solution for Docker hosts, containers and containerized services</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c32bbb7ed04" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Log Aggregation using BEK (Beats , Elasticsearch and Kibana ) stack and Ingest APIs]]></title>
            <link>https://mahesh-mahadevan.medium.com/log-aggregation-using-bek-beats-elasticsearch-and-kibana-stack-and-ingest-apis-3cdd6f997637?source=rss-c8611f2cdfad------2</link>
            <guid isPermaLink="false">https://medium.com/p/3cdd6f997637</guid>
            <category><![CDATA[elk]]></category>
            <category><![CDATA[filebeat]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[kibana]]></category>
            <category><![CDATA[ingest]]></category>
            <dc:creator><![CDATA[Mahesh Mahadevan]]></dc:creator>
            <pubDate>Thu, 02 Aug 2018 05:42:08 GMT</pubDate>
            <atom:updated>2018-08-02T08:34:55.961Z</atom:updated>
            <content:encoded><![CDATA[<p>There are quite a few articles and resources available on the internet when it comes to creating a Log aggregation pipeline using <a href="https://www.elastic.co/elk-stack">ELK </a>stack. For those unfamiliar , ELK stands for <a href="https://www.elastic.co/products/elasticsearch">Elasticsearch </a>, <a href="https://www.elastic.co/products/logstash">Logstash </a>and <a href="https://www.elastic.co/products/kibana">Kibana</a>. <em>(This could be very well called the BELK stack with </em><a href="https://www.elastic.co/products/beats/filebeat"><em>FileBeats</em></a><em> being quite universally used to ship log data from files and fed onto logstash for further processing.)</em></p><p>Quite recently, I had an opportunity to setup a log aggregation pipeline for some of the DEV and QA environments. So far , these environments were simply ignored because expensive alternative solutions like <a href="https://www.splunk.com/">Splunk </a>et al. were reserved for more important UAT and Production environments.</p><p>Having previously done such a setup on an earlier version of Elastic stack , I honestly thought that the only way to do this is via good old FileBeats →Logstash →Elasticsearch →Kibana way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qQbT-o_YbgwuT_X8kMm6mg.png" /></figure><p>But I ran into some hurdles when it came to shipping the logs from my beats daemon to Logstash. The culprit was my Logstash setup, which was done on an Amazon EC2 instance where the only possible ingress communication available to it was good old TCP over port 80. However, the communication between Filebeats and Logstash occurs over lumberjack protocol. For security reasons , all the other ports were blocked unless requested otherwise to be open.</p><p>Well , being a lazy bum that I am , I decided to find alternate routes rather than exploring the opening of additional ports <em>( which required me dealing with the security team and involved lot of explaining ). </em>I started tinkering with the idea of using a reverse proxy on the EC2 instance using <a href="https://traefik.io/">traefik </a>and route the Filebeat data via port 80 onto Logstash. But I soon realised this will not work as I previously mentioned the protocol used between Beats and Logstash was not TCP but Lumberjack.</p><p>This is when I stumbled upon another alternative option provided by Filebeats to ship data directly over to Elasticsearch over TCP and skip using Logstash altogether. Now, some of you might inquire, what about the log filtering functions that Logstash used to provide. This is where the new <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/ingest.html">Ingest Node</a> provided by Elasticsearch comes in handy.</p><p>Ingest Nodes or APIs are like pre-processors that run over every document before they are indexed in Elasticsearch. There are many processors available with ingest apis , but we are interested in <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/grok-processor.html">Grok processor</a> which will allow us transform our unstructured log data into structured format and make it easier for us to search information. This feature allows us to replace most of the functions provided by Logstash for basic log aggregation. For folks unfamiliar with grok, check <a href="http://grokconstructor.appspot.com/?_sm_au_=iVV5bkJQCWW79rHF">this </a>site more information.</p><h3><strong>TL;DR;</strong></h3><h3>Setup</h3><ol><li><strong>Elaticsearch and Kibana</strong> — You can have these installed on an Amazon EC2 instance or any other physical or virtual machine. The setups are shipped in different packaging formats, use the one convenient for you. I usually end up using the .zip format. The hardware requirements for the machine will completely depend upon the usage and the amount of data you need to keep on your stack. For fairly small usages and considering that you will be cleaning the logs every 4–5 days , a m4.xlarge or m4.2xlarge type of Amazon EC2 instance or its equivalent should be good enough with around 20 GB of storage. You can find additional hardware recommendations <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/hardware.html">here</a>. Alternatively , you can also explore <a href="https://aws.amazon.com/elasticsearch-service/">Elasticsearch service</a> on AWS. I eventually ended up with the service option on AWS just because of the simplicity and the scalability it provides. Configuration on these two services is very minimal and almost none if you are using default ports.</li><li><strong>FileBeat</strong> — You will need to have Filebeat installed on every location ( in my case Dev and QA boxes) where the logs are generated. <a href="https://www.elastic.co/downloads/beats/filebeat">Download </a>Filebeat matching your hardware requirements and update the filebeat.yml with the required configuration for your log files. Follow steps mentioned <a href="https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-getting-started.html">here</a> except step 3 which is only required for setting up Filebeat for Logstash. You can also skip the steps to setup Kibana dashboard if you really have no purpose for it at this time. For configuring Filebeat with Elasticsearch follow this <a href="https://www.elastic.co/guide/en/beats/filebeat/current/elasticsearch-output.html">link</a>. Your filebeat.yml should look somewhat like this if you followed the instructions properly.</li></ol><pre>filebeat.prospectors:<br><br>- type: log<br>  enabled: true<br>  paths:<br>    - /path/to/log<br>  fields:<br>    environment: &quot;Dev-101&quot;</pre><pre>output.elasticsearch:<br>  hosts: [&quot;10.20.30.40:9200&quot;]<br>  protocol: https<br>  path: /elasticsearch<br>  index : &quot;application-logs--%{+yyyy.MM.dd}&quot;</pre><pre>setup.template.name: &quot;application-logs&quot;<br>setup.template.pattern: &quot;application-logs-*&quot;</pre><p>Few points to note …</p><blockquote><strong>Custom Fields </strong>— Don’t forget to add your custom fields, like fields.environment added in the example above. This will help you differentiate log data coming from different locations</blockquote><blockquote><strong>Multiline </strong>— You can manage multiline log messages from within filebeat.yml itself. These are quite useful and mostly required for many log formats. You can find examples and instructions for setting the same <a href="https://www.elastic.co/guide/en/beats/filebeat/current/multiline-examples.html">here</a>.</blockquote><blockquote><strong>Load index template</strong> — One of the configuration steps involve <a href="https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-template.html">loading index template onto Elasticsearch</a>. If the Elasticsearch output is enabled in filebeat.yml , Filebeat will automatically load the template file, but in case you like to have a different index name , you have to change the value at certain places in the configuration. In our example above we have updated the index name to “application-logs-*”</blockquote><p>3. <strong>Ingress Grok Processor </strong>— The last piece of the puzzle is to add <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/grok-processor.html">Grok processor</a> to make our log data structured. Elasticsearch provides simple <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/ingest-apis.html">REST apis</a> for configuring Ingest processors. Using the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/put-pipeline-api.html">PUT Pipeline API</a> you can create a new pipeline and define a Grok Processor within the same.<em>( A pipeline is nothing but a series of processors , which are executed in the order of their definition. )</em></p><pre>PUT _ingest/pipeline/my_pipeline</pre><pre>{<br>  &quot;description&quot; : &quot;My pipline for log data&quot;,<br>  &quot;processors&quot;: [<br>    {<br>      &quot;grok&quot;: {<br>        &quot;field&quot;: &quot;message&quot;,<br>        &quot;patterns&quot;: [&quot;%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}&quot;],</pre><pre>        &quot;trace_match&quot; : true<br>      }<br>    }<br>  ]<br>}</pre><p>You can have multiple grok expressions in “patterns” field, but the processor will exit on the first match and use this pattern to structure your data. I also suggest setting the trace_match property to identify which of the grok expressions matched the message data in case you have multiple patterns. Use the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/simulate-pipeline-api.html">Simulate pipeline API</a> in order to test your processors against sample message data.</p><p>Once your pipeline is working , there is one more configuration required to be updated on your filebeat.yml. You need to add pipeline name created above in the yml file as shown in example below along with previous configurations.</p><pre>output.elasticsearch:<br>  ...<br>  pipeline: my_pipeline</pre><p>Go ahead and start your Elasticsearch and Kibana. Run Filebeat using below command…</p><pre>sudo ./filebeat -e -c filebeat.yml -d &quot;*&quot;</pre><p>As soon as it starts, you should be able to see data being sent to Elasticsearch in batch mode. Filebeat has very low cpu and memory footprint, so you do not have to worry about letting this run as a background process on your machines.</p><p>You can optionally install <a href="https://chrome.google.com/webstore/detail/elasticsearch-head/ffmkiejjmecolpfloofpjologoblkegm">Elasticsearch head chrome plugin</a> to check index and documents created on Elasticsearch.</p><p>Finally, open up the Kibana dashboard and follow the instructions mentioned <a href="https://www.elastic.co/guide/en/kibana/6.3/connect-to-elasticsearch.html">here</a> in order to configure index pattern. The name of the index pattern you will need to search will be same as what you mentioned in your filebeat.yml.</p><p>Excellent !! you are all set to <a href="https://www.elastic.co/guide/en/kibana/6.3/discover.html">discover</a> and search your log data in a single place rather than looking over at multiple locations.</p><p>Thats it folks ! Add comments or send me suggestions on how to improve this article.</p><p>Additional reading — <a href="https://dzone.com/articles/elasticsearch-ingest-node-vs-logstash-performance-2">Performance comparison between using Ingest API and Logstash</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3cdd6f997637" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>