Navigating Unknowns While Migrating 50-ish Database Instances Online

At Stream, we have been migrating our entire infrastructure from AWS to GCP. Databases are among the highest-stakes parts; they're stateful, and we want to minimize the impact as much as we can. We had 50-ish database instances on RDS (AWS's managed Postgres service), and around half of them are at TB scale. Every Stream product (Chat, Video, Feeds, and Moderation) runs on these databases, so this migration touched every team in the company. Each of them has different traffic patterns and performance bottlenecks. The end goal is to migrate all of them from RDS on AWS to CloudNativePG (CNPG) on GCP, online.
The entire team has extensive experience with Postgres, but we didn't have much experience with either Kubernetes (k8s) or CNPG, an open-source Kubernetes operator that runs and manages Postgres clusters for you. At Stream's scale, the entire migration is a long process with tons of unknown unknowns.
We couldn't uncover every unknown up front, and we didn't have to. Instead, for each step we asked: "If what we don't know goes wrong here, are we still fine?" Where the answer was no, we either reshaped the plan or explored just far enough to make it yes. Then we moved on, with the rest still unknown.
I led our move to CNPG, from how we run it to how we migrated onto it. In this post, I'll share how that played out: first the unknowns we had to resolve before anything else, then the ones we carried into the migration itself.
How we decided what to explore and what to leave unknown
For each part of the project, the answer to that question decided what we did next:
- If yes, we proceed with it still unknown, and learn along the way.
- If no, we reshape the plan until the answer becomes yes.
- If no reshaping can get us there, we explore that unknown first, and stop as soon as the answer becomes yes.
The question gives us a stopping point. The goal of each exploration is not to remove the unknown, but instead to make its worst case survivable.
We divided the migration into two parts:
- The migration itself: we need a way to migrate data online from RDS to CNPG.
- The operations after it's migrated.
Our team had done several live data migrations between different RDS instances, so we believed the migration was the part we knew better (more on that later). But the bigger reason was the cost of being wrong. If we found out CNPG didn't work for us only after migrating, no reshaping of the plan could make that survivable. If it turned out CNPG was too tricky for us to operate, we wouldn't bother with the migration.
So we reversed the order and validated CNPG first, before diving into the migration.
Part 1: Can CNPG work for us?
Below are the unknowns we had to resolve before starting. The worst case we wanted to avoid was that, after all the migration effort, CNPG didn't work for us. We split it into the dimensions we cared about, as follows. We knew it wouldn't be a complete list, but simply thinking through an initial list can turn some unknown unknowns into known unknowns. For each one, we explored only until its worst case was ruled out, and deliberately left the rest unknown.
Day-2 Operations
Worst case to avoid: It's too complicated for a small team like Stream to operate.
Day-2 operations are the ongoing work of running a system after launch: scaling, upgrades, and recovery. The output of this part is the answer to one question: Are we comfortable operating CNPG?
Stream is a small team, so we need daily operations, such as scaling up IOPS (disk read/write operations per second, which cloud providers charge for) and upgrading the Postgres version, to be as easy as they were on RDS. The only way we can achieve that on a self-hosted solution is to leverage AI skills. So we listed the most critical operations based on our past experience, built our own CLI tools and AI skills for them, and saw how it felt.
Limiting the list to only the most critical ones is also important, because the goal here is to make sure the most critical ones work, and to be confident extrapolating that experience to the rest. For us, some items on the initial list were:
- Failover: This was the first one we built because it's the building block of many other operations. Our connection pooler (a proxy that lets many app connections share a small number of database connections) could also complicate it. We wanted to know how long the customer-facing downtime was, and how it worked so that we could optimize it when needed.
- Scaling up the machine (CPU, memory): This involves node pool replacement and failover. If we can do this, node replacement should be similar.
- Scaling disk size and speed up or down: It's on the list because it's one of our most frequent operations.
- Postgres minor and major version upgrades: This was on the list because version upgrades can involve logical replication (streaming row-level changes from one database to another) and can sometimes be risky. We wanted to make sure the complexity was acceptable for us.
- Backup and restore: It's on the list because it's definitely the most critical one. We wanted to make sure we could restore a new cluster under various outages, and to know how long the downtime would be.
What we deliberately left unknown
We consciously left out some items during this phase because we were confident they could be polished over time. Even if they went wrong at this stage, nothing in production would feel it. Some of them were:
- Developer experience (DX) of the CLI tools and AI skills: It's important for the CLI tools and AI skills to have good DX. You don't want engineers scratching their heads during a 3am incident, trying to figure out how each CLI option differs from the others. But during this verification phase, it was fine. We just needed to keep a backlog and fix them before running in production.
- Configuration glitches: Sometimes there were glitches, such as "password hash mismatches between restarts". We usually identified the cause and a potential fix, but left it in the backlog during this phase because it wasn't a blocker.
- Monitoring and alerting: We knew they were important and critical, but only in production. We consciously left them out to save time at this stage.
Performance
Worst case to avoid: CNPG cannot meet our performance requirements. If this happened, we would end up migrating our databases to something that's too slow. We already knew how our databases performed on RDS and which levers to tune. So in theory, if we matched the RDS size, it should work. The validation here was to catch the unexpected cases and get a general idea of what CNPG's stats look like under real load.
We picked some databases, and for each one we:
- Spun up a CNPG cluster matching its RDS size.
- Copied the data over to CNPG with pgcopydb, a tool that copies the existing data (the COPY phase) and can then follow new changes as they happen.
- Put a proxy in front of the source DB and mirrored all queries to CNPG.
- Observed the key stats on CNPG.

What we gave up and what we strengthened
In this experiment, data consistency on CNPG wasn't important. We didn't run any follow-up during the initial COPY, and we knew the mirrored queries could be lost or fail. But that was fine, because the primary purpose was to learn how CNPG performs with real data and traffic. For the same reason, we also skipped CNPG's monitoring and alerting at this point.
On the other hand, the newly introduced proxy was now on our critical path. So we made sure monitoring, alerting, and error handling were in place so it wouldn't impact production traffic.
Price
Worst case to avoid: The migration cannot save us enough money.
One of the business goals of the entire migration is to save infra cost. In theory it can, but how much? And can that justify the engineering effort of hosting databases ourselves?
It's very hard to get a precise price estimate. And sometimes you don't have to.
The actual cost of not-yet-built infrastructure can be extremely hard to estimate, because there are so many parts you can be charged for, plus the various discounts you may have. I found it useful to:
- Have a clear idea of the major parts costing money: for databases, it's usually nodes (machines), storage, IO (IOPS and throughput), and bandwidth (app to pooler, pooler to DB, etc.).
- Know the levers you can adjust for the things that cost money: Can we downsize the machine? Can we host it in two zones instead of three? Can we use different storage types (Hyperdisk, GCP's network-attached disks, vs. NVMe, local SSDs on the machine)?
- Have best-case and worst-case estimates: the primary purpose is to avoid the worst case, and it's much easier to get reasonable best- and worst-case numbers than a precise one. So if even the best case won't meet our needs, or even the worst case is acceptable, we can make the call. We didn't need the precise number, only to know whether the worst case was survivable.
Know your system to avoid seemingly attractive options
In RDS and other managed services, we can't read from standby instances as replicas, and we have to pay extra if we need one. In CNPG, read replicas are free. Also, our service is IOPS-heavy, and we usually needed to upgrade the node type to get more IOPS. So one plan to save infra cost was to:
- Enable read replicas on the application side.
- This spreads IOPS, so we can potentially downsize the machine type to save cost.
But after building a prototype, we realized read replicas wouldn't offload as much IOPS as we expected, because the buffer pool cache (Postgres's in-memory cache of recently used data) served most queries. Also, in CNPG, any node can become the primary during a failover, so each of them also needs to be able to serve the write load. With all this considered, the effort on the application side wouldn't justify the infra cost savings. It would also have brought a new set of unknowns on the application side. So we ruled this option out at this phase.
Part 2: The Migration
Once CNPG's own risk was managed, the next step was to migrate data from RDS. We had used logical replication to migrate customers' data between RDS instances before, so we expected the migration process to be mostly the same (spoiler alert: it was not). We had an idea of what the major steps looked like, while knowing CNPG had its own quirks we didn't know about yet.
How the migration works

The migration has to be done online, meaning we can't afford much downtime. At a high level, it works like this:
- Make an initial COPY to CNPG. At the same time, collect the changes made since the COPY started.
- Apply the changes made during the COPY, plus any new changes.
- Freeze writes on the source and wait for the sync to drain.
- Cut over by flipping the clients' DB endpoint.
Where failure is survivable
The strategy here is to shape the migration so that even if the unknowns fail, production isn't affected. For our case:
- The COPY and sync phases are safer, because even if they fail, customers won't be affected.
- Note that the COPY and sync do place additional load on the source, such as IOPS and disk space for WAL (Postgres's write-ahead log: the record of every change, which replicas and backups replay), so make sure they're well monitored.
- The cutover phase is critical, because the freeze is visible to customers.
We selectively tighten only the parts that can affect production. On the other parts, we trade completeness for simplicity, because if something fails there, an agent can fix it on the spot without customers noticing.
One new thing at a time: Park at CloudSQL first
Migrating data from RDS directly to CNPG (on GCP) involves two layers of risk:
- It's a cross-cloud move.
- CNPG is new to us.
Part 1 told us CNPG could work for us, but we didn't know whether it was ready to receive a migration.
So we decided to park the data on CloudSQL (GCP's managed database service) first. Unlike in Part 1, we didn't have a specific "worst case" in mind to avoid. It was mostly unknown unknowns: we knew there would be problems on the CNPG side, but we didn't know exactly what they were. When you can't name the worst case, you can't explore it. What you can do is reduce how many unknowns can fail at the same time. So we moved to CloudSQL first to focus on the cross-cloud migration, assuming CloudSQL would be more stable for us at that time.

It turned out to be one of the best decisions we made, because we ended up running into many CNPG-specific issues during the migration, and it was nice to only have to solve one thing at a time.
The WAL disk issue was one of the most interesting ones on the CNPG side. With the serving settings, each CNPG cluster has 3 instances and archiving turned on, which copies WAL to Google Cloud Storage (GCS) for backup and recovery. This means WAL can only be recycled after it has been propagated to the replicas and uploaded to GCS. But during the COPY phase, WAL grew much faster than it could propagate, so it filled up the WAL disk and crashed CNPG.
So we switched to 1 instance with archiving off during the COPY phase, only to shift the bottleneck to WAL disk speed. Recycling couldn't keep up, and the WAL disk still filled up. And even with a faster WAL disk, a large database's index builds still filled it. It turned out CNPG never really turns archiving off: with backups disabled, it still runs its archive step on every WAL segment; it just sends it nowhere. That do-nothing step capped WAL cleanup, so it couldn't keep up with the WAL generated by the index builds. So we had to give the WAL disk far more room during the migration than it needs for serving.
This debugging chain showed that a fix often just shifts the unknown somewhere else. But since we had shaped the COPY phase this way, none of it impacted production traffic.
v2: Trade consistency (No, we are not crazy)
Before long, we realized our approach was too disruptive for customers. Even in the best cases, the downtime was still 3–5 minutes. This meant requesting a maintenance window from each customer on a database before we could move it, which put a huge workload on the customer success team. In some cases it was nearly impossible. This turned out to be the worst case of the "safe" approach.
After trying every possible way to shrink the downtime, which at best was still around 2 minutes, we revisited the nature of the problem. The downtime existed because we needed to freeze writes and wait for the WAL to drain before letting new traffic in on CNPG. That was to preserve the ordering of changes: if we flipped traffic to CNPG before the WAL drained, a change made earlier on the old database could end up overwriting a newer change to the same row made on CNPG (a lost update).
So I went back to see how our earlier RDS → CloudSQL migration had handled the cutover. It didn't freeze at all. It flipped the traffic while the old database was still syncing, and handled lost updates manually as an edge case. It could get away with that because that migration also moved the apps from EC2 to k8s, and that switch was fast enough to keep the overlap tiny. That made me revisit an assumption I hadn't questioned:
Is a lost update really a worst case for us?
Only on some critical paths. Given the nature of our data, most writes in our DB are INSERTs, and most of the UPDATEs are self-correcting. So if we could find a way to guard only the critical tables where we can't afford data skew, we could flip the endpoint while the WAL is still draining and eliminate the downtime completely.
A trade like this isn't an engineering call alone. "Lost updates during a short window" doesn't mean much to a customer success team, so I translated it into product terms: what a customer would actually see, e.g. "a message edited during the switch might show its previous version". Framed that way, CS and product agreed the risk was much smaller than asking every customer for a maintenance window.

- (same) Make an initial COPY to CNPG. At the same time, collect the changes made since the COPY started.
- (same) Apply the changes made during the COPY, plus any new changes.
- (new) In parallel:
- Cut over by flipping the clients' DB endpoint.
- Wait for the sync to drain.
In the new version, we flipped the service endpoint while waiting for the remaining WAL to drain. This creates a both-write window where lost updates can happen. Since flipping the service itself also took time (surge-deploying the k8s pods: starting the new pods before the old ones stop, so the service never goes down), the actual both-write window was:
max(WAL draining time, service flip time)
In our case, it was mostly under 20 seconds, dominated by the service flip time.
When applying the WAL to the critical tables, we carefully compared the timestamps from each source to make sure the final result on CNPG was correct. It held up: the equality checks found no lost updates on the guarded tables.
Tiering the databases. But how?
We had around 50 databases to migrate, each with different traffic patterns, scales, and performance bottlenecks. We knew we wanted to start with the "easy" ones and learn from the experience. But what does "easy" mean? Should we tier by data size, throughput, IOPS, or other dimensions?
We built the first version of the migration skill and ran several drills simulating different data sizes and traffic patterns. The intention was to apply the scientific method: form an initial hypothesis about which dimension can break what, then run on small, quiet databases first to refine the theory and iterate.
For example:
- During the COPY phase, data size drove how long it took and how much IOPS it consumed, which in turn affected the parked WAL size.
- Index size drove CPU consumption on the target side (when the target built those indexes). It also affected the parked WAL size.
- Applying the changes on the target was IOPS-heavy. So if the source's write rate was high, we needed to over-provision the target, otherwise the sync couldn't catch up.
Finding the first production database to start with was tricky, because we weren't sure whether our theory was true. But on the quiet ones without much data, we could tolerate more risk. We also carefully shaped our procedure to separate the risky parts from the non-risky parts. In this case, anything before the cutover is relatively safe, so we could allow more unknowns when picking the next database to migrate. But anything after the cutover was critical, so we ran every kind of drill we could to verify the unknowns before running on the real ones.
This served us quite well. During the both-write window, we found a specific application path that issues huge transactions, making conflict resolution much riskier. So we added that path's likelihood to our tiering criteria, something we could never have thought of without running in production. It was exactly the kind of unknown we couldn't have resolved up front, and it surfaced in a place where we could still handle it.
Closing Words
It's been a long journey, and it's still ongoing. We learned a lot along the way:
Navigating unknowns: The question we kept asking was: if this goes wrong, are we still fine? Sometimes getting to yes isn't trivial, and we need to shape our approach to make it so.
Engineering happens at the shortcuts unique to your system: The v2 change, where we traded data consistency for availability, is a perfect example. Without the context it seems crazy, but once you understand the nature of the data, it turns out to be a good trade-off. Knowing your system is what tells you which failures you can actually survive.
The best design is the one that's never built: In our case, the best example was read replicas. It's a good pattern in general, but it wasn't aligned with our goal, so we left it out. Every option you add brings its own unknowns, so ruling one out removes them too.
Work with AI: The entire process wouldn't have been possible without AI. AI made exploring cheap and made fixing survivable failures cheap, which let us leave more things unknown. But in our case, AI also tended to over-engineer in many ways, and it doesn't take long for your procedures to become something no one can understand. That deserves its own post, but the core takeaway is that you can't outsource understanding, because you need that understanding to decide what to solve and what to let go.
Here is where we are: we have migrated 26 databases with 17 TB of data, with zero unplanned customer-facing downtime. The team is comfortable operating CNPG, performance has been on par with CloudSQL so far, and we are saving infra cost as expected. Thanks to the v2 cutover, nearly all customers migrated without needing a maintenance window. There are still unknowns for the even larger databases out there, but we believe the same learning loop will help us navigate them safely.
