{"id":1485,"date":"2017-08-10T10:28:34","date_gmt":"2017-08-10T04:58:34","guid":{"rendered":"https:\/\/www.botreetechnologies.com\/blog\/?p=1485"},"modified":"2020-12-08T12:54:42","modified_gmt":"2020-12-08T07:24:42","slug":"instant-problem-solving-youtube-api-integration-issue","status":"publish","type":"post","link":"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/","title":{"rendered":"Instant problem solving\u200a-\u200aYouTube API integration issue"},"content":{"rendered":"\n<p>While working on an assignment, we came across an urgent task from the customer where we need to fix a performance issue for the YouTube API integration.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is it?<\/h3>\n\n\n\n<p>The Rails app we received had a YouTube integration using <a href=\"https:\/\/github.com\/Fullscreen\/yt\" target=\"_blank\" rel=\"noopener noreferrer\" data-href=\"https:\/\/github.com\/Fullscreen\/yt\">yt gem<\/a>, using which we need to search YouTube videos and fetch metadata &#8211; content details, statistics, status, id etc.<\/p>\n\n\n\n<p>The current implementation was done in such a manner that it takes 12\u201315 seconds to search and find all metadata for 12 videos which is really huge time. We need to reduce this to the limits as per the standards such that it can fetch and render the results in 1\u20133 seconds at max!<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Understand the path followed to identify the issue<\/p><\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">What it <a href=\"https:\/\/github.com\/Fullscreen\/yt\" target=\"_blank\" rel=\"noopener noreferrer\" data-href=\"https:\/\/github.com\/Fullscreen\/yt\">YT&nbsp;Gem<\/a>?<\/h3>\n\n\n\n<p><a href=\"https:\/\/github.com\/Fullscreen\/yt\" target=\"_blank\" rel=\"noopener noreferrer\" data-href=\"https:\/\/github.com\/Fullscreen\/yt\">YT gem<\/a> is a ruby client for YouTube API, which is a wrapper around YouTube API. As per the documentation, they claim that it is better than the original <a href=\"https:\/\/github.com\/google\/google-api-ruby-client\" target=\"_blank\" rel=\"noopener noreferrer\" data-href=\"https:\/\/github.com\/google\/google-api-ruby-client\">google-api-ruby-client<\/a> because ruby client is more generic and YT has been coded better!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Debug Debug Debug &#8230;<\/h3>\n\n\n\n<p>So the first step would be to setup the application, run it and reproduce the issue.<\/p>\n\n\n\n<p>We found that when it throws the search API call, it usually taken 10\u201312 seconds because there are certain API calls which are sent for each video!<\/p>\n\n\n\n<p>So, the flow is as following,<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Search the videos using search term and collect the video ids.<\/li><li>Because we need to find meta data which was somehow not available in the original search call, it has called an API for each video ID to load the meta data. And this was the bottleneck!<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">So, how to fix?<\/h3>\n\n\n\n<p>First of all, We went through the documentation of the YT gem and YouTube APIs and confirmed that what we are trying to fetch is supported by both of them.<\/p>\n\n\n\n<p>We found that though the previous developer doubted that YT gem does not support fetching multiple videos in one API call, it is supported! Based on that we have to fix the code which is using the loop as of now and just make a single API call!<\/p>\n\n\n\n<p>See the code below which has been fixed,<br><script src=\"https:\/\/gist.github.com\/ParthBarot-BoTreeConsulting\/4ed1a71864ff17160bd0db032251036e.js\"><\/script><\/p>\n\n\n\n<p>After this change, the performance of this method has been improved almost by 85-90%! It was taking 10\u201312 seconds for searching videos, which has been now reduced to 1\u20131.3 seconds only!<\/p>\n\n\n\n<p>Sometimes we may miss a very small point, but fixing it could affect the overall flow or performance in a very different manner!<\/p>\n\n\n\n<p><a href=\"https:\/\/www.botreetechnologies.com\/ruby-on-rails-development\"><strong><b>Click here for more<\/b> details&#8230;<\/strong><\/a><\/p>\n\n\n\n<p>At<a href=\"https:\/\/www.botreetechnologies.com\/\"> BoTree Technologies<\/a>, we build enterprise applications with our RoR team of 25+ engineers.<\/p>\n\n\n\n<p>We also specialize in Python, RPA, AI, Django, JavaScript and ReactJS.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/www.botreetechnologies.com\/contact\">Consulting is free<\/a> &#8211; let us help you grow!<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>While working on an assignment, we came across an urgent&#8230;<\/p>\n","protected":false},"author":6,"featured_media":13845,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73,10],"tags":[],"class_list":["post-1485","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ruby-on-rails","category-technology"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Instant problem solving\u200a-\u200aYouTube API integration issue<\/title>\n<meta name=\"description\" content=\"YT gem is a ruby client for YouTube API, which is a wrapper around YouTube API. It is said to be better than the original google-api-ruby-client!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Instant problem solving\u200a-\u200aYouTube API integration issue\" \/>\n<meta property=\"og:description\" content=\"YT gem is a ruby client for YouTube API, which is a wrapper around YouTube API. It is said to be better than the original google-api-ruby-client!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/\" \/>\n<meta property=\"og:site_name\" content=\"BoTree Technologies\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/BoTreeTechnologies\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-08-10T04:58:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-12-08T07:24:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/08\/youtube-api.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1280\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Parth Barot\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@BoTreeTech\" \/>\n<meta name=\"twitter:site\" content=\"@BoTreeTech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Parth Barot\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/\"},\"author\":{\"name\":\"Parth Barot\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1952b3c6679346e5a2792581a67b1b0f\"},\"headline\":\"Instant problem solving\u200a-\u200aYouTube API integration issue\",\"datePublished\":\"2017-08-10T04:58:34+00:00\",\"dateModified\":\"2020-12-08T07:24:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/\"},\"wordCount\":452,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/08\/youtube-api.jpg\",\"articleSection\":[\"Ruby on Rails\",\"Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/\",\"name\":\"Instant problem solving\u200a-\u200aYouTube API integration issue\",\"isPartOf\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/08\/youtube-api.jpg\",\"datePublished\":\"2017-08-10T04:58:34+00:00\",\"dateModified\":\"2020-12-08T07:24:42+00:00\",\"author\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1952b3c6679346e5a2792581a67b1b0f\"},\"description\":\"YT gem is a ruby client for YouTube API, which is a wrapper around YouTube API. It is said to be better than the original google-api-ruby-client!\",\"breadcrumb\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/#primaryimage\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/08\/youtube-api.jpg\",\"contentUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/08\/youtube-api.jpg\",\"width\":1920,\"height\":1280,\"caption\":\"YouTube API integration\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.botreetechnologies.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Instant problem solving\u200a-\u200aYouTube API integration issue\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#website\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/\",\"name\":\"BoTree Technologies\",\"description\":\"Committed to inspire generation.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.botreetechnologies.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1952b3c6679346e5a2792581a67b1b0f\",\"name\":\"Parth Barot\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/parth-barot-150x150.png\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/parth-barot-150x150.png\",\"contentUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/parth-barot-150x150.png\",\"caption\":\"Parth Barot\"},\"description\":\"Parth is the co-founder and CTO at BoTree Technologies. He has worked on building products in different domains and technologies. He is now managing research and pre-sales by supporting it with his problem-solving approach.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Instant problem solving\u200a-\u200aYouTube API integration issue","description":"YT gem is a ruby client for YouTube API, which is a wrapper around YouTube API. It is said to be better than the original google-api-ruby-client!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/","og_locale":"en_US","og_type":"article","og_title":"Instant problem solving\u200a-\u200aYouTube API integration issue","og_description":"YT gem is a ruby client for YouTube API, which is a wrapper around YouTube API. It is said to be better than the original google-api-ruby-client!","og_url":"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/","og_site_name":"BoTree Technologies","article_publisher":"https:\/\/www.facebook.com\/BoTreeTechnologies\/","article_published_time":"2017-08-10T04:58:34+00:00","article_modified_time":"2020-12-08T07:24:42+00:00","og_image":[{"width":1920,"height":1280,"url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/08\/youtube-api.jpg","type":"image\/jpeg"}],"author":"Parth Barot","twitter_card":"summary_large_image","twitter_creator":"@BoTreeTech","twitter_site":"@BoTreeTech","twitter_misc":{"Written by":"Parth Barot","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/#article","isPartOf":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/"},"author":{"name":"Parth Barot","@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1952b3c6679346e5a2792581a67b1b0f"},"headline":"Instant problem solving\u200a-\u200aYouTube API integration issue","datePublished":"2017-08-10T04:58:34+00:00","dateModified":"2020-12-08T07:24:42+00:00","mainEntityOfPage":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/"},"wordCount":452,"commentCount":0,"image":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/#primaryimage"},"thumbnailUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/08\/youtube-api.jpg","articleSection":["Ruby on Rails","Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/","url":"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/","name":"Instant problem solving\u200a-\u200aYouTube API integration issue","isPartOf":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/#primaryimage"},"image":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/#primaryimage"},"thumbnailUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/08\/youtube-api.jpg","datePublished":"2017-08-10T04:58:34+00:00","dateModified":"2020-12-08T07:24:42+00:00","author":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1952b3c6679346e5a2792581a67b1b0f"},"description":"YT gem is a ruby client for YouTube API, which is a wrapper around YouTube API. It is said to be better than the original google-api-ruby-client!","breadcrumb":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/#primaryimage","url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/08\/youtube-api.jpg","contentUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/08\/youtube-api.jpg","width":1920,"height":1280,"caption":"YouTube API integration"},{"@type":"BreadcrumbList","@id":"https:\/\/www.botreetechnologies.com\/blog\/instant-problem-solving-youtube-api-integration-issue\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.botreetechnologies.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Instant problem solving\u200a-\u200aYouTube API integration issue"}]},{"@type":"WebSite","@id":"https:\/\/www.botreetechnologies.com\/blog\/#website","url":"https:\/\/www.botreetechnologies.com\/blog\/","name":"BoTree Technologies","description":"Committed to inspire generation.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.botreetechnologies.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1952b3c6679346e5a2792581a67b1b0f","name":"Parth Barot","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/parth-barot-150x150.png","url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/parth-barot-150x150.png","contentUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/parth-barot-150x150.png","caption":"Parth Barot"},"description":"Parth is the co-founder and CTO at BoTree Technologies. He has worked on building products in different domains and technologies. He is now managing research and pre-sales by supporting it with his problem-solving approach."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/1485","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=1485"}],"version-history":[{"count":1,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/1485\/revisions"}],"predecessor-version":[{"id":13846,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/1485\/revisions\/13846"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/media\/13845"}],"wp:attachment":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=1485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=1485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=1485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}