Cloud runtime choices
What you will learn
A JVM application can run on a virtual machine (VM), a managed container platform, a Kubernetes cluster, or a function runtime. Choose based on workload lifecycle, control, operational ownership, startup latency and state rather than provider branding.
- Compare service families using workload constraints.
- Identify runtime-specific restrictions and data dependencies.
- Budget database connections across replicas.
Plain Java examples: save as Main.java in a fresh directory, then run javac --release 21 Main.java and java Main. Standalone Java 21 functional examples. These are offline Java 21 models, not cloud or hosted CI execution. Companion local pipeline evidence is separate.
Choose a runtime family from requirements
public class Main { enum RuntimeKind { VM, MANAGED_CONTAINER, KUBERNETES, FUNCTION } static RuntimeKind choose(boolean needsHost, boolean needsCluster, boolean eventOnly) { if (needsHost) return RuntimeKind.VM; if (needsCluster) return RuntimeKind.KUBERNETES; if (eventOnly) return RuntimeKind.FUNCTION; return RuntimeKind.MANAGED_CONTAINER; } public static void main(String[] args) { System.out.println(choose(false,false,false)); System.out.println(choose(false,false,true)); }}Expected output:
MANAGED_CONTAINERFUNCTIONA deliberately simple decision model; actual decisions require latency, compliance and cost review.
Provider service map — candidates, not provisioning instructions
AWS: EC2 (VM), ECS/Fargate (managed container tasks), EKS (Kubernetes), Lambda (event functions), RDS for PostgreSQL, ElastiCache, S3 and CloudWatch. Azure: Virtual Machines, Container Apps/App Service, AKS, Functions, Azure Database for PostgreSQL Flexible Server, Azure Managed Redis, Blob Storage and Azure Monitor. Google Cloud: Compute Engine, Cloud Run, GKE, Cloud Run functions, Cloud SQL for PostgreSQL, Memorystore, Cloud Storage and Cloud Monitoring. These families are not exact substitutes; verify features, region, architecture, runtime lifecycle, terms and SKU before selection. AWS Lambda documentation lists Java 21 and 25; Google Cloud documents a Java 21 runtime and Spring Boot deployment. Azure Java guidance distinguishes hosted Java stacks and container options. A function handler is not necessarily a long-running HTTP server.
Design around resource limits
Keep durable state in approved managed storage, not an ephemeral container filesystem. Use private networking and approved TLS endpoints for databases and caches; check DNS, egress, connection limits and health probes. Scaling replicas multiplies connections: 100 database slots minus 20 reserved, with 10 per replica, permits at most eight replicas under these assumptions. Include migration jobs and other users; reserve for rolling deployment overlap. Function timeout, concurrency and cold-start behavior vary by plan and region; do not assume the sample limits are provider values.
Bound replicas by connection capacity
public class Main { static int maxReplicas(int dbLimit,int reserved,int perReplica) { if (dbLimit<=0 || reserved<0 || reserved>=dbLimit || perReplica<=0) throw new IllegalArgumentException("connections"); return (dbLimit-reserved)/perReplica; } public static void main(String[] args) { System.out.println(maxReplicas(100,20,10)); }}Expected output:
8The floor division leaves reserved capacity untouched.
Reject a mismatched execution model
public class Main { record Workload(int durationSeconds, int limitSeconds, boolean localState) { Workload { if(durationSeconds<0 || limitSeconds<=0) throw new IllegalArgumentException("duration"); } boolean fits() { return durationSeconds<=limitSeconds && !localState; } } public static void main(String[] args) { System.out.println(new Workload(90,60,false).fits()); System.out.println(new Workload(20,60,true).fits()); }}Expected output:
falsefalseThe hypothetical function plan rejects both excessive duration and reliance on local durable state.
Common mistakes
Do not assume serverless means no servers, no limits or no charges. Autoscaling may exhaust database connections. Managed Kubernetes still requires workload and security operations. Avoid relying on region-independent pricing, permanent local disk or a universal Java runtime version.
Practice
Calculate the replica limit for 160 slots, 40 reserved and 15 per replica.
Expected output:
8Compare with the manual review criteria.
Further reading: AWS compute · AWS Java · Azure Java · Google Java · Cloud Run contract. Independent editorial review remains pending.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Cloud runtime choices — knowledge check
Cloud deployment and CI/CD reasoning.
Which family provides direct OS control?
What does a managed container platform reduce?
Where should durable catalog data live?
What limits safe replica scaling?
Before choosing a managed Java runtime, verify what?