case study   |   16 Aug, 2023

How implementing a monorepo reduced the deployable codebase of multi-tenant e-commerce builder

Effortless scalability with one bold move


I'm thrilled to share the journey of how we transformed our multi-tenant e-commerce builder platform to dance effortlessly with scalability and efficiency. As the lead front-end developer, I faced a mammoth challenge that our codebase was growing faster then wildfire as new themes and components were getting created, and deploying each tenant's individual app on AWS EC2 was an expensive operation.

Here's how we flipped the script and made our platform a lean, mean, scalable machine!

Background

Picture this: Vue.js and Laravel creating this beautiful symphony for our multi-tenant e-commerce platform. The solution is multi-tenant in nature. For each new business that adopts our SaaS as their e-commerce solution, a new tanant gets created on a fresh EC2 instance. But as we added new themes and components, our codebase ballooned. Managing such a large codebase was one issue, and also deploying entire codebases to each tenant's EC2 instance became like inviting everyone to a party but renting a mansion for each guest i.e it was just not sustainable!

The Big Hurdles

Our initial setup used separate instances for each tenant on EC2. However, as our product grew, so did the complexities. We needed a more efficient, scalable solution. The problems at hand were:

  1. Codebase Explosion: Every new theme or component was a brick in our already expanding code wall.
  2. Expensive Deployments: Those individual EC2 instances for each tenant were draining our resources.
  3. Scalability Issue: We needed a solution that could handle hundreds or thousands of components without turning our platform into a digital snail.

 

Solution

I rolled up my sleeves and decided to give our architecture a facelift. Enter the monorepo! everything neatly organized in one place, leveragin a central repository. Plus, I used a private npm registry to package our components as installable goodies. This meant, we could pick and choose which components to install for each tenant, drastically reducing the code baggage on their instances. Since, all of our UI components were saparated in a monorepo and packaged as distrubutables, our core application only handled fundamental operations and worked kind of like a micro-kernal, only responsible for providing basic functions for operating the e-commerce stores.

Implementation

  1. Managing monorepo with Lerna
    We implemented and managed the monorepo using Lerna, a tool built by the developers behind the Babel project, which can help to streamline the npm publishing workflow of monorepo based projects. Depending on the user's selected theme and the selection and organization components, the automated deployment proccess manipulated the package.json to include the packages selected by the user on the frontend and installed those packages from the private npm registry.

  2. Making Vue JS dance
    Remember how in Hogwarts they have those magical paintings that change? Well, I made our platform a bit like that. Vue.js's dynamic component feature became our magic wand. It allowed us to render components on the fly, depending on the theme or what our users fancied.
    <component :is="someDynamicComponent"></component>
    Flexibility at its finest!

Impact

  1. Streamlined Codebase: Through selective component installations, we optimized our deployable codebase, ensuring a more efficient and tailored deployment process.

  2. Cost-Efficient Operations: By reducing redundant deployments, we significantly improved cost-effectiveness, minimizing the resource usage in our deployment infrastructure.

  3. Enhanced Scalability: Our platform's architectural enhancements have fortified it for scalability, enabling seamless integration of new components without compromising performance.

Conclusion

This transformation wasn’t just a quick fix. But it set us up for a brighter future for the application. We’re now more agile, ready to groove even with thousands of new themes and components without sacrificing speed or performance.

Closing Thoughts

This wasn’t just a technical overhaul. it was a game changer. The platform isn’t just about lines of code, it’s about empowering growth, flexibility, and staying ahead in the ever-evolving tech infrastructure.