Sub topic 9
PaaS: renting a platform to run code
This chapter assumes you know what a server, an operating system, and an application are. It also assumes you are comfortable with basic web terms such as HTTP and IP address. It builds on IaaS, where you rent virtual machines and manage everything above the hardware.
What PaaS is
Platform as a Service (PaaS) is a service model where the provider runs the servers, the operating system, and the language runtime. You supply application code and configuration. The platform provisions machines, installs the runtime, starts your code, and keeps it running.
Compare this with IaaS. On IaaS you pick a machine image, patch the operating system, and install the runtime yourself. On PaaS those jobs belong to the provider. Your job narrows to the application and its data.
A worked example
The smallest PaaS workload is application code. This Flask app contains no server setup, no operating system settings, and no web server configuration.
from flask import Flask
application = Flask(__name__)
@application.route("/")
def index():
return "Hello from a PaaS-hosted app"AWS Elastic Beanstalk is a PaaS offering. With its command line tool you create the application and an environment, then deploy the code.
# PaaS: deploy application code to a managed platform (AWS Elastic Beanstalk CLI).
eb init my-app --platform python --region us-east-1
eb create my-app-env
eb deployBehind these three commands the platform does the work you would do by hand on IaaS. It launches instances, sets up a load balancer, installs the Python runtime, and starts your app. The name application is not accidental. Elastic Beanstalk's Python platform looks for a callable with that name by default.
What you still manage
PaaS removes infrastructure chores, but not all responsibility.
- Your application code, including its security flaws.
- Your data and who can access it.
- Configuration, such as environment variables, scaling limits, and instance size.
- Dependencies you list, for example in
requirements.txt. The platform runs them, but it does not choose or audit them for you.
The provider patches the operating system and runtime. A later chapter covers how this split is described as shared responsibility.
Common errors
Most PaaS problems come from the platform's assumptions, not from the code.
- Wrong entry point. The platform cannot find the app object. Check that the name matches what the platform expects.
- Local state. Storing files or sessions on the instance's disk breaks when the platform adds, replaces, or restarts instances. Use an external database, object store, or cache.
- Hard-coded settings. Ports, database addresses, and secrets in code do not travel between environments. Read them from environment variables.
- Unsupported runtime version. Platforms offer specific language versions. Your code must fit one of them.
- Assuming full control. You cannot install arbitrary system packages or change kernel settings. If you need that, IaaS or containers fit better.
When PaaS fits
PaaS suits web applications and APIs written in a supported language, where the team wants to spend time on features instead of servers. It fits less well when you need a custom operating system, specialized software on the host, or fine control of networking.
Exercise
Your team deploys a Flask app to a PaaS. After a redeploy, users report that files they uploaded earlier are gone. What is the likely cause, and what is the fix?
Show answer
The app saved uploads to the local disk of an instance. On a PaaS, instances are replaced during deployments and scaling, so local files are lost. Store uploads in external storage such as an object store (for example Amazon S3) and keep only references to them in the app.
Exercise
Name two tasks you handle on IaaS that the provider handles on PaaS.
Show answer
Any two of: patching the operating system, installing and updating the language runtime, and provisioning and configuring the servers and load balancer.