Skip to content
In this postPostgreSQLMySQLValkey

Cloud Hypervisor vs Firecracker: what we measured for databases and Next.js

We tested Cloud Hypervisor and Firecracker side by side on lab hardware for two workload types, databases and Next.js apps, with every microVM restored from a snapshot. Here is what each one cost in wake time, tail latency, CPU and memory, and the two gotchas that bit us.

By Bob Bass8 min read
FirecrackerCloud HypervisorMicroVMsNext.jsPostgreSQL
Cloud Hypervisor and Firecracker logos side by side

Short version: we tested Cloud Hypervisor and Firecracker side by side on lab hardware for two workload types, databases and Next.js apps, with every microVM restored from a memory snapshot. Both survived hard crashes without losing a committed write. Firecracker woke faster and used less memory per awake guest. Cloud Hypervisor kept its slowest requests fast under load, while Firecracker's slowest 1% went past half a second. For Next.js apps that made the choice easy. Databases are a more nuanced story, and we cover the numbers below.

What we tested

The reason to want a microVM is a separate kernel per tenant. What we wanted to know was the price of that kernel, and whether it holds up when many of them share one machine.

Both test series used the same start path. Boot the guest once, drop its page cache, take a memory snapshot. After that, every start is a restore from the snapshot, never a fresh boot.

  • Databases: 100 PostgreSQL microVMs on one lab server, driven by pgbench TPC-B (small read-write transactions), with MySQL and Valkey added for crash, wake and memory tests. Cloud Hypervisor v54.0, Firecracker v1.16.0.
  • Next.js: 40 apps in 512 MB guests, 400 requests per second spread across them for 60 seconds, three passes per runtime. Cloud Hypervisor v54.1, Firecracker v1.16.2, Next.js 16.4.
  • Baseline: a lightweight container baseline we used for comparison, with the same images on the same machine.

The two workload types ran on two different 8-core, 16-thread lab servers, so compare ratios across workloads, not raw milliseconds. Everything here is from our lab runs. A figure is a single run unless it shows a range or a pass count, and your results will differ.

Safety: 225 hard crashes, zero lost commits

The crash test is simple and unforgiving. Writers commit numbered transactions and record only the ids the database acknowledged. At a random moment the VMM process gets SIGKILL. The same disk boots again, and every acknowledged id has to be there, with no torn transaction and the integrity checks clean.

Cloud Hypervisor took 150 of those kills on PostgreSQL (about 488,000 acknowledged commits) and 75 on MySQL (about 272,000). Zero acknowledged commits lost across all 225, pgbench balances intact, CHECK TABLE clean on every MySQL run, and a clean filesystem check at the end.

Firecracker passed as well: 150 kills across PostgreSQL, MySQL and Valkey, about 21 million acknowledged commits, nothing lost. But only after we changed its disk cache mode. With Firecracker's default cache_type=Unsafe, every PostgreSQL and MySQL copy we cloned from a running guest failed its checks, with tables missing and 60,896 commits absent. With Writeback everything came out clean, at a cost of 18% PostgreSQL throughput with one client and 10% with eight. If you run anything durable on Firecracker, check that setting first.

One rule came out of this that holds for either VMM: after a crash, cold-boot the disk and never restore the old memory snapshot onto it. We tried it once. PostgreSQL came up looking healthy and was silently missing 4,310 commits, on a corrupt filesystem.

Wake from a snapshot

Wake pathFirecrackerCloud Hypervisor
PostgreSQL, restore to first query62-97 ms245-269 ms
MySQL, restore to first query52-55 ms341-457 ms
Valkey, restore to first query49-52 ms319-339 ms
Next.js, first byte after a wake, 30 cycles (p50 / p95)241 / 270 ms378 / 432 ms

Cloud Hypervisor lands at about 0.25 to 0.45 seconds. Firecracker restores a database in under a tenth of a second, which is a real advantage, and we come back to it below.

A guest that has been stopped to a snapshot holds no host memory on either runtime. What it costs is disk: about 130 MB for an idle Next.js guest on Cloud Hypervisor and 94 MB on Firecracker, and about 41 MB for an empty PostgreSQL guest on Firecracker.

Tail latency under load

For the Next.js workload, this is the result that decided it.

MeasureContainersCloud HypervisorFirecracker
Next.js p99, 400 req/s over 40 apps7.9 ms (one pass)11.9-12.3 ms490-754 ms
Next.js slowest request78 ms (one pass)319-408 ms1,190-1,551 ms
PostgreSQL p99, 2,000 TPS over 100 guests2 ms69-83 ms1,026-1,367 ms
Host CPU per Next.js request6.6 ms10.7-11.8 ms12.0-14.1 ms
Host CPU per PostgreSQL transaction0.79 ms4.15 ms5.68 ms
PostgreSQL transactions per second one lab server sustained4,0001,000-1,500under 500
Host memory per awake, idle Next.js app (MB)80159-188109-128
Host memory per idle PostgreSQL (MiB)327458

Every Next.js pass served 24,000 of 24,000 requests with no errors on all three runtimes, and the typical request took 2-4 ms on all of them. The difference was entirely at the slow end. On Firecracker, about one request in a hundred took half a second or more. On Cloud Hypervisor the p99 stayed at 12 ms in three of three passes. Databases showed the same shape on a different machine: 69-83 ms for Cloud Hypervisor's slowest 1% against about one second or more for Firecracker.

A median hides this completely. If you benchmark a VMM, look at p99 and the maximum, under a load that keeps many guests busy at once.

CPU: the same overhead hurts databases more

Look at the CPU rows again. On Next.js, Cloud Hypervisor costs 1.6 to 1.8 times a container's host CPU per request. On PostgreSQL it costs about 5 times a container's CPU per transaction. That looks like two different VMMs, but in absolute terms the extra cost is similar: about 4.1 to 5.2 ms per HTTP request and about 3.4 ms per transaction (calculated from the table).

The thing to know is that a VM charges per network round trip, not per unit of useful work. Each round trip pays for VM exits, virtio queue handling and waking a vCPU. We counted 70 to 130 VM exits per TPC-B transaction. A Next.js request does several milliseconds of rendering for each round trip, so the toll is a modest share of the total. A small database transaction does well under a millisecond of work per round trip, so the same toll becomes most of the bill. That last part is our reading of the numbers, not something we isolated in a separate test.

Tuning moved it a little: a different guest disk backend gained 16-28%, one vCPU instead of two 10-16%, and disabling halt polling gained nothing.

It also gets worse when the machine is busy. With background work holding the server at 70% CPU and 500 transactions per second across 100 guests, the containers' p99 was 9.5 ms and Cloud Hypervisor's 62.8 ms.

Memory per idle VM

An idle, restored PostgreSQL VM cost 74 MiB of host memory on Cloud Hypervisor against 32 MiB in a container. That figure counts the drop in available host memory, so it includes host-side caching, which is about half of every VM number.

Restored guests only hold what they touch, and that can flip the comparison. An idle MySQL restored from a snapshot used 153-155 MiB against 439-441 MiB in a container, because only pages touched since the snapshot are resident.

For Next.js the gap is wider in absolute terms, 159-188 MB per awake app on Cloud Hypervisor against 80 MB in a container, because a Node process touches far more memory than an idle PostgreSQL. The multiple, about 2 to 2.35 times, matches the databases.

Where Firecracker wins

Firecracker is the better tool in three ways, and none of them is small.

Wake time. 49-97 ms from snapshot to first query for databases, and a Next.js p50 of 241 ms against 378 ms. For a sandbox that wakes, runs for a few seconds and goes back to sleep, that is most of the user's wait.

Memory per awake guest. About 40 to 70 MB less per awake Next.js app than Cloud Hypervisor. When memory is what runs out first, that means more awake guests per server.

A smaller surface. Firecracker was built to emulate as few devices as possible. Less emulated hardware means less VMM code a guest can reach. Cloud Hypervisor is also minimal by general standards, but it carries more, including live CPU and memory resize. In our tests that worked under load: a PostgreSQL guest went from 1 vCPU and 1 GiB up to 4 vCPUs and 8 GiB and back with zero failed transactions.

If your workload is short-lived and mostly idle between bursts, Firecracker's numbers are hard to argue with. Ours were long-lived servers under steady traffic, where the slow end is what people notice.

Two gotchas worth knowing before you ship snapshots

The clock stops while the guest sleeps

A guest restored from a snapshot resumes its wall clock where the snapshot stopped it. Sleep an hour, wake, and the guest thinks no time has passed. Setting the guest clock from the host after every restore, before the guest takes any traffic, handles that part.

That was not enough for Next.js. Next.js 16.4 stamps cache entries with Date.now() but measures their age with performance.timeOrigin + performance.now(), and that clock does not advance while the VM is asleep. Cached pages looked younger than they were, for as long as the app had slept in total, so ISR stopped refreshing. The fix is a small preload loaded through NODE_OPTIONS that makes performance.now() follow the wall clock. After a 78 second sleep, the clock, after() and ISR all passed.

We have not tested the database side of this. Our guess is that a restored database guest without the host clock fix would report a stale now(), and that timers built on the monotonic clock (idle timeouts, TLS session lifetimes, replication keepalives) would see the sleep as zero time. If you run databases from snapshots, check it.

A confinement flag that turns a restore into a cold boot

Cloud Hypervisor can confine itself with Landlock, so the VMM process can only touch the files it needs. On v54.1, passing --landlock together with --restore is rejected unless you also pass --kernel. With --kernel added, it does not fail. It silently cold-boots an empty VM instead of restoring your snapshot.

What does work: a plain --restore of a snapshot taken from a confined VM brings the saved rules back with it. The restored config shows landlock_enable: true, and a disk hot-added from outside the allowed directory fails with EACCES. So we restore without the flags and check the snapshot's saved rules before starting it. If your restore path ever takes far longer than usual, or a woken app has no state, look at this first.

Where we landed

For the Next.js workload, Cloud Hypervisor is the one we would pick. An app server that stays up spends its life under load, and a p99 of half a second is something users feel. A wake that is about 0.14 seconds slower is not.

For databases we are not drawing a conclusion yet. Small transactions are sensitive to the per-round-trip cost described above, so the answer depends heavily on the workload, and we are still testing.


If you would rather not think about VMMs at all and just want a database, create one on Layerbase Cloud. PostgreSQL, MySQL, Valkey and the rest of the 19 Cloud engines, on one account.