Sub topic 9
PaaS: Renting a Platform to Run Code
Platform as a Service (PaaS) is a service model where the provider runs the servers, the operating system, and the language runtime, and you supply only your application code and its configuration. This chapter assumes you know what a server, an operating system, and an application are, and that you recognize basic networking terms such as HTTP. It also assumes you have seen the IaaS chapter, where you rented a virtual machine and managed everything above the hardware.
What the platform does for you
On IaaS you choose a machine image, patch the operating system, install a runtime, configure a web server, and set up scaling yourself. PaaS removes most of that work. You hand the platform a code bundle, and it does the following:
- Provisions virtual machines or containers to run the code.
- Keeps the operating system and runtime patched.
- Places a load balancer in front of your instances.
- Starts more instances when load rises and removes them when it falls.
- Replaces instances that fail health checks.
- Collects logs and metrics in one place.
The virtual machines still exist. They are managed by the platform, and you usually do not log in to them.
Where PaaS sits in the stack
The stack runs from hardware up to the application. With PaaS the provider manages every layer up to and including the runtime. You manage the application code, its configuration, and its data.
A worked example: Flask on Elastic Beanstalk
AWS Elastic Beanstalk is a PaaS offering. It uses ordinary AWS resources underneath, such as EC2 instances, a load balancer, and an Auto Scaling group, but it creates and wires them for you.
The application below is a complete Flask app. Elastic Beanstalk's Python platform looks for a WSGI callable named application in a file called application.py, which is why the variable has that name.
from flask import Flask
application = Flask(__name__)
@application.route("/")
def index():
return "Hello from a PaaS-hosted app"The platform also needs to know which libraries to install. It reads a requirements.txt file in the same folder:
FlaskThen you deploy with the Elastic Beanstalk CLI:
# 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 deployEach command does a distinct job:
eb initregisters an application namedmy-appin your project folder and selects the Python platform and region.eb createbuilds an environment. An environment is one running copy of the application with its own instances, load balancer, and URL. This step takes several minutes.eb deployuploads a new version of your code to the existing environment and rolls it out to the instances.
Compare this with the IaaS example from the earlier chapter, where aws ec2 run-instances gave you an empty machine. Here you never picked an operating system image or installed Python.
The deployment flow
What you still manage
PaaS does not make operations disappear. You remain responsible for:
- Application security. Input validation, authentication logic, and dependency vulnerabilities in your own code are yours. If a library in
requirements.txthas a known flaw, the platform will not fix it for you. - Access control. Who can deploy, who can read environment settings, and which network paths are open.
- Data. Backups, schema changes, and retention of the data your app stores.
- Configuration. Environment variables, instance size limits, and scaling rules.
- Cost. The platform bills for the resources it creates on your behalf, even though you did not create them by hand.
Common errors and gotchas
Storing state on the instance. Instances are created and destroyed automatically. A file saved to local disk can vanish when an instance is replaced, and a second instance will not see it. Keep user uploads in object storage, sessions in a shared cache or database, and data in a managed database.
Assuming you can install anything. The platform supports particular languages and versions. If you need a system library or an unusual runtime, you may have to use a custom platform, a container option, or move to IaaS.
Hardcoding configuration. Database addresses and secrets belong in environment variables or a secrets service, not in source code. Environments for testing and production differ, and the same code should run in both.
Ignoring platform end-of-life. Providers retire old runtime versions. The platform patches the operating system, but you must move your code to a supported language version.
Forgetting to delete environments. An environment keeps running, and billing, until you remove it. In Elastic Beanstalk, eb terminate my-app-env deletes it.
Wrong entry point. Platforms expect a specific start convention. If the deployment succeeds but the health check fails, check the application's file name, callable name, and port handling first, then read the logs with eb logs.
Trade-offs
| Aspect | What PaaS gives you | What it costs you |
|---|---|---|
| Effort | No OS patching, server setup, or scaling scripts | Time learning the platform's conventions |
| Speed | Fast path from code to a running service | Slow environment creation on some platforms |
| Control | Simple configuration surface | No root access to the operating system in most cases |
| Flexibility | Many languages and frameworks | Limited to supported runtimes and versions |
| Portability | Standard code can often move | Platform-specific config and add-ons create lock-in |
| Cost | Pay for capacity, with less staff time spent on operations | Can cost more per unit of compute than raw IaaS |
Lock-in deserves a note. A plain Flask app is portable. The deployment configuration, the managed database connection, and any provider-specific services you add are what make leaving harder.
Where PaaS fits in the other models
IaaS gives you more control and more work. SaaS gives you a finished product with nothing to deploy. PaaS sits between them: you write the software, and the provider runs the place where it lives. It suits web applications, APIs, and backends with ordinary needs, and teams that want to focus on code rather than servers. It is a weaker fit when you need custom operating system settings, specialized hardware, or a runtime the platform does not support.
Exercise
Your team deploys a Flask app to a PaaS with two instances. Users report that a profile photo they uploaded sometimes appears and sometimes does not. The code saves uploads to a folder on the local disk. What is the cause, and how should you fix it?
Show answer
Each instance has its own local disk, and the load balancer sends requests to either one. A photo saved on instance A is missing when a request reaches instance B. Instances can also be replaced, which deletes their local files. The fix is to store uploads in shared, durable storage such as an object storage service, and save only a reference to the file in the database.
Exercise
Name two responsibilities that remain yours on PaaS, and one that the provider takes over compared with IaaS.
Show answer
You remain responsible for your application code (including its security and dependencies) and for your data and configuration. The provider takes over patching the operating system and runtime, and managing the servers and the scaling and load balancing infrastructure.