Mhonn YbañezSRE, DevOps, AI Engineer
 Today I Learned
Read the full page

Is there such a thing as a serverless database?

Posted
Tags
databases, postgres, distributed-systems

Yes. The servers still exist, but compute and storage live on separate machines and scale on their own. That split is what makes scale-to-zero possible, and it's also where cold starts and network latency come from. The storage side isn't a dumb disk, either: it has its own compute that turns the write log into data pages.

At work we were short on compute for an initiative we wanted to pursue. So I had an idea: what if we keep the compute local and put the data in the cloud? At least the data would stay in sync. That got me wondering whether databases already work this way, which led me to serverless databases.

The question I had

Is there such a thing as a serverless database? And if there is, how does it actually work?

What I found

What "serverless" means for a database

Yes, it's real. And like every serverless thing, the servers still exist. You just never see them.

  • The provider runs everything. Hardware, operating system, database software, patching.
  • It scales on its own. Compute grows and shrinks with traffic. Some can scale to zero, meaning they shut the compute down completely when nobody is using it.
  • You pay for what you use. Instead of renting a fixed-size server around the clock, you pay for the compute time, storage, and I/O you actually consume.
  • Compute and storage are separate. This is the part that makes the rest possible, and the part I spent the most time on.

Compute and storage live on different machines

My first guess was that "separated" meant two processes on the same box. It doesn't. They're different clusters of machines, connected by the data center network.

  • The compute layer runs the database engine in VMs or containers. It parses queries, sorts, joins, and caches data in memory. It keeps no permanent data files.
  • The storage layer is a separate, purpose-built storage service, replicated across machines and usually across availability zones. Its job is durability. Object storage like S3 often sits behind it for long-term data and backups.

Why split them, if keeping them together is faster?

  • They scale independently. Lots of data but few queries? Pay for storage and almost no compute. Small data but heavy queries? The other way around.
  • New compute is quick to add. The data already lives in shared storage, so a new compute node doesn't copy any files. It just connects and starts working.
  • A crash loses no data. If the compute machine dies, the provider starts a new one somewhere else and points it at the same storage.

The cost, part 1: cold starts

Scaling to zero is great for the bill, but the next query has to wait for the database to wake up. That's heavier than a serverless function's cold start, because several things have to happen:

  1. Start the compute. Boot a VM or container with the database engine.
  2. Route the connection. The proxy in front connects your client to the new node.
  3. Load the metadata. Schema, table info, and keys come from storage.
  4. Warm the cache. The new node's memory is empty, so the first queries all go to remote storage. They're slow until the cache fills.

How long it takes depends on the provider. The ones built for this, like Neon, usually wake in under a second or so. Older designs could take much longer.

Providers soften it in a few ways:

  • Keep a small minimum running. No true zero, but no wake-up wait either. You trade a bit of cost for always being ready.
  • Hold the connection in a proxy. Your client connects to the proxy, and the proxy waits while the compute wakes up behind it.
  • Keep warm compute ready. A pool of already-booted nodes that can be attached quickly.

The cost, part 2: the network hop

Because compute and storage are on different machines, anything that touches storage crosses the network. But reads and writes feel it very differently.

When you pay the hopWhy
ReadsOnly on a cache missThe compute node keeps hot data in memory (and often local SSD). Repeat reads never leave the machine.
WritesEvery commitA write isn't safe until storage has it. Storage also copies it to several nodes before saying "done".

So for a read-heavy app, the hop mostly disappears behind the cache. For a system doing nonstop, latency-sensitive writes, it doesn't, and a database with its own local disks can still be the better fit.

Ship the log, not the page

To make writes cheaper, databases like Aurora and Neon don't send whole data pages over the network. They send the log: compact records of each change (redo log in MySQL terms, WAL in Postgres terms). A log record is far smaller than the page it changes.

Aurora, for example, writes six copies across three availability zones and treats a write as done once four of the six confirm.

Where my epiphany came in

If the compute only sends logs, then something on the other side has to turn those logs into actual data pages. So the storage layer must have compute too.

And it does. The storage nodes aren't dumb disks. They run their own software that:

  1. Saves the log record to disk and confirms it, which is what makes the write durable.
  2. Applies the logs in the background. If one record says "age = 30" and the next says "age = 31", the storage node folds them into the data page.
  3. Builds pages on demand. If compute asks for a page that isn't caught up yet, storage applies the pending log records right then and sends back the current page.

That also moves work like backups and cleanup off the compute node you're paying for, so your queries don't slow down while they run. It's still "serverless" to you because you never see or manage those storage CPUs. You get billed for storage and I/O.

Is the compute just a proxy, then?

That was my next guess: if storage does so much, maybe compute just passes queries through. Not really. The compute node is a full database engine, just without a permanent disk. It:

  • Parses and plans SQL. Checks the schema, picks indexes, builds an execution plan.
  • Does the work. Joins, sorts, aggregations, functions.
  • Manages transactions and locks. Makes sure two transactions don't change the same row at once.
  • Is the main cache. Most repeat reads are answered from its memory without touching storage at all.

There is a proxy, but it's a separate piece in front. Altogether there are three tiers, and each one scales on its own:

TierActs likeWhat it does
ProxyThe gatewayHolds your connection, routes it to a compute node, and wakes compute up if it's asleep
ComputeThe brainA Postgres or MySQL engine in a VM. Runs SQL, caches data, and scales up and down with load
StorageThe safeReplicated storage that receives the log, applies it to pages, and keeps the data durable

Because the compute holds no permanent data, the provider can throw it away, add another one, or resize it without moving a single byte of your data. A new one just starts with a cold cache.

Is it the same as a serverless function?

Similar idea, but not the same. Both are compute you don't manage, that shuts down when idle, and that keeps its permanent data somewhere else. The difference is how they scale and how much they hold while running.

Serverless function (like Lambda)Serverless database compute
LifetimeOne request or a short burst, then it may be thrown awayStays up while there's traffic, suspends after minutes of idle
How it scalesOut: more copies side by sideMostly up: the same node gets more CPU and memory
State while runningNothing worth keepingWarm cache, open connections, transactions, row locks
Cold start costBoot the runtime and code, then full speedBoot the engine, then slow until the cache warms up
ConnectionsShort-lived, possibly thousandsLong-lived, which is why the proxy sits in front

The big one is writes. Something has to own the locks and decide which change came first, so there's usually one node that handles writes, and it grows or shrinks in place. Extra copies are read replicas. Thousands of functions can still send writes to that one node, the same as with any database. Functions get away with being throwaway because they push all their state into... a database.

Is it really for production or better for non-production data consumers?

At one point I guessed that serverless databases weren't really for production traffic. Production would run on a normal database, and a serverless one would sit on the side for metrics, analytics, and ML, synced from production.

That pattern is real, but it's a different split. A transactional (OLTP) database serves the app: lots of small reads and writes that need to be fast. An analytical (OLAP) warehouse or data lake handles a few huge scans, usually fed from the transactional one. Either side can be serverless or not:

RegularServerless
Production (OLTP)RDS Postgres, self-hosted PostgresAurora Serverless, Neon, DynamoDB
Analytics (OLAP)Self-managed Spark, provisioned RedshiftBigQuery, Snowflake, Redshift Serverless, Athena

I think the mix-up makes sense, because splitting compute from storage got famous through warehouses like Snowflake and BigQuery. But serverless databases do run production traffic. DynamoDB is serverless and is one of the most used production databases on AWS. And regular Aurora, with servers you size yourself, already uses the same log-applying storage layer. Serverless only changes how the compute is sized.

Where it fits well: spiky or unpredictable traffic, lots of small databases (one per customer or per preview branch), dev and test, new products that don't know their load yet. Where it fits less: steady heavy load around the clock, where a fixed server is often cheaper, and latency-sensitive heavy writes. In production, people usually keep a minimum above zero so nobody waits on a cold start.

Isn't this just managed?

This was my last pushback. It felt like "serverless" was just a fancy name for "managed". It's closer to a stricter kind of managed:

Self-hostedManagedServerless
Who runs servers, OS, patchesYouProviderProvider
Who picks the server sizeYouYouNobody, it sizes itself
Do you pay when it's idleYesYes, by the hourLittle or nothing
Traffic spikeYour problemYour problem: resize, add replicasScales on its own
ExamplePostgres on your own VMAmazon RDS for PostgresAurora Serverless, Neon, DynamoDB

It's the same ladder I saw for runtimes in my Kubernetes post: custom Kubernetes, managed Kubernetes, then serverless. Each step hands more of the work to the provider.

Every serverless database is managed, but not every managed one is serverless. The test is one question: do I still have to decide how big the server is? With RDS I pick a size, pay for it all day, and resize it myself. With serverless, that decision goes away too.

My skepticism wasn't totally wrong, though. The name oversells it: there are plenty of servers, I just learned about three fleets of them. "Serverless" really means "no servers for me to think about". And some products that scale between a minimum and a maximum and never reach zero are closer to "managed with autoscaling". It's more of a spectrum than a strict category.

Takeaway

A serverless database is a normal database engine with its disk moved to another machine, and that machine has a brain of its own. Picking one isn't about the label. It comes down to my own questions, and the shape of the traffic decides both:

  • Cost vs performance. Is the tradeoff acceptable? Spiky or idle traffic is often cheaper on serverless, and steady heavy traffic is often cheaper on fixed servers. The performance cost is cold starts and slower writes.
  • Cost vs overhead. Do we have room for more maintenance? Self-hosted is cheapest on paper but everything is on us, managed takes the ops but leaves the sizing, and serverless takes the sizing too, for a premium.

Plus one more: how hard would it be to leave? Postgres-compatible options can move back to plain Postgres, while something like DynamoDB means rewriting the data layer.

As for my original idea: serverless doesn't give us more compute, it's just someone else's compute billed by use.