Services in the Cloud

This article was first published in the “From the Cloud” column in php|architect magazine.

Need to scale your web application but finding the cost of physical services too much for your budget? Cloud services may be just the answer for you.

What is cloud computing? Well, loosely put, it’s any form of computing that takes place over a network. More well-defined, it’s the practice of offloading expensive processes to a machine or pool of machines, scaling to any number of machines depending on resource utilization. Historically, cloud computing has been limited to use in the enterprise due to the prohibitive expense of running tens of hundreds of machines, or even thousands of machines, to process data. The costs include hardware, electricity, space, and more, making it impractical for any small- to medium-sized business, but these obstacles are no longer a problem with the advent of cloud services such as Amazon Elastic Compute Cloud (EC2), Windows Azure, and Google App Engine.

Small, medium, and large businesses are now saving money by ditching their in-house, data-processing, server farms and moving to these cloud services for everything from processor-intensive number crunching to easy-to-scale web hosting. It’s a growing industry, and more and more of the services we use on the Web are trusting their business models to external cloud computing services.

Amazon Elastic Compute Cloud

Amazon Elastic Compute Cloud, or EC2, takes the concept of virtual private servers to a new level. With EC2, Amazon provides a cloud in which users may run any number of virtual machine (VM) images with varying degrees of resources allocated to each machine. Each image running in the cloud looks and behaves just like a real server running in a server farm. This is very attractive to businesses who rely on racks upon racks of machines in a data center. With virtualization, these business can greatly reduce costs by switching to EC2, getting rid of hardware, cutting energy costs, and freeing up space.

For persistent storage, EC2 connects to Amazon Simple Storage Service, or S3. For content distribution, Amazon CloudFront provides edge locations to speed up delivery of files to end users. Amazon Web Services provides a full and flexible cloud-computing solution, but this flexibility comes with a price: the user is in full control and must manage his or her servers, program them to scale properly, and set everything up just as one would do with a real server farm—without the hardware. That is, EC2 is not managed hosting. Your system admins will still have plenty of work to keep them busy.

Still, EC2 is cheap—about $73 USD a month for the smallest VM at the time of this writing—and provides plenty of options, including multiple distributions of Linux and Windows Server images, or the ability to create your own, and software exists, such as Scalr, to aid in scaling a pool of machines in EC2.

Use EC2 when you want total control over the entire environment in which your applications run, from the software that runs in the cloud (such as Apache, PHP, MySQL, etc.) right down to managing the virtual servers to scale based on load. If porting applications already running across multiple servers, then EC2 is a good fit because, for the most part, you can image those machines and move them directly into EC2 with minimal changes.

Google App Engine

Google App Engine differs from EC2 in that the Google cloud is a full development platform in which you run applications rather than deploy virtual machines. App Engine abstracts away the low-level details of the operating system, removing the need for administration of a virtual machine and allowing you to focus on building applications at a higher level. Think of it as a massive operating system that is fully managed by Google.

Scaling in App Engine happens naturally. As your applications need more resources, App Engine allocates more. Under a certain threshold, there is no cost to use the service, but as demand on your applications requires resources above that threshold, then Google will start charging for resource usage. Some of the quotas imposed on the free service include limits on e-mails that can be sent per day, bandwidth in and out quotas per day, CPU megacycles per day, HTTP requests per day, and data store API calls per day.

In addition, App Engine imposes some hard limits for the service, including a maximum of thirty seconds per request, 1,000 files per application, a maximum of 10 MB allowed in an HTTP response, and no more than 1 MB per item stored in the data store. Other restrictions include: read-only access to the file system, execution of code only through an HTTP request, and data store queries are limited to only 1,000 rows returned per call.

While there certainly appear to be a lot of limitations and restrictions involved in using App Engine, it can save you the hassle of managing a server farm. Use App Engine when you don’t want to worry with server set-up and maintenance, you want an environment that already comes complete with helpful APIs and even a built-in web application framework, and you don’t mind programming in Python or Java. Other languages will be added in the future, perhaps including PHP.

As a side note, it is possible to run PHP on App Engine with Quercus, a Java implementation of the PHP language. Follow the “PHP on App Engine” link in the Related Links section for more information.

Windows Azure

A relative newcomer to the cloud game, the Azure Services Platform from Microsoft is a collection of various services and APIs that exist in the Microsoft cloud. These services include Live Services, SQL Services, .NET Services, SharePoint Services, and Dynamics CRM Services. The hosting and management environment in which these services live is called Windows Azure, which is described by Microsoft as a “cloud services operating system.” On top of this plat- form and on this operating system, Microsoft runs such services as Windows Live, Office Live, Exchange Online, and others, and they have opened up the platform, allowing developers to build and run applications on Azure that may utilize the services of the platform.

Azure is similar to App Engine in that it is a development platform that acts as an operating system, rather than a system in which you run your own virtual machines, as with EC2. Scaling, reliability, load balancing, and geo-replication are all handled by the Windows Azure Fabric Controller, and the Azure Storage Service provides an unstructured data store for storing BLOBs and non-relational tables. REST and SOAP APIs provide access from Azure to each of its services.

Azure is naturally tightly integrated with Microsoft .NET technologies. However, at MIX09, support for FastCGI was announced, which opens the door for running PHP applications in the Azure cloud.

At the time of this writing, Azure is open to developers by invitation only during their Community Technology Preview (CTP) stage. A pricing model for pay-as-you-go service fees is forthcoming, but during the CTP, the service is free to those with an invitation token. All are allowed to sign up for a token, though it is not clear if everyone who signs up receives one, and times for receiving a token vary.

Use Windows Azure if your organization relies on the Microsoft family of technologies and needs tighter integration with their online services. Like App Engine, Azure can relieve you of the overhead that comes with managing a virtual server farm like EC2. Plus, Azure has built-in FastCGI support, and, thus, can run PHP applications, so for those wanting to run PHP in a managed cloud, Azure is a good fit.

A View from the Cloud

I’ve said it before, and I’ll say it again. Software as a Service (SaaS) and software + services models are the future of computing. The software and operating systems we use are becoming so tightly integrated with the Cloud that the experience is seamless. We are beginning to not notice the difference between applications that run on the desktop and applications that run in the Cloud. Cloud services exist to bring that level of seamlessness to the masses. Whereas running a cloud was once costly and impossible to maintain for individuals and small- to medium-sized companies—and even unattractive to large companies—these services can provide cloud technology at a fraction of the cost and without the administrative overhead required to run a server farm.

While I’ve mentioned three such services, these are not the only three. As I stated earlier, cloud services is a growing industry. Other clouds include AppLogic from 3tera, Mosso from Rackspace, and more. The choice of which to use is dependent on your needs and whether the service offerings meet those needs.