WordPress cloud hosting: Shifter goes Serverless

WordPress cloud hosting: a paradigm shift in traditional hosting

Shifter is a serverless hosting solution for WordPress. It brings serverless technology to one of the most widely used CMS platforms. Here’s how we did it.
shifter

It’s not you, WordPress. It’s everything else.

Over the past 10 years, WordPress has become one of the most successful Open Source projects. Today, one in four websites are powered by WordPress, with no signs of slowing down. WordPress has evolved from a blogging platform into a full content management system. Developers are always discovering new, creative ways to extend and leverage the power of WordPress, from mobile applications to serving the highest trafficked media outlets. There’s not much that WordPress can’t do.

Revisiting Traditional Hosting

First, let’s take a step back and think about where serverless architecture fits in the topic of hosting.
WordPress Cloud hosting is difficult. WordPress is built to serve casual bloggers, enterprise applications, and all users between. However, the same reasons that make it great also make it difficult for both users and hosts. 
Despite the progress made since its release, how we host WordPress has not changed. Deploying, scaling, and security are just more comprehensive versions of what we did 10 years ago.
Now, with WordPress cloud hosting infrastructures just a click away, it’s almost our duty to do more. We revisited the basic needs of hosting to both improve it and to think about it in a completely new way.
Static site generators are a growing trend because they excel at scaling and security while keeping it simple. However, these products tend to fall short in terms of the features and ease of use that you might expect from a full-featured CMS. So, how can we get the best of both worlds? How can we get everything you’d expect from WordPress with the power of static site technology?

WordPress cloud hosting: going Serverless

In many ways, we view our path to serverless hosting as a parallel to the community that realises a need for the WP REST API . With the API, developers can abstract the CMS from view. Separating these two functions introduces a whole new set of options. You can now use WordPress to power native applications, Javascript web apps, and more.
We realised that WordPress cloud hosting is no different. Why should we limit ourselves to the monolithic architecture that we grew up with? Why bundle everything into one unhappy server that will always be trying to keep up? To move toward the future, we had to abstract WordPress from the server, which meant going on serverless architecture.
The concept of serverless architecture is about building separate services. On AWS, these services are Lambda, API Gateway, DynamoDB, and Cognito. The tasks of these functions were once performed on servers with various middleware. Because AWS can now deliver these services on-demand or à la carte, there is no need for servers.

Serverless Lifecycle: Creating, Generating, Delivering

Create. Generate. Deliver. This is the life cycle that every website follows, including traditionally hosted websites. With Shifter, we break it down using various microservices in each step.

Creating: Docker

WordPress Cloud Hosting is powered by Docker. This container technology offers a complete filesystem to run everything including WordPress itself. It can quickly boot and varnish. Use it when you need it and delete it when you don’t. Shifter takes advantage of this feature by supplying WordPress when you’re editing content and powers it down when you’re not. With Docker, we can run multiple containers on a server and scale up as demand grows. Shared resources and its impact on speed could potentially be a concern, but they aren’t a factor here. The Docker container running WordPress only has to generate the files we need for use later in the process.
lifecycle

Generating: AWS Microservices

Because our goal is to deliver Shifter as a SaaS, we needed to think about cost, maintenance, and human resources. The AWS suite of microservices, such as Lambda and DynamoDB, allow us to build functions as a service. They fire when needed and can run in parallel. This gives us the freedom to scale. Since WordPress is not bound by server resources, it can pass off the heavy lifting. In turn, this reduces latency and computing power and allows each piece to do what it does best. It ultimately processes dynamic PHP content into static HTML files for deployment.

(function loop(){
  var retry_count = 0;
  var process = require('process');
  process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
  console.log('site_id=' + site_info.id + ', url=' + site_info.url);
  try {
    var req = https.get(site_info.url, function(res) {
      var body = '';
      var status_code = res.statusCode;
      console.log("Got response: %j", status_code);
      if ( status_code == 200 || status_code == 404 ) {
        res.setEncoding('utf8');
        res.on('data', function(chunk) {
          body += chunk;
        });
        res.on('end', function(res) {
          // replace host name
          replaceIndexFileHostname(
            parsedUrl.resource + ( parsedUrl.port ? ':' + parsedUrl.port : '' ),
            site_info.publish,
            body,
            path.join(wk_folder, 'index.html')
          );
          // S3 sync
          s3Sync(
            site_info,
            s3_info,
            {'folder': wk_folder, 'pathname': pathname, 'statusCode': status_code},
            function(err){callbackFunc(err);}
          );
        });
      } else {
        retry_count++;
        if (retry_count > retry_limit) {
          console.log('https response: %j', res);
          callbackFunc(null, "Request response Error: " + res.statusCode);
        } else {
          loop();
        }
      }
    });
    req.setTimeout(60000);
    req.on('timeout', function() {
      console.log('docker url request timed out');
      req.abort();
    });
    req.on('error', function(err) {
      retry_count++;
      if (retry_count > retry_limit) {
        console.log('Error: %j', err);
        callbackFunc(err, 'Request timed out.');
      } else {
        loop();
      }
    });
      req.end();
  } catch (err) {
    console.log('Error: %j', err);
    callbackFunc(err, 'Request timed out.');
  }
})();
Code example: Retrieve HTML file from a Docker machine via HTTPS request, and upload that to S3.

Delivering: S3, CloudFront, Global CDN

Next, static files and resources are moved to a global CDN with all of the inherent security, durability, and speed that you expect. CloudFront delivers content by geolocation. It’s also more secure because there is nothing to maintain. Vulnerability plagued by PHP, Apache, etc. are no longer relevant. This also applies to the database. It’s not there, so there is nothing to hack.
Simply put, it’s a super fast worldwide network of pure content.

Challenges of building a SaaS on a new technology with a new concept

Our commitment to going serverless has changed everything for us. We now have the opportunity to offer products alongside much larger companies and still be competitive. AWS gives us, a small startup team, the chance to achieve larger goals with fewer resources, funding, and speed while leveraging more from what we have.
We are happy with the progress that we’ve made, and we are pleased with the capabilities that Shifter offers. We are linking serverless with microservices, which means that we are working in a relatively young development model, especially compared to traditional LAMP. Of course, we’ll face new problems. And, with this development model, we will find a solution. We believe that this is the right path to follow; that it is the future of hosting. We hope that Shifter will be an example of that future and that it will design for these challenges.
generator
Technical issues aside, the biggest challenge that we face is getting people on board with this approach. Since it’s a new concept, it may be less comfortable and more difficult to understand. We’ll try hard to spread this concept through our product, messaging, and communications.

Kickstarter

We’ve proven that Kickstarter is more than just a wild concept. Today, we need your help to develop our roadmap and bring more features to Shifter. Enter Kickstarter. We will begin our crowdfunding campaign with the opening day of our WordCamp US this year in Philadelphia. We ask for your support to help realize this product and in return, you’ll receive special offers, awesome rewards, first dibs on cool swag, and more.

Related Posts

— September 18, 2018

How to Optimize Cloud Costs with Spot Instances: New on Cloud Academy

One of the main promises of cloud computing is access to nearly endless capacity. However, it doesn’t come cheap. With the introduction of Spot Instances for Amazon Web Services’ Elastic Compute Cloud (AWS EC2) in 2009, spot instances have been a way for major cloud providers to sell sp...

Read more
  • AWS
  • Azure
  • Google Cloud
— August 23, 2018

What are the Benefits of Machine Learning in the Cloud?

A Comparison of Machine Learning Services on AWS, Azure, and Google CloudArtificial intelligence and machine learning are steadily making their way into enterprise applications in areas such as customer support, fraud detection, and business intelligence. There is every reason to beli...

Read more
  • AWS
  • Azure
  • Google Cloud
  • Machine Learning
— August 17, 2018

How to Use AWS CLI

The AWS Command Line Interface (CLI) is for managing your AWS services from a terminal session on your own client, allowing you to control and configure multiple AWS services.So you’ve been using AWS for awhile and finally feel comfortable clicking your way through all the services....

Read more
  • AWS
Albert Qian
— August 9, 2018

AWS Summit Chicago: New AWS Features Announced

Thousands of cloud practitioners descended on Chicago’s McCormick Place West last week to hear the latest updates around Amazon Web Services (AWS). While a typical hot and humid summer made its presence known outside, attendees inside basked in the comfort of air conditioning to hone th...

Read more
  • AWS
  • AWS Summits
— August 8, 2018

From Monolith to Serverless – The Evolving Cloudscape of Compute

Containers can help fragment monoliths into logical, easier to use workloads. The AWS Summit New York was held on July 17 and Cloud Academy sponsored my trip to the event. As someone who covers enterprise cloud technologies and services, the recent Amazon Web Services event was an insig...

Read more
  • AWS
  • AWS Summits
  • Containers
  • DevOps
  • serverless
— July 11, 2018

AWS Certification Practice Exam: What to Expect from Test Questions

If you’re building applications on the AWS cloud or looking to get started in cloud computing, certification is a way to build deep knowledge in key services unique to the AWS platform. AWS currently offers nine certifications that cover the major cloud roles including Solutions Archite...

Read more
  • AWS
— June 26, 2018

Disadvantages of Cloud Computing

If you want to deliver digital services of any kind, you’ll need to compute resources including CPU, memory, storage, and network connectivity. Which resources you choose for your delivery, cloud-based or local, is up to you. But you’ll definitely want to do your homework first.Cloud ...

Read more
  • AWS
  • Azure
  • Cloud Computing
  • Google Cloud
— March 13, 2018

Choosing the Right AWS Certification for You and Your Team

As companies increasingly shift workloads to the public cloud, cloud computing has moved from a nice-to-have to a core competency in the enterprise. This shift requires a new set of skills to design, deploy, and manage applications in the cloud.As the market leader and most mature pro...

Read more
  • AWS
  • AWS certifications
— March 7, 2018

How to Encrypt an EBS Volume

Keeping data and applications safe in the cloud is one the most visible challenges facing cloud teams in 2018. Cloud storage services where data resides are frequently a target for hackers, not because the services are inherently weak, but because they are often improperly configured....

Read more
  • AWS
  • encryption
— February 28, 2018

How to Develop Machine Learning Models in TensorFlow

Predictive analytics and automation—through AI and machine learning—are increasingly being integrated into enterprise applications to support decision making and address critical issues such as security and business intelligence. Public cloud platforms like AWS offer dedicated services ...

Read more
  • Amazon Machine Learning
  • AWS
  • AWS Labs
— February 15, 2018

Is Multi-Cloud a Solution for High Availability?

With the average cost of downtime estimated at $8,850 per minute, businesses can’t afford to risk system failure. Full access to services and data anytime, anywhere is one of the main benefits of cloud computing.By design, many of the core services with the public cloud and its underl...

Read more
  • AWS
  • Azure
  • Cloud Adoption
  • Google Cloud
— February 13, 2018

Cloud Academy Sketches: Encryption in S3

Some of 2017’s largest data breaches involved unprotected Amazon Simple Storage (S3) buckets that left millions of customer data records exposed to the public. The problem wasn’t the technology, but administrators who improperly configured the security settings.For cloud teams in char...

Read more
  • AWS