Serverless Databases
Databases are the backbone of modern applications, but they are 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 unikernels, combining extreme performance with true scale-to-zero efficiency.
Why Run Serverless Databases on Unikraft Cloud?
⚡ Instant Boot, Millisecond Latency
Unikraft unikernels start in milliseconds, enabling databases to scale up instantly when requests arrive and shut down to zero when idle. This ensures resources are used only when needed, without cold-start penalties.
🔒 Stronger Security by Design
Each database instance runs as a specialised, single-process unikernel, 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 unikernel 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 backend that is fast, elastic, and efficient.
📈 Performance Without Trade-offs
Unlike traditional serverless platforms where databases often suffer from high overhead, unikernel-based instances deliver bare-metal-like throughput and predictable latency, optimised for both OLTP and OLAP workloads.
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
kraft
CLI tool and a container runtime engine, e.g. Docker. -
Clone the
examples
repository andcd
into theexamples/postgres/
directory:
Code
Make sure to log into Unikraft Cloud by setting your token and a
metro close to you. We use fra0
(Frankfurt, 🇩🇪) in this
guide:
Code
When done, invoke the following command to deploy this application on Unikraft Cloud:
Code
The output shows the instance URL and other details:
Code
In this case, the instance name is postgres-saan9
and the service young-thunder-fbafrsxj
.
They are different for each run.
If you use port 5432/tls as per the example above you can now directly connect to postgres:
Code
Use the unikraft
password at the password prompt.
You should see output similar to:
Code
Use SQL and psql
commands for your work.
Idle Scale-to-Zero
This example uses the idle
scale-to-zero
policy by default (see the labels
section in the Kraftfile
). It means that the instance will scale-to-zero even
in the presence of psql
connections. To ensure that the instance is not put
into standby even for long running queries (during which the connections are
also idle), the PostgreSQL example makes use of scale-to-zero application
support. To this end, we load the
pg_ukc_scaletozero
module
into PostgreSQL, which 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.
If you'd like to use a port other than 5432/tls
you'll need to use the kraft cloud tunnel
command to connect to PostgreSQL. See the tunneling
guide for more information. In addition, you need
to explicitly disable scale-to-zero by either changing the label in the
Kraftfile
or use --scale-to-zero off
in the deploy command.
At any point in time, you can list information about the instance:
Code
Code
When done, you can remove the instance:
Code
Using Volumes
You can use volumes for data persistence for you PostgreSQL instance.
For that you would first create a volume:
Code
Then start the PostgreSQL instance and mount that volume:
Code
Customize Your Deployment
Your deployment is a standard PostgreSQL installation. Customizing the deployment generally 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 a different location to mount your volume or set additional configuration options.
And, of course, you can use the PostgreSQL instance in conjunction with a frontend service, see the guide here. However, in that case make sure to disable scale-to-zero if you plan to use the DB internally.
Support for scale-to-zero for internal instances is coming soon.
Learn More
Use the --help
option for detailed information on using Unikraft Cloud:
Code
Or visit the CLI Reference.