Video in progress

Splitting a monolith into 15 microservices is being proposed. How do the JVM footprint and infrastructure cost change, and how do you calculate it?

Every JVM has an "idle" cost: metaspace, code cache, JIT and GC threads, the framework context, a minimal heap. For a Spring Boot service that is typically 200-400 MB of RSS plus the startup time. 15 services × replicas multiplies this base cost. I measure that cost and compare it with the business benefit; if needed I also add shrinking the footprint to the plan.

📖 Answer

I start the calculation from the base cost: start a single typical Spring Boot service with no load:

jcmd <pid> VM.native_memory summary   # with -XX:NativeMemoryTracking=summary
cat /sys/fs/cgroup/memory.current

For example: an empty context on the heap 80 MB, metaspace 90 MB, code cache 40 MB, threads 50 MB, GC and others 40 MB: ~300 MB and ~1 vCPU during warm-up.

The monolith: 6 replicas × 4 GB = 24 GB. The microservices: 15 services × 3 replicas (the minimum for HA) × (300 MB base + their own working memory). The base part alone is 13.5 GB. Once working memory is added, the total often grows 1.5-2 times. On top of that come sidecars (service mesh, log agent) in every pod.

The hidden costs:

  • every service goes through JIT warm-up separately, and in small pods C2 gets less CPU and warms up more slowly;
  • network calls add serialization and allocation, so CPU per request goes up;
  • watching, updating and tuning 45 JVMs is an operational cost.

On the benefit side: independent deploys, independent scaling (only the hot part grows), short GC pauses on small heaps, and isolation.

If you split anyway, you can shrink the footprint like this:

  • special base settings for small pods: heap percentage, -Xss and thread pools;
  • AppCDS/AOT cache for startup and metaspace;
  • virtual threads to reduce the number of platform threads;
  • very small services in native image;
  • merging some services: a "modular monolith" is often the right middle ground.

My recommendation: put the calculation in a table, and choose the boundaries based on the teams and the deploy frequency. If the only reason to split is "modern architecture", the JVM cost shows that it is expensive.