{"id":24835,"date":"2021-04-13T15:10:28","date_gmt":"2021-04-13T23:10:28","guid":{"rendered":"https:\/\/www.spokeo.com\/compass\/?p=24835"},"modified":"2022-04-13T12:23:43","modified_gmt":"2022-04-13T20:23:43","slug":"node-microservice","status":"publish","type":"post","link":"https:\/\/www.spokeo.com\/compass\/node-microservice\/","title":{"rendered":"Rails rendering is slow \u2013 We use a Node microservice to achieve greater site performance"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"><strong>The need for speed<\/strong><\/h3>\n\n\n\n<p>People tend to be impatient. If a delay is introduced into any process, whether it be driving on the road or being placed on hold, a person&#8217;s satisfaction goes down. The same holds true for the internet.&nbsp;<\/p>\n\n\n\n<p>According to research by Google, <a href=\"https:\/\/www.marketingdive.com\/news\/google-53-of-mobile-users-abandon-sites-that-take-over-3-seconds-to-load\/426070\/\">53% of site visits are abandoned if pages take longer than 2 seconds to load<\/a>, and a 2-second delay in load times result in abandonment rates of up to 87%.<\/p>\n\n\n\n<p>On top of customer satisfaction, search engine rankings are heavily impacted by site performance. Getting ranked higher than your competitors equates to more visibility and more revenue. This is why we constantly strive to improve Spokeo\u2019s tech stack and get our pages to load as fast as possible.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Where it all began<\/strong><\/h3>\n\n\n\n<p>Spokeo has been using Ruby on Rails (RoR) since 2006 to serve it\u2019s massively-scaled dynamic website with billions of unique URLs.&nbsp;<\/p>\n\n\n\n<p>Rails is a model\u2013view\u2013controller (MVC) framework, providing default structures for a database, a web service, and web pages.&nbsp; By using Rails, you can stand up a new website very quickly. It\u2019s very developer friendly and allows for quick turnaround time from an idea\u2019s inception to its implementation. &nbsp; As one of the most popular MVC frameworks, Rails should be applauded for its role in bringing Spokeo to where we are today.&nbsp;<\/p>\n\n\n\n<p>However, RoR has some drawbacks as well:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The web server\u2019s boot speed is incredibly slow.<\/li><li>The built-in rendering engine performs poorly.<\/li><li>Ruby is bad at multithreading.<\/li><\/ul>\n\n\n\n<p>These bottlenecks are not significant when compared to the valuable time savings for developers when creating an application \u2013&nbsp;however they start to become an important constraint as a website becomes mature, full-featured, and heavily-trafficked.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>The Crux of the problem<\/strong><\/h3>\n\n\n\n<p>HAML.&nbsp; When spoken out loud it sounds delicious.&nbsp; This HTML Abstraction Language is the RoR standard that Spokeo has historically used to build its web page templates.&nbsp; This worked as a solution for a long time.&nbsp; However, as the HAML templates got more complex, the slower our pages became. We noticed that there was a linear increase in render times as the number of partials (template files included from within other template files) increased in our HAML templates. For example, a template would have the following: layout \u2192 header \u2192 content(table, loop \u2192 row partial) \u2192 footer<\/p>\n\n\n\n<p>All of this could easily translate into 20-30 partials.&nbsp; As more page elements get added, the page slows down further.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/BKHe8GXpHfUySGa2U4yqlc6ghZIrB-CtXxt2PNLq6FTWHpQ-qxPu2EdXtLD8aVzM79oy2nRPkXeT7gn5bXJwgZzBkVDP83EFLh6VITO0sWRdNYJfMmHkUnDgRgTOTHL48v3VfU9J\" alt=\"\"\/><\/figure>\n\n\n\n<p>[Caption]: Photo by Radowan <a href=\"https:\/\/unsplash.com\/photos\/cYyqhdbJ9TI?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditShareLink\">Nakif Rehan<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Performance<\/strong><\/h3>\n\n\n\n<p>Ruby is not thread safe.&nbsp; The Rails framework protects us from this fact by wrapping everything in a giant mutex lock. In order to serve the high demands of web traffic, we turn to multiple processes. After a while it becomes inefficient to scale.&nbsp; You\u2019re spending a ton of time spawning new processes which use up precious system resources.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Solution<\/strong><\/h3>\n\n\n\n<p>We want to improve webpage rendering times, but we don\u2019t want to throw the baby out with the bathwater.&nbsp; Spokeo leverages much of the Rails framework, and we exhaustively benchmarked all parts of our application. After years of refinements, we determined that the final and best opportunity lied in swapping the \u2018View\u2019 part of Rails MVC with something faster. Let&#8217;s use Node.js!<\/p>\n\n\n\n<p>There are many advantages to using Node.js:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Non blocking I\/O<\/li><li>Excellent asynchronous request handling<\/li><li>Low memory footprint<\/li><li>Smarter caching<\/li><li>Superior connection handling capability (a result of the above factors)<\/li><\/ul>\n\n\n\n<p>By using Node.js and leveraging React to render our pages we can have our cake and eat it too.&nbsp; And so we built an internal microserver for rendering, code-named \u201cSalsa\u201d.<\/p>\n\n\n\n<p>Salsa is a Node app which leverages React to render pages. &nbsp; What we discovered after our testing is that the render time did not increase linearly with the number of components on the page, unlike HAML.<\/p>\n\n\n\n<p>Now we get to keep the slick Model and Controller aspects of Rails while using the superior speed of Node.js for the View, and we can boost our site performance and scale more requests!&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The need for speed People tend to be impatient. If a delay is introduced into any process, whether it be driving on the road or being placed on hold, a&hellip;<\/p>\n","protected":false},"author":88,"featured_media":24836,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[722],"tags":[],"class_list":["post-24835","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tech-blog"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Rails rendering is slow \u2013 We use a Node microservice to achieve greater site performance | Spokeo<\/title>\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.spokeo.com\/compass\/node-microservice\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Rails rendering is slow \u2013 We use a Node microservice to achieve greater site performance | Spokeo\" \/>\n<meta property=\"og:description\" content=\"The need for speed People tend to be impatient. If a delay is introduced into any process, whether it be driving on the road or being placed on hold, a&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.spokeo.com\/compass\/node-microservice\/\" \/>\n<meta property=\"og:site_name\" content=\"The Compass Blog | Digital Identity and People Search | Spokeo\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Spokeo\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-13T23:10:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-13T20:23:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/www.spokeo.com\/compass\/image\/Blue-Grey-2-2260x1160-1-scaled.jpg?fit=800%2C411&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"411\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Olivia Tighe\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Spokeo\" \/>\n<meta name=\"twitter:site\" content=\"@Spokeo\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Olivia Tighe\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.spokeo.com\/compass\/node-microservice\/\",\"url\":\"https:\/\/www.spokeo.com\/compass\/node-microservice\/\",\"name\":\"Rails rendering is slow \u2013 We use a Node microservice to achieve greater site performance | Spokeo\",\"isPartOf\":{\"@id\":\"https:\/\/www.spokeo.com\/compass\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.spokeo.com\/compass\/node-microservice\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.spokeo.com\/compass\/node-microservice\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/www.spokeo.com\/compass\/image\/Blue-Grey-2-2260x1160-1-scaled.jpg?fit=800%2C411&ssl=1\",\"datePublished\":\"2021-04-13T23:10:28+00:00\",\"dateModified\":\"2022-04-13T20:23:43+00:00\",\"author\":{\"@id\":\"https:\/\/www.spokeo.com\/compass\/#\/schema\/person\/79de1b18e01fb71637ea971e65b66b34\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.spokeo.com\/compass\/node-microservice\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.spokeo.com\/compass\/node-microservice\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/www.spokeo.com\/compass\/image\/Blue-Grey-2-2260x1160-1-scaled.jpg?fit=800%2C411&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/www.spokeo.com\/compass\/image\/Blue-Grey-2-2260x1160-1-scaled.jpg?fit=800%2C411&ssl=1\",\"width\":800,\"height\":411},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.spokeo.com\/compass\/#website\",\"url\":\"https:\/\/www.spokeo.com\/compass\/\",\"name\":\"The Compass Blog | Digital Identity and People Search | Spokeo\",\"description\":\"The official Spokeo blog covers topics such as digital identity, consumer protection and privacy, how to avoid scams and catfishing, and more.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.spokeo.com\/compass\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.spokeo.com\/compass\/#\/schema\/person\/79de1b18e01fb71637ea971e65b66b34\",\"name\":\"Olivia Tighe\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.spokeo.com\/compass\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5147448fc308e61aecaa6782b45b69738d5ed842652b02bffc24ca6e0a7a1911?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5147448fc308e61aecaa6782b45b69738d5ed842652b02bffc24ca6e0a7a1911?s=96&r=g\",\"caption\":\"Olivia Tighe\"},\"url\":\"https:\/\/www.spokeo.com\/compass\/author\/olivia\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Rails rendering is slow \u2013 We use a Node microservice to achieve greater site performance | Spokeo","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.spokeo.com\/compass\/node-microservice\/","og_locale":"en_US","og_type":"article","og_title":"Rails rendering is slow \u2013 We use a Node microservice to achieve greater site performance | Spokeo","og_description":"The need for speed People tend to be impatient. If a delay is introduced into any process, whether it be driving on the road or being placed on hold, a&hellip;","og_url":"https:\/\/www.spokeo.com\/compass\/node-microservice\/","og_site_name":"The Compass Blog | Digital Identity and People Search | Spokeo","article_publisher":"https:\/\/www.facebook.com\/Spokeo\/","article_published_time":"2021-04-13T23:10:28+00:00","article_modified_time":"2022-04-13T20:23:43+00:00","og_image":[{"width":800,"height":411,"url":"https:\/\/i0.wp.com\/www.spokeo.com\/compass\/image\/Blue-Grey-2-2260x1160-1-scaled.jpg?fit=800%2C411&ssl=1","type":"image\/jpeg"}],"author":"Olivia Tighe","twitter_card":"summary_large_image","twitter_creator":"@Spokeo","twitter_site":"@Spokeo","twitter_misc":{"Written by":"Olivia Tighe","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.spokeo.com\/compass\/node-microservice\/","url":"https:\/\/www.spokeo.com\/compass\/node-microservice\/","name":"Rails rendering is slow \u2013 We use a Node microservice to achieve greater site performance | Spokeo","isPartOf":{"@id":"https:\/\/www.spokeo.com\/compass\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.spokeo.com\/compass\/node-microservice\/#primaryimage"},"image":{"@id":"https:\/\/www.spokeo.com\/compass\/node-microservice\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.spokeo.com\/compass\/image\/Blue-Grey-2-2260x1160-1-scaled.jpg?fit=800%2C411&ssl=1","datePublished":"2021-04-13T23:10:28+00:00","dateModified":"2022-04-13T20:23:43+00:00","author":{"@id":"https:\/\/www.spokeo.com\/compass\/#\/schema\/person\/79de1b18e01fb71637ea971e65b66b34"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.spokeo.com\/compass\/node-microservice\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.spokeo.com\/compass\/node-microservice\/#primaryimage","url":"https:\/\/i0.wp.com\/www.spokeo.com\/compass\/image\/Blue-Grey-2-2260x1160-1-scaled.jpg?fit=800%2C411&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.spokeo.com\/compass\/image\/Blue-Grey-2-2260x1160-1-scaled.jpg?fit=800%2C411&ssl=1","width":800,"height":411},{"@type":"WebSite","@id":"https:\/\/www.spokeo.com\/compass\/#website","url":"https:\/\/www.spokeo.com\/compass\/","name":"The Compass Blog | Digital Identity and People Search | Spokeo","description":"The official Spokeo blog covers topics such as digital identity, consumer protection and privacy, how to avoid scams and catfishing, and more.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.spokeo.com\/compass\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.spokeo.com\/compass\/#\/schema\/person\/79de1b18e01fb71637ea971e65b66b34","name":"Olivia Tighe","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.spokeo.com\/compass\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5147448fc308e61aecaa6782b45b69738d5ed842652b02bffc24ca6e0a7a1911?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5147448fc308e61aecaa6782b45b69738d5ed842652b02bffc24ca6e0a7a1911?s=96&r=g","caption":"Olivia Tighe"},"url":"https:\/\/www.spokeo.com\/compass\/author\/olivia\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.spokeo.com\/compass\/image\/Blue-Grey-2-2260x1160-1-scaled.jpg?fit=800%2C411&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p8V62u-6sz","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.spokeo.com\/compass\/wp-json\/wp\/v2\/posts\/24835","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.spokeo.com\/compass\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spokeo.com\/compass\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spokeo.com\/compass\/wp-json\/wp\/v2\/users\/88"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spokeo.com\/compass\/wp-json\/wp\/v2\/comments?post=24835"}],"version-history":[{"count":1,"href":"https:\/\/www.spokeo.com\/compass\/wp-json\/wp\/v2\/posts\/24835\/revisions"}],"predecessor-version":[{"id":24837,"href":"https:\/\/www.spokeo.com\/compass\/wp-json\/wp\/v2\/posts\/24835\/revisions\/24837"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.spokeo.com\/compass\/wp-json\/wp\/v2\/media\/24836"}],"wp:attachment":[{"href":"https:\/\/www.spokeo.com\/compass\/wp-json\/wp\/v2\/media?parent=24835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spokeo.com\/compass\/wp-json\/wp\/v2\/categories?post=24835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spokeo.com\/compass\/wp-json\/wp\/v2\/tags?post=24835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}