Building a Modern WordPress: Full Stack Serverless WordPress

Introduction:

Full Stack Serverless, as discussed by Lougao, emphasizes pay-for-what-you-use, no fixed monthly costs, and automatic scaling.

“Serverless” is a cloud computing model that empowers developers to build and run applications without the burden of managing underlying servers and infrastructure. Despite its name, “Serverless” doesn’t imply the absence of servers; rather, it signifies that developers are free from concerns about server maintenance, scaling, and management.

In a Serverless architecture, developers can write functions (Functions) or services, automatically triggered by the cloud platform when needed. These functions are typically independent, small code snippets executing specific tasks.

Key features of the Serverless computing model include:

  1. Server Management: Developers are relieved from server management responsibilities as cloud service providers handle the underlying infrastructure.
  2. On-Demand Computing: Functions or services execute on-demand, only activated when necessary, preventing resource wastage.
  3. Elastic Scaling: Cloud service providers automatically scale and shrink computing resources based on workload, ensuring adaptability to changing workloads.
  4. Event-Driven: Functions are often triggered by events such as HTTP requests, database changes, or queue messages.
  5. Pay-As-You-Go Model: Developers are typically billed based on actual function executions or resource usage, avoiding the need to pre-purchase fixed server quantities.

Full Stack Serverless:

The term “Serverless” in Full Stack Serverless refers not only to Serverless Functions but also to products offering Serverless runtime and billing models for various components. These include Serverless Database (Neon, TiDB), Serverless Cache (Upstash Redis, PolyScale), Serverless Queue (Upstash Kafka, QStash), Serverless Storage (AWS S3), and Serverless Compute (AWS Lambda). Developers can leverage these products to build modern, Full Stack Serverless applications.

These products share characteristics such as on-demand billing, no fixed monthly costs (minimum monthly cost is 0), and automatic scaling, making them cost-effective for small or fluctuating workloads. Full Stack Serverless, as discussed by Lougao, emphasizes pay-for-what-you-use, no fixed monthly costs, and automatic scaling.

Advantages of Serverless WordPress over Serverful Solutions:

Modernization:

The popular website-building tool WordPress, born in 2003, initially operated on a monolithic LAMP architecture (Linux, Apache, MySQL, PHP). Over the years, LAMP gained widespread use due to its open-source and cross-platform nature. However, in today’s tech landscape, there is a growing demand for on-demand payment and automatic scaling.

With the introduction of Serverless Function services by AWS, features like request-based billing, scaling to zero, and unlimited scalability have expanded into other software areas like databases and message queues. This allows the construction of Full Stack applications with request-based billing and scaling to zero, providing significant advantages for startups and those who prefer serverless management.

Cost Optimization:

While current perceptions of Serverless often focus on OpsLess (operations-less), Lougao advocates for Full Stack Serverless, emphasizing scaling to zero and request-based billing. Scaling to zero allows users to avoid fixed monthly resource consumption costs, saving money during periods of low business activity. When business operations resume, cloud services can instantly provide resources, eliminating concerns about purchasing servers that may remain underutilized.

Request-based billing aims to calculate resource costs based on user requests, achieving pay-as-you-go efficiency. Taking AWS Lambda, a Serverless computing provider, as an example, if an average request takes 0.5 seconds, with 10,000 requests per day, the monthly cost would be $1.33. This cost can decrease even further if daily request numbers decrease, potentially reaching zero if there is minimal activity.

AWS Lambda Price for serverless wordpress
AWS Lambda Price for serverless function

No need to worry about server migration:

Deploying WordPress through traditional server purchase requires careful consideration of when to migrate to more powerful servers or the risk of starting with over-provisioned resources. Serverless WordPress deployment eliminates these concerns, automatically scaling computing, database, and storage resources to handle peak user traffic.

Building WordPress on Full Stack Serverless:

Utilizing the benefits of Full Stack Serverless, an architectural diagram for Serverless WordPress deployment includes the following components:

Full Stack Serverless WordPress Architecture
Full Stack Serverless WordPress Architecture

When users access the website deployed on Serverless Functions:

  1. The request first passes through Cloudflare’s CDN, caching static files such as images, CSS, and JS files.
  2. Website images are persistently stored on Cloudflare’s r2 and can be cached by Cloudflare CDN.
  3. The website is hosted on Alibaba Cloud’s Function Compute, capable of auto-scaling based on traffic.
  4. As the website can run on multiple server nodes, WordPress is modified to be stateless, with stateful data (wp-content directory) stored in a shared NAS for seamless scalability.
  5. Some WordPress themes and plugins involve significant database queries during a single page visit. For example, an official website created with the Astra theme and Elementor plugin may have over 100 database queries per page visit. To address delays and high database bills, additional database caching services are required, such as PolyScale or Redis services provided by redis.com or upstash.com. (The pricing plan of Upstash Redis may not be suitable for use as a WordPress cache. If each page visit requires 100 database queries, the 100k command limit provided by Upstash would only cover 1000 page visits. This means that 1000 page visits will cost $0.2.)
  6. TiDB Cloud offers Serverless Database services, providing MySQL services for WordPress.

Why Not Choose RDS (Relational Database Service)?

Most RDS services involve fixed monthly costs, meaning users must pay even if their website has no user visits for a month. True Serverless principles emphasize pay-for-what-you-use, and hence, the choice is made to support scaling to zero and request-based billing for the Serverless Database.

Why Not Choose AWS Lambda for Serverless WordPress Functions?

An in-depth discussion on this topic is available in a dedicated blog post, accessible here: Why should you not use AWS Lambda as the Function for Serverless WordPress?

Monolith vs. Single-Purpose Functions:

While AWS recommends Lambda’s best practice as single-purpose functions, the industry debate persists. For example, this article argues in favor of using monolith functions in API scenarios: https://rehanvdm.com/blog/should-you-use-a-lambda-monolith-lambdalith-for-the-api

Since WordPress is not designed for a single-purpose function architecture, utilizing monolith functions for Serverless WordPress is a more convenient choice. Users can view the WordPress Docker image used at https://github.com/LougaoCloud/WordPressOnFaas.

Conclusion:

By harnessing Full Stack Serverless products with pay-for-what-you-use principles, a Serverless WordPress hosting solution has been constructed, offering the following advantages:

  • Cost Advantage: Full Stack Serverless solutions outperform any Serverful solutions, particularly for websites with minimal traffic.
  • Scalability: As website traffic increases, there is no need to migrate to higher-performance servers, as Full Stack Serverless WordPress automatically scales databases, caches, and storage.
  • Enhanced Availability: Modifying WordPress to a stateless architecture and deploying it in the cloud ensures higher availability compared to deploying it on a single server.

Leave a Comment

Your email address will not be published. Required fields are marked *