MyPetParlor App Completes Major Azure Migration for Multi-Tenant Support, Scaling, and Regional Expansion
Published on 1st April, 2024![Hero image for author with name: Luthando A. Vilakazi](https://images.ctfassets.net/pyb53xeqbh60/3GsXgTHO2AFtzKviPCTl0Q/f969275c6b080fa9ae865c58ca378702/image.png?w=400&h=400&q=50&fm=png)
Luthando A. Vilakazi
Author
In a move to optimise for multi-tenant support, improve scalability, and prepare for future regional deployments, the MyPetParlor App team has successfully completed a massive migration of its Azure infrastructure.
![Hero image for article with title: MyPetParlor App Completes Major Azure Migration for Multi-Tenant Support, Scaling, and Regional Expansion](https://images.ctfassets.net/pyb53xeqbh60/7tj3bANIhcMzqQvQPqH9s0/bbbee5196e3f79f8401963470451e742/Blog_Post_-_Feature_Update_7.png?w=750&h=422&q=50&fm=png)
In a move to optimise for multi-tenant support, improve scalability, and prepare for future regional deployments, the MyPetParlor App Azure
Laying the Groundwork: Database Consolidation
Before embarking on the Azure migration, the MyPetParlor App team undertook a critical step: consolidating their databases. Previously, multiple database instances were created, each dedicated to specific tenants or services, posing challenges in terms of operational complexity, resource utilization, and scalability.
By consolidating their databases into a unified PostgreSQL environment the team laid the foundation for a simplified multi-tenant architecture. This involved migrating data from MongoDB to PostgreSQL for a shared service pivotal to the platform's daily operations. The migration was successfully implemented on February 20th, 2024, around 5 PM (GMT), marking the final step in the team's journey away from MongoDB-based services.
Click here
More Groundwork: Row-based Sharding
Previously, the team had a schema-based sharding
To address these scalability limitations and enable more flexibility, the team migrated to a row-based sharding model using the distributed tables capability in Citus. In this new architecture, all tenant data is stored in a shared set of tables with an additional tenant_id column acting as the distribution key. Each table is hash-distributed across nodes based on the tenant_id value, ensuring that all data for a given tenant is co-located on the same nodes for optimal query performance.
This row-based sharding architecture offers several key benefits:
Improved Scalability: The team can now easily scale to hundreds of thousands or even millions of tenants by distributing across more nodes as needed.
Cross-Tenant Queries and Reporting: With all data co-located by tenant_id, complex queries, reporting, and analytics can be performed efficiently across all tenants.
Customization Flexibility: If a tenant requires custom tables or a unique data model, it can be easily provided within their isolated tenant_id data subset.
Row-Level Security: Using the tenant_id column, row-level security policies can be implemented to restrict tenants to only their data.
The migration to the row-based sharding architecture was completed during a scheduled maintenance window on March 16th, 2024, between 12:00 AM and 2:00 AM SAST, breaking through previous scalability limits and allowing the MyPetParlor App to efficiently serve over 1 million customers.
Click here
Optimising for Multi-Tenancy Support: Shared Resources with Tenant Isolation
With the database consolidation complete, the team could proceed with implementing an architecture optimised for multi-tenancy on Azure. This involved adopting the Deployment Stamps pattern
To achieve this, the team implemented several key tasks:
Tenant Identification: A new service was created to handle tenant identification. Constants were defined for tenant ID query parameters and headers, and middleware was implemented to extract the tenant ID from requests and set it in the context.
Database Restructuring: The PostgreSQL database was restructured to support a row-based sharding model using the Citus extension. Each table was modified to include a
tenant_id
tenant_id
.API Updates: All API endpoints were updated to execute the TenantMiddleware and incorporate the tenant ID from the request context into their queries and operations. This ensured that data access and manipulation were scoped to the appropriate tenant.
Benefits of the Migration
The successful migration to the optimised multi-tenant architecture brings several key benefits to the MyPetParlor App platform:
Multi-Tenant Support: MyPetParlor App can now serve multiple tenants from a single running instance, improving resource utilization and enabling more efficient scaling.
Improved Scalability: With shared resources and tenant isolation, MyPetParlor App can scale its infrastructure more efficiently, accommodating growth in user traffic and tenant demand without the need for extensive resource provisioning for each new tenant.
Simplified Operations: By consolidating resources and implementing a centralized tenant management system, the operations team can streamline management and monitoring tasks, reducing the overall operational complexity of the platform.
Regional Expansion Readiness: The new architecture lends itself well to more complex queries and deployments, paving the way for MyPetParlor App's planned expansion into regions like the United States of America and the EU.
The migration was a complex undertaking, involving careful planning, execution, and coordination. The MyPetParlor App team's dedication and expertise in Azure technologies ensured a smooth transition, minimizing downtime and ensuring uninterrupted service for existing users.
Looking Ahead
With the successful completion of this migration, MyPetParlor App is well-positioned to handle increasing demand, support multiple tenants efficiently, and deliver a seamless experience to its growing user base. The team is now focused on leveraging the newly implemented architecture to enhance the platform's capabilities further and prepare for the upcoming launch in the American and EU regions.