Serverless Databases
Databases are central to modern apps, but they're notoriously resource-hungry, slow to scale, and costly to operate at low utilisation. Traditional VM- or container-based solutions keep idle resources running, resulting in waste and inefficiency. With Unikraft Cloud, serverless databases gain the advantages of microVMs, combining extreme performance with true scale-to-zero efficiency.
Why run serverless databases on Unikraft Cloud
âš¡ Instant boot, millisecond latency
Unikraft microVMs start in milliseconds, enabling databases to scale up instantly when requests arrive and shut down to zero when idle. This ensures the system uses resources only when needed, without cold-start penalties.
🔒 Stronger security by design
Each database instance runs as a specialised, single-process microVM, drastically reducing the attack surface compared to general-purpose OSes. This isolation protects customer data with built-in, lightweight security.
💰 Cost-efficient scale-to-zero
Unikraft's microVM architecture allows serverless databases to consume no resources when idle and scale to thousands of instances under load. You pay only for active queries, making it ideal for spiky workloads, dev/test environments, and SaaS platforms.
🛠Seamless serverless integration
Unikraft Cloud natively supports serverless architectures. Databases can integrate with API gateways, event triggers, and headless services running on Unikraft, forming a fully serverless back end that's fast, elastic, and efficient.
📈 Performance without trade-offs
Unlike traditional serverless platforms where databases often suffer from high overhead, microVM-based instances deliver bare-metal-like throughput and predictable latency. These instances optimise both Online Transaction Processing (OLTP) and Online Analytical Processing (OLAP) workloads.
📸 Checkpoints for point-in-time recovery
Checkpointing saves the complete state of a running microVM at any time, without interrupting execution. Checkpoints are incremental, fast, and keep a history, so you can restore the database to any previous checkpoint to recover from a failed migration or an erroneous write.
🔀 Instance branching for instant clones
Unikraft Cloud lets you branch a running instance, creating an identical, independent copy in milliseconds while leaving the original untouched. Test your migrations or destructive changes on a byte-for-byte copy of production before applying them, so you can proceed with confidence.
Getting started
This guide shows you how to use PostgreSQL, a powerful, open source object-relational database system, in a serverless fashion. With Unikraft Cloud, you can run PostgreSQL in a lightweight virtual machine, with minimal overhead and millisecond-fast startup times. The instance will scale-to-zero when not in use.
To run it, follow these steps:
-
Install the CLI. Use the unikraft CLI or the legacy kraft CLI. You need a BuildKit builder. The easiest way to get one is via Docker. You can also set up and use BuildKit directly; see the quick start.
The unikraft CLI is the current standard, while kraft is the legacy version. Choose one of the CLIs below and only run the commands associated with it for the rest of this guide.
-
Clone the
examplesrepository andcdinto theexamples/postgres/directory:Code
Make sure to log into Unikraft Cloud by setting your token and a metro close to you.
This guide uses fra (Frankfurt, 🇩🇪):
The UKC_TOKEN and UKC_METRO environment variables are only supported by the legacy CLI.
When done, invoke the following command to deploy this app on Unikraft Cloud:
The output shows the instance address and other details:
In this case, the instance name is postgres-saan9 and the service young-thunder-fbafrsxj.
They're different for each run.
If you use port 5432/tls, according to the example above, you can now directly connect to postgres:
Code
Use the unikraft password at the password prompt.
You should see output like:
Code
Use SQL and psql commands for your work.
This example uses the idle scale-to-zero policy by default.
This means that the instance will use scale-to-zero even in the presence of psql connections.
The PostgreSQL example makes use of scale-to-zero app support.
This ensures that the instance isn't put into standby even for long running queries (during which the connections are also idle).
To this end, the example loads the pg_ukc_scaletozero module into PostgreSQL.
This module suspends scale-to-zero during query processing.
You can see this in action by running SELECT pg_sleep(10); and verifying that the instance keeps on running.
At any time, you can list information about the instance:
When done, you can remove the instance:
Using volumes
You can use volumes for data persistence for your PostgreSQL instance.
For that you would first create a volume:
Then start the PostgreSQL instance and mount that volume:
Using checkpoints
Limited Access
Checkpointing is a new feature that is not enabled by default and requires a valid license. The interface described here reflects the current implementation and may change before general availability.
You can checkpoint a running PostgreSQL instance to capture its complete state—memory and volume—without interrupting it. Checkpoints are reusable, named restore points that keep a history. Start a fresh instance from any checkpoint to recover from a failed migration or an erroneous write. For a full description of how checkpointing works, see the checkpointing feature page.
To checkpoint a running instance, call the POST /instances/checkpoints endpoint with the source instance name:
Later, restore the database by creating a new instance from the checkpoint:
The new instance resumes from exactly the checkpointed state, while the source instance keeps running unaffected.
Using instance branching
Limited Access
Instance branching is a preview feature and isn't yet available on the public Unikraft Cloud. The interface described here reflects the current implementation and may change before general availability.
You can branch a running PostgreSQL instance to create an independent copy with the exact same state. The source instance keeps running unaffected. For a full description of how branching works, see the branching feature page.
To create a branch, pass --branch with the source instance name to unikraft run:
The branch boots immediately from the same state as the source. Connect to it like any other instance. Whatever you do, the source instance remains unaffected.
When you're done, remove the branch:
Customize your deployment
Your deployment is a standard PostgreSQL installation. Customizing the deployment means providing a different environment.
An obvious one is to use a different database password when starting PostgreSQL.
For that you use a different POSTGRES_PASSWORD environment variable when starting the PostgreSQL instance.
You could also use a different location to mount your volume or set more configuration options.
And, you can use the PostgreSQL instance in conjunction with a frontend service, see the guide here.
Learn more
Use the --help option for detailed information on using Unikraft Cloud:
Or visit the CLI Reference or the legacy CLI reference.