{
    "componentChunkName": "component---src-pages-blog-markdown-remark-fields-slug-js",
    "path": "/blog/how-we-cut-our-aws-costs",
    "result": {"data":{"markdownRemark":{"html":"<p>In this two part series we will go over SuperTokens manged service infrastructure and the changes we made to cut our AWS billing by more than 50%.</p>\n<p><strong>Part 1: How does the SuperTokens managed service work and why does it need to change.</strong></p>\n<p><a href=\"./how-we-cut-our-aws-costs-part-2/\"><strong>Part 2: Using multi-tenancy to cut our AWS infra costs by more than 50%</strong></a></p>\n<h2 id=\"introduction\" style=\"position:relative;\"><a href=\"#introduction\" aria-label=\"introduction permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Introduction</h2>\n<p>The SuperTokens managed service powers numerous web products, mobile applications, and services and is primarily hosted on AWS. Our infrastructure leverages a suite of AWS tools, including AWS RDS for our database, EC2 instances for SuperToken deployments, and System Manager for instance management and automation. Over time, we’ve refined our deployment cycle to enhance stability, fault tolerance, and cost efficiency but our most recent update has yielded our biggest savings yet, slashing costs by over 50% while achieving <a href=\"https://twitter.com/supertokensio/status/1701600309397852270\" target=\"_blank\" rel=\"nofollow\">record scalability</a>.</p>\n<h2 id=\"what-was-the-supertokens-infrastructure-like\" style=\"position:relative;\"><a href=\"#what-was-the-supertokens-infrastructure-like\" aria-label=\"what was the supertokens infrastructure like permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What was the SuperTokens infrastructure like?</h2>\n<p>To gain a better understanding of the SuperTokens infrastructure, it’s crucial to grasp the deployment cycle.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/23fe31ac9ea589a4ae08d7943018c02c/5c98f/supertokens-deployment-process.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 126.58227848101265%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAZCAIAAAC+dZmEAAAACXBIWXMAABibAAAYmwFJdYOUAAAB0UlEQVQ4y5WUiZLaMAyGef9nbAvLLpA7li3r8BE6dlraLRSymkzGSfSNlF/H7vrIcs7WOhFRVRFB9CHGe7fdQzilRMxdP+wPx64fQogi8gWYa9gSX7U88mY45+yLkXMoIt5TynkrvFqM0Tn3xOExLKLeEzMbA0Uw70OI22Hp+uF0bi6X9nS+DOMUQngNL0u5MzOAnWczz8YYAGtF9QtqxxhVA4BNKamGvEWwGvhKxN4TEVtXWoVFrHP3/OO0iXicZgBomq4fJgPWGHgNX39HXgvriVJK9c2vw2tYVUvO1vXDOBsgYiJe1qy2NAmLENGyLMzl8KxJEH35ReuISwTvSf+qjWpATzEmAAvWOsQ/8FI/i0gIkYgQMcZ016oJEbUOya1hPqUdQtBHzXCLbwwUCXNex3vHzJem7YfxfGkOh2Pb9V03yN0AEtE4TbMxQ5Vwmuac884hHt8/mrb7/mN/eHvvh/HjdEb0/+rHXHz2b9+K23GaK6whcB18sNY6p6rMcj9DouoQx3Fqux6sRfQFXgW71XCp9r/fLuuplm31ebYMPqdd9gl6mmejGhwiM2+Hy2KocvZt2wFYYtkKExVhoJoBKP27PfK6BqWs8XKh9yLyE/oQvQhv5HlRAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"SuperTokens Deployment process\"\n        title=\"SuperTokens Deployment process\"\n        src=\"/static/23fe31ac9ea589a4ae08d7943018c02c/f058b/supertokens-deployment-process.png\"\n        srcset=\"/static/23fe31ac9ea589a4ae08d7943018c02c/c26ae/supertokens-deployment-process.png 158w,\n/static/23fe31ac9ea589a4ae08d7943018c02c/6bdcf/supertokens-deployment-process.png 315w,\n/static/23fe31ac9ea589a4ae08d7943018c02c/f058b/supertokens-deployment-process.png 630w,\n/static/23fe31ac9ea589a4ae08d7943018c02c/40601/supertokens-deployment-process.png 945w,\n/static/23fe31ac9ea589a4ae08d7943018c02c/78612/supertokens-deployment-process.png 1260w,\n/static/23fe31ac9ea589a4ae08d7943018c02c/5c98f/supertokens-deployment-process.png 1283w\"\n        sizes=\"(max-width: 630px) 100vw, 630px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<p>SuperTokens allows users to use the SuperTokens SAAS service in two modes: development and production. Here’s the breakdown of each:</p>\n<p><strong>Development Mode:</strong>\nThe Development mode used to run on an <em>EC2 T3.small</em> instance. To maximize resource utilization, we would deploy up to seven development core instances on the same <em>T3.small</em> instance. This configuration resulted in a remarkably swift setup for new development cores, typically taking a mere 15-20 seconds and was suitable for testing purposes.</p>\n<p><strong>Production mode:</strong>\nIn contrast, the production mode followed a different deployment strategy. Each production mode deployment was hosted on a dedicated <em>EC2 T2.micro</em> instance. This meant that when a new production SuperTokens core instance had to be created, a fresh <em>T2.micro</em> instance was spun up, and docker was installed using System Manager. Consequently, this process required additional time when compared to the development mode, with an average deployment time of around 4-5 minutes.</p>\n<p>For example, if 7 users were to sign up for SuperTokens, it would look like the following:</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/97c3cca9c744960520e2e9d47e8ef148/58a91/supertokens-example-infrastructure.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 59.49367088607595%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAIAAADtbgqsAAAACXBIWXMAABibAAAYmwFJdYOUAAABVElEQVQoz31SWbLcIBDz/Q+aGcCJaeidxSmbF7+ppCr6bCSkXrbzPMeYOcOvnDNAztB7P/9BRbqeoWQofYxV3MYYvXczrxWPDKLaex83FsPdmdnUEKmUqmpmxiy9923OuUhIfBzQ2pftIy6lvEOsFUutISYRLaW+34GIvsVwk1prf4kRKcSESIgU0y4iVyUlEdlaa8wsIu6u5qpGxKr2iEWkIokoswBcsYkZoKja5u4x7QCwqKoWQiKieeNOVH+8AhLVWt8hItFqhPl2LhWZeVHd/f5eP2O/3gGRiDjGxHzHjjuLbGaW0n4ceYmZJcRUKz6zWLO1G4hkZleDqu7tcs4ZmPhrMa0dRxbRR/wASrkiEJ3nuR6vPbv7kQGJRCRnEJE55xP7ARGl/Sf9sbnEc87ee4gpAxDz6xVE9XNVD1R1Hcm3eIzRWhPR+3RcRN3988L+g991GbqGKY1tSAAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"SuperTokens example Infrastructure\"\n        title=\"SuperTokens example Infrastructure\"\n        src=\"/static/97c3cca9c744960520e2e9d47e8ef148/f058b/supertokens-example-infrastructure.png\"\n        srcset=\"/static/97c3cca9c744960520e2e9d47e8ef148/c26ae/supertokens-example-infrastructure.png 158w,\n/static/97c3cca9c744960520e2e9d47e8ef148/6bdcf/supertokens-example-infrastructure.png 315w,\n/static/97c3cca9c744960520e2e9d47e8ef148/f058b/supertokens-example-infrastructure.png 630w,\n/static/97c3cca9c744960520e2e9d47e8ef148/40601/supertokens-example-infrastructure.png 945w,\n/static/97c3cca9c744960520e2e9d47e8ef148/78612/supertokens-example-infrastructure.png 1260w,\n/static/97c3cca9c744960520e2e9d47e8ef148/58a91/supertokens-example-infrastructure.png 1990w\"\n        sizes=\"(max-width: 630px) 100vw, 630px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<h3 id=\"initial-improvements-to-the-deployment-cycle\" style=\"position:relative;\"><a href=\"#initial-improvements-to-the-deployment-cycle\" aria-label=\"initial improvements to the deployment cycle permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Initial Improvements to the deployment cycle</h3>\n<p>One of our initial optimizations focused on reducing the startup time for generating production instances. We recognized that creating a custom <a href=\"https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html\" target=\"_blank\" rel=\"nofollow\">AMI</a>(Amazon Machine Image) pre-installed with Docker alongside the operating system would cut down on start-up time. This change trimmed approximately 45 seconds from the production deployment procedure, reducing the setup time to approximately 3-4 minutes.</p>\n<p>In retrospect, another avenue for improvement that we identified was the usage of <a href=\"https://aws.amazon.com/ec2/pricing/reserved-instances/\" target=\"_blank\" rel=\"nofollow\">AWS Reserved Instances</a>. While this approach would have entailed an upfront cost, it would have resulted in substantial long-term savings.</p>\n<p>So what prompted us to change our deployment process?</p>\n<h2 id=\"why-we-had-to-change-our-deployment-process\" style=\"position:relative;\"><a href=\"#why-we-had-to-change-our-deployment-process\" aria-label=\"why we had to change our deployment process permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Why we had to change our deployment process</h2>\n<p>The past year has been quite a ride for SuperTokens. We released a host of new features and saw a big uptick in users. But, as our user numbers climbed, so did our infrastructure costs. With our AWS credits running out soon, we knew we had to do something to cut our expenses.</p>\n<p>While working on our new multi-tenancy feature, we saw an opportunity to optimize the utilization of our EC2 instances by consolidating our core instances. This would cut down our costs while also providing the expected performance.</p>\n<p>In <a href=\"./how-we-cut-our-aws-costs-part-2\">part 2</a> we will go over the changes we made to achieve this.</p>","frontmatter":{"date":"September 19, 2023","title":"How we cut our AWS costs by more than 50%","cover":"how-we-cut-our-aws-costs.png","author":"Joel Coutinho","description":"Part 1 in a series of  how we were able to cut down our AWS infrastructure costs by more than 50%"},"fields":{"slug":"/how-we-cut-our-aws-costs/"}},"site":{"siteMetadata":{"title":"SuperTokens Blog"}}},"pageContext":{"id":"d5238929-3000-5471-873a-3233c822d76a","fields__slug":"/how-we-cut-our-aws-costs/","__params":{"fields__slug":"how-we-cut-our-aws-costs"}}},
    "staticQueryHashes": []}