Skip to lesson

Hosting options for a student project

ShopLite runs only on your laptop, so nobody else can try it. To put it online you must choose where it runs, and that choice decides how much work you do and how much you pay.

IaaS: rent a virtual machine

IaaS (Infrastructure as a Service) means renting a virtual machine (VM), a computer in the provider's data centre, that you manage yourself. You get the operating system; updates, Docker, firewall, HTTPS and restarts are all yours.

A VM gives you the most freedom: install anything, run Docker, open any port. The price is chores, because nobody patches the operating system or renews a certificate unless you do.

PaaS and serverless: hand over the container

A container platform (PaaS, Platform as a Service) takes your container image and runs it for you. You give it an image, a port and environment variables; it handles the machine, restarts, logs and usually HTTPS.

Compare the three models by the layers you still look after. Your code and image are always yours; the rest moves to the provider as you go from a VM to a platform.

Who manages what on three hosting models. On a VM you manage your code, image, restarts, updates and HTTPS. On a container platform and on serverless you manage only your code and image, and the provider handles the rest. The provider always owns the physical machine.

Example 1 · Who manages what in each hosting model

WhoManagesDemo.javaJava
import java.util.List;
record Layer(String name, String iaas, String paas, String serverless) {}
public class WhoManagesDemo {    public static void main(String[] args) {        List<Layer> layers = List.of(                new Layer("Your code and config", "you", "you", "you"),                new Layer("Container image", "you", "you", "you"),                new Layer("Runtime restarts", "you", "provider", "provider"),                new Layer("Docker and OS updates", "you", "provider", "provider"),                new Layer("HTTPS certificate", "you", "provider", "provider"),                new Layer("Scaling to zero", "not possible", "plan-dependent", "provider"),                new Layer("Physical machine", "provider", "provider", "provider"));
        System.out.printf("%-24s %-14s %-15s %s%n", "Layer", "IaaS (VM)", "PaaS", "Serverless");        for (Layer l : layers) {            System.out.printf("%-24s %-14s %-15s %s%n", l.name(), l.iaas(), l.paas(), l.serverless());        }        long yours = layers.stream().filter(l -> l.iaas().equals("you")).count();        System.out.println("On a VM you manage " + yours + " of " + layers.size() + " layers.");    }}
Output
Layer                    IaaS (VM)      PaaS            Serverless
Your code and config     you            you             you
Container image          you            you             you
Runtime restarts         you            provider        provider
Docker and OS updates    you            provider        provider
HTTPS certificate        you            provider        provider
Scaling to zero          not possible   plan-dependent  provider
Physical machine         provider       provider        provider
On a VM you manage 5 of 7 layers.

What this code does

  • Each Layer record is one row of the responsibility table; the three columns are the three hosting models.
  • Your code, configuration and image are always yours. What moves to the provider as you go right is restarts, patching and HTTPS.

Serverless goes one step further: the platform starts your app only when a request arrives and stops it when traffic ends. You pay per request or per second of running time, and Google Cloud Run works this way.

The rule to remember: the less you manage, the less you control. A VM lets you install anything but you must patch it; a platform is quick to start but limits ports, disk and memory to its plans.

These names describe a model, not a brand. One provider (AWS, Azure, Google Cloud) usually sells all three.

Options for a container plus MySQL

ShopLite is a container image (shoplite-api) plus a MySQL 8.4 database. The VM route needs only the Docker commands you already know:

Terminal
# The VM route in three commands (from your laptop)ssh deploy@203.0.113.25cd /opt/shoplitedocker compose pull && docker compose up -d

Example 2 · The VM route: one Compose file on a rented machine

Runs in: a Linux VM with Docker and the Compose plugin installed

Terminal
$ ssh deploy@203.0.113.25deploy@shoplite-vm:~$ cd /opt/shoplitedeploy@shoplite-vm:/opt/shoplite$ lsCaddyfile  compose.yaml  deploy.sh  shoplite.envdeploy@shoplite-vm:/opt/shoplite$ docker compose pulldeploy@shoplite-vm:/opt/shoplite$ docker compose up -ddeploy@shoplite-vm:/opt/shoplite$ docker compose ps
Sample output
[+] Pulling 2/2
 ✔ api Pulled                                                     6.8s
 ✔ caddy Pulled                                                   2.1s
[+] Running 3/3
 ✔ Network shoplite_default  Created                              0.1s
 ✔ Container shoplite-api-1    Started                            0.6s
 ✔ Container shoplite-caddy-1  Started                            0.8s
NAME               IMAGE                                       SERVICE   STATUS                    PORTS
shoplite-api-1     ghcr.io/asha-rao/shoplite-api:3f9c2e1...    api       Up 20 seconds (healthy)   8080/tcp
shoplite-caddy-1   caddy:2.10                                  caddy     Up 19 seconds             0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp

What this code does

  • The VM only needs Docker: the API image comes from GitHub Container Registry, and Caddy, a small web server, handles HTTPS in front of it.
  • This is the same docker compose you used on your laptop. The difference is that you now own this machine's updates, firewall and disk.

Three common ways to put that pair online:

  • A container platform such as Render, Railway or Fly.io: point it at ghcr.io/<you>/shoplite-api:<sha> and set the environment variables. Some offer only PostgreSQL or Redis, and then you add a managed MySQL from another provider.
  • A small VM with Docker Compose: one Linux VM with Docker, a compose.yaml for the API and a reverse proxy, and the database in a container or as a managed service.
  • A big-cloud container service: AWS App Runner or ECS, Azure Container Apps or Google Cloud Run, with Amazon RDS, Azure Database for MySQL or Cloud SQL. Powerful, but with more settings, networks and permissions to learn.

The VM route uses exactly the Docker and Compose commands from the earlier modules, so nothing new is hidden from you.

Free tiers, sleeping apps and cold starts

A cold start is the wait while a stopped app starts before it can answer its first request. For a Spring Boot API it means starting the container, the JVM, Spring and Flyway, often 20 to 60 seconds.

A free tier is a plan with no bill but with limits: little memory, few hours a month, or an app that sleeps after some idle minutes.

Example 3 · Filtering hosting options by your needs

HostingFilterDemo.javaJava
import java.util.List;
record HostingOption(String name, int monthlyRs, int memoryMb, boolean sleeps,                     boolean mysqlOffered, String region, int setupMinutes) {}
public class HostingFilterDemo {    public static void main(String[] args) {        // Made-up numbers for practice: always check real pricing pages        List<HostingOption> options = List.of(                new HostingOption("PaaS free plan", 0, 512, true, false, "Singapore", 20),                new HostingOption("PaaS starter plan", 650, 512, false, false, "Singapore", 20),                new HostingOption("Small VM + Compose", 500, 1024, false, true, "Mumbai", 90),                new HostingOption("Big-cloud containers", 1800, 1024, false, true, "Mumbai", 180));
        int budget = 1000;        System.out.println("Needs: awake, >= 512 MB, under Rs " + budget + " a month");        for (HostingOption o : options) {            String verdict;            if (o.sleeps()) {                verdict = "no: sleeps when idle";            } else if (o.memoryMb() < 512) {                verdict = "no: too little memory";            } else if (o.monthlyRs() > budget) {                verdict = "no: over budget";            } else {                verdict = "yes" + (o.mysqlOffered() ? "" : " (add a managed MySQL)");            }            System.out.printf("%-21s Rs %4d  %-9s -> %s%n", o.name(), o.monthlyRs(), o.region(), verdict);        }    }}
Output
Needs: awake, >= 512 MB, under Rs 1000 a month
PaaS free plan        Rs    0  Singapore -> no: sleeps when idle
PaaS starter plan     Rs  650  Singapore -> yes (add a managed MySQL)
Small VM + Compose    Rs  500  Mumbai    -> yes
Big-cloud containers  Rs 1800  Mumbai    -> no: over budget

What this code does

  • Each option is a record with the points that matter for a comparison; the checks run in order, so the first failed need is the reason shown.
  • A platform that runs your container but not MySQL is still a valid choice: the verdict reminds you that the database must come from somewhere else.

A sleeping app is stopped after some idle time, on some platforms about 15 minutes. The next visitor pays for the cold start, so a recruiter who opens your link at night may stare at a blank page.

Compare options on the same few points: monthly cost after the free credit, memory per app (a Spring Boot API wants at least 512 MB), whether the app sleeps, whether MySQL is offered, the nearest region (Mumbai, Hyderabad or Singapore for Indian users) and how long the first setup takes.

Predict the output

Who waits for a cold start?

Read the facts, then pick what happens.

Round 1 of 2

Which requests wait for a cold start?

Free plan: sleeps after 15 idle minutes
Cold start: 45 seconds
Requests arrive at minute: 0, 5, 30
(the app is asleep before minute 0)
Free tiers and prices change often. Check each provider's current pricing page on the day you choose; the numbers in this lesson's examples are made up for practice.

Choosing for a portfolio project

A portfolio project is a project you show to recruiters and interviewers, so it must stay online, answer within a few seconds and cost little. You do not need autoscaling or several regions.

Score each option on cost, simplicity and staying awake, and count staying awake double for a demo. The program below does exactly that.

Example 4 · Scoring options for a portfolio demo

PortfolioChoiceDemo.javaJava
import java.util.Comparator;import java.util.List;
record Candidate(String name, int cost, int simplicity, int awake) {    // Each score is 1 (poor) to 5 (great). Staying awake counts double for a demo.    int total() {        return cost + simplicity + 2 * awake;    }}
public class PortfolioChoiceDemo {    public static void main(String[] args) {        List<Candidate> candidates = List.of(                new Candidate("PaaS free plan", 5, 5, 1),                new Candidate("PaaS starter plan", 3, 5, 5),                new Candidate("Small VM on student credits", 4, 3, 5),                new Candidate("Big-cloud containers", 2, 2, 5));
        candidates.stream()                .sorted(Comparator.comparingInt(Candidate::total).reversed()                        .thenComparing(Candidate::name))                .forEach(c -> System.out.printf("%2d  %s%n", c.total(), c.name()));    }}
Output
18  PaaS starter plan
17  Small VM on student credits
14  Big-cloud containers
12  PaaS free plan

What this code does

  • total() turns three 1 to 5 scores into one number; doubling awake says a demo that answers at once matters most. Change the weights and the order changes.
  • The free plan comes last because a sleeping demo makes a bad first impression; the top two are close, so pick the one you are more comfortable running.

Good fits for a student are a small VM paid with student credits (for example from the GitHub Student Developer Pack or a cloud's student programme), or a container platform's lowest paid plan that does not sleep.

A free plan that sleeps is fine for practice, but warn readers in your README that the first request may be slow.

Cost safety: budgets, alerts and shutting things down

A budget alert is an email that the cloud sends when your spending passes a share of the monthly budget you set, such as 50%, 80% and 100%. It warns you; it does not stop anything.

Set a budget and alerts on the day you create the account, before anything else. The program below adds up daily costs and shows when each alert fires.

Example 5 · Budget alerts at 50%, 80% and 100%

BudgetAlertDemo.javaJava
import java.util.List;
public class BudgetAlertDemo {    public static void main(String[] args) {        int budget = 400;                       // rupees for the month        int[] thresholds = {50, 80, 100};       // percent        List<Integer> dailyCost = List.of(20, 20, 25, 30, 120, 125, 130, 130);
        int spent = 0;        int next = 0;        for (int day = 1; day <= dailyCost.size(); day++) {            spent += dailyCost.get(day - 1);            while (next < thresholds.length && spent * 100 >= budget * thresholds[next]) {                System.out.println("Day " + day + ": ALERT " + thresholds[next]                        + "% of budget used (Rs " + spent + " of Rs " + budget + ")");                next++;            }        }        System.out.println("Spent Rs " + spent + " in " + dailyCost.size() + " days");        System.out.println("Day 5 jumped from Rs 30 to Rs 120: something new is running.");    }}
Output
Day 5: ALERT 50% of budget used (Rs 215 of Rs 400)
Day 6: ALERT 80% of budget used (Rs 340 of Rs 400)
Day 7: ALERT 100% of budget used (Rs 470 of Rs 400)
Spent Rs 600 in 8 days
Day 5 jumped from Rs 30 to Rs 120: something new is running.

What this code does

  • This is what a cloud budget does for you: it adds up the daily cost and sends one alert each time a threshold is crossed.
  • The alerts do not stop anything. Spending kept going after day 7; only deleting the extra resource would have stopped it.

Most surprise bills come from things left running: a database you forgot, a large VM chosen by mistake, or a public storage bucket that someone downloads from. When a demo ends, delete the resources, not just stop them; a stopped VM still pays for its disk and its public IP on many clouds.

An alert only warns you; it does not stop the spending. For a hard stop, delete or scale down the resources yourself.

Next step

Check your understanding

11 quick questions