In this tutorial, we will guide you through the process of deploying a highly available e-commerce website on DigitalOcean. The design employs a Global Load Balancer (GLB) and Virtual Private Cloud (VPC) peering to maintain seamless connectivity across distributed resources. The website will utilize Next.js for the frontend and Node.js for the backend, ensuring scalability along with load balancing and high availability.
The infrastructure setup involves deploying two droplets located in Frankfurt and San Francisco, all managed under a GLB, with a managed MySQL database configured for high availability in Singapore. VPC peering will facilitate secure communication between the frontend servers and the database.
Prerequisites
Before beginning, ensure you have the following:
- A DigitalOcean account.
- Basic understanding of cloud networking, VPC, and load balancing concepts.
- Multiple droplets created across different regions, fostering high availability.
- A managed MySQL database set up for high availability in your preferred region.
- Familiarity with deploying applications built with Next.js and Node.js.
Architecture Diagram
Step 1 — Deploy Droplets
To enhance redundancy and minimize latency, deploy two droplets—one in Frankfurt and another in San Francisco.
-
Create Droplets: From the dashboard, set up two droplets in different regions with identical specifications for consistent performance.
-
Install Required Software: SSH into each droplet to install necessary software (Node.js and Next.js) and ensure that your e-commerce application is deployed.
Step 2 — Configure MySQL Managed Database with High Availability (HA)
To keep the database accessible during outages, it needs to be set up for high availability.
-
Create Managed MySQL Database: Establish a managed MySQL database with HA enabled to assist with automatic failover and replication.
-
Enable HA: Ensure high availability is configured during the database setup and consider creating a read-only replica in a different availability zone.
-
Configure Security: Set firewall rules allowing access to the MySQL database solely from your droplets.
-
Test Connectivity: Verify database connectivity from both droplets to confirm the application can read and write to the MySQL database.
Step 3 — Set Up the Global Load Balancer (GLB)
Using a GLB is essential for equitable traffic distribution across regions, optimizing performance for users worldwide.
-
Log into the DigitalOcean dashboard and create a GLB that distributes traffic between the droplets located in Frankfurt and San Francisco.
-
Frontend Configuration: Set the frontend to listen on appropriate ports for HTTP or HTTPS traffic.
-
Health Checks: Enable health checks to route traffic to healthy droplets, ensuring service reliability.
-
Configure Load Balancing Rules: Implement rules for traffic balancing, such as least connection or round-robin methods.
-
DNS Configuration: Create DNS records directing your domain to the GLB’s IP address.
Step 4 — Set Up VPC Peering Between Droplets and Managed DB
VPC peering allows private IP communication between your frontend droplets and the managed database.
-
Create VPC Peering: Establish a VPC peering connection in the dashboard between the droplets and the managed database.
-
Update Routing Tables: Modify routing tables for both droplets and the database VPCs to facilitate traffic through the peering connection.
-
Firewalls: Adjust the droplets’ firewalls to permit outbound traffic to the MySQL instance.
-
Test the Connection: Use tools like telnet from the droplets to verify database connectivity via VPC peering.
Step 5 — Deploy the E-commerce App Stack (Next.js + Node.js)
Having set up the infrastructure, you can now deploy the e-commerce application on the droplets.
-
Clone the Application: SSH into each droplet and either clone the repository of your e-commerce app or upload the code directly.
-
Install Dependencies: Ensure that Node.js, npm (or yarn), and other dependencies are installed.
-
Set Up Environment Variables: Configure the necessary environment variables for the frontend and backend.
-
Start the Application: Use a process manager to start both the Next.js frontend and the Node.js backend.
-
Verify Application Functionality: Test functionality of the application across both regions to confirm proper routing through the GLB.
Conclusion
In this tutorial, an e-commerce website has been deployed using a Global Load Balancer and VPC peering. By utilizing cloud-based services such as a managed MySQL database with high availability and establishing multiple droplets in different geographical locations, we have ensured both reliability and performance for a global audience. With secured communication established through VPC peering, a scalable architecture has been achieved, paving the way for resilient and effective global e-commerce applications.
Welcome to DediRock, your trusted partner in high-performance hosting solutions. At DediRock, we specialize in providing dedicated servers, VPS hosting, and cloud services tailored to meet the unique needs of businesses and individuals alike. Our mission is to deliver reliable, scalable, and secure hosting solutions that empower our clients to achieve their digital goals. With a commitment to exceptional customer support, cutting-edge technology, and robust infrastructure, DediRock stands out as a leader in the hosting industry. Join us and experience the difference that dedicated service and unwavering reliability can make for your online presence. Launch our website.