Home | Archive

live migrations

🌱 tags: inkhaven sre updated: ,

(an accounting parable in the process of haphazard expansion; to be later divided into three parts)1

In the winter, the birds come in their thousands. On the trash heaps, you can see the storks perch; off the southernmost tip of the Mumbai coastline, in November, you'll see a patch of flamingos, floating like dirty-colored effluent on the waves. We're so used to nasty things on city shores that it takes a moment to notice that these things are alive, alive, alive on the waves. Too young to be pink yet.

When a company wants to move where its services are hosted, here is what we wish would happen: why-dont-we-24e22cee9a.jpg

And here is what it feels like when one actually does it: 2tws3v.jpg

(artistic depiction, to be later replaced with lovingly hand-drawn diagrams)

I feel the need to take a moment to marvel that this sort of thing – the movement of massive virtualized machines from host to host, across companies and continents, with the expectation of minimal disruption of service – is possible in the first place. A moment of silence to experience the awe of modern day cloud computing.

Okay cool, let's move on.

Here's the problem:

You might recognize three of these four as together forming the CAP theorem (famously, "pick any two")2. As for the fourth, well, that just says you also need to be able to do it all backwards.

Fortunately, at least in principle, this is very simple to solve for!

You just need to figure out which two things you want to pick for each step. And then you need to break down the steps until they are small enough that these compromises don't hurt.

(Beware, however, The Danger: more steps means more places things can go wrong.)

First, an audit:

Consider our service: a social media app for birdwatchers to log sightings of birds, tagged with a GPS location and short messages. These "tweets", if you will, are sent out to other birdwatchers in your area, so they can keep an eye out for the same species – or perhaps the same specimen! – of bird.

It's day three. You finally have all your accounts on everything set up. You get on a call with the CTO and the person who, you are told, is going to be your primary point of contact for this whole thing.

They will screenshare draw.io, and draw you five boxes. This, they say, is the deployment.

They are wrong. Not wrong, exactly, but they have a certain way of imagining things. A CTO, a product manager, these types of people have very particular ways of imagining the thing you're both looking at together. To them, these things are like capabilities – or perhaps more baldly, waterwheels in the revenue stream. They think, what does my product do? And then, what does it need to do it? And that's what they tell you.

This is not quite what you need to know. Here's what you care about:

  • What's actually happening in there? Forget what it's meant to do: what's at all actually doing?
  • What will hurt when it breaks, and how much? What's going to get them mad at me?

So. Armed with the variously well-grounded map your liaison/leadership has given you, you embark upon your forensic expedition.

Get to know your services

  • API serves the API request made by the app and the website. Straightforward, cleanly. Deployed as a Docker container.
  • Frontend is the website. You get a Github repo when they tell you about this, as is only right. It's served by the load balancer straightforwardly, but you have a tiny little service that tracks user sessions. It's mostly redundant with the app code, really. Probably entirely redundant. Should have been deleted eight months ago, but there was this whole feature push, and then lots happened. Anyway, they're working on it.
  • Inside the API code, you have a Terraform script that spins up a Memcached. It's only for testing.
  • Production does use Redis, though, to keep track of GPS coordinates. This is how the API decides which collection of tweets to serve to which user. It's quite a clever use of GIS. The logic for it all lives in API, where you note approvingly that the Redis endpoint is configured via an environment variable – and then, less approvingly, note that the environment variable is overridden in the src/config/vars.go, if IS_DEV is set to true. A search for IS_DEV across every code repo you have access to turns up no other uses of IS_DEV, anywhere.
  • There's a photo bucket cached at edges, which the CTO tells you is informed by the Redis GIS data but the logic for which will take you 3 weeks to get somebody to show you where and how. The backing store is an object store. This sort of thing is, if not S3, an S3-like that "speaks" the S3 API. It shouldn't be surprising, and it isn't. It's just S3. (The buckets are atrociously named, but the buckets are always atrociously named. You yourself have never named a bucket well in your life; every time you try, the sight of the form field inspires you to black out for thirty seconds and then it exists and it's called mealsquare3-2_sandbox and you don't care anymore so you don't change it.)

Breathe. We're only halfway through.

  • bg is a server running in a virtual machine with a homebrewed Github actions deployment pipeline and whose IP address is hardcoded in a dozen places in the code. It calculates thumbnails, recognizes birds, runs the recommender algorithm, and also refers to the Redis. (This is deemed okay and safe because bg doesn't write to any of the production stores unless the call to it is about production data.) You are seized at 11:30PM one Tuesday night with primordial terror, and wake up to check whether Redis is the only place where GIS data is written. You note with relief that of course it's also written to the Postgres database, and are vaguely ashamed for having needed to check. These are competent people. These are your peers. These people have been here since the beginning of this company, and could maybe just buy you? The person, wholesale? – considering the equity they've accrued. You should have more respect.
  • There's also batch, which is importantly different from bg in that it primarily exists to update the bird-recognition models. It downloads and uploads massive corpora of photo data from the photo bucket on a daily basis – seemingly over the public internet. You breathe deep.
  • Two weeks in, you discover the secrets management system. This one you've prepared for, and you were prepared to be more horrified than you are. At least it exists, you know? At least it appears that they don't need to send each other secrets on Slack. (Although, you know, they probably still do.) Are you supposed to have access to these? Probably if they could figure out how to make it possible for you to do your work without needing access to these, they wouldn't need you in the first place. You click back out, run a script to grep for every secret-key-like string in every repository you've been given access to, and save the results to a file. You have already decided that outside of this measure, you will avoid the rest of the question for as long as you possibly can.

Breathe again. The most important parts:

  • The database. Seven copies of three databases, in fact; all on separate database instances, of course, for sanitation reasons. Which for which? Some are for testing or staging environments; for others, we create dummy databases in the build scripts, because they're small and we don't need to do UAT (User Acceptance Testing, otherwise known as it's so hard to fake convincing userdata that we just renamed you Oogle Boogle living at 1234 Fivesix Lane in our testing environment and called it a day) on them. Each in its dignity is possessed of a storied history of schema migrations; there is real design thought put into the shape of their entities and relations. Too bad they all use the default RDS postgres config, but that's easily enough fixed.
  • The virtual networks. These exist, but nothing uses them correctly. Though you were forewarned, you'd forgotten – perhaps you'd repressed the knowledge in horror – the API server talks to the database over the public internet. It's hard to find words for how scary this is. It's like these people have never heard of .

Exhale. We're done. This is as good as it's going to get. There we have it: our rogues' gallery It's been three days and you owe these people a plan. A roadmap, as it were.

You know you don't understand everything you need to to guarantee that you will break nothing along the way. To guarantee that, you'd need years of study.3 So what you need to find out next is the answer to your question 2.

What are your SLOs?

In other words, what will get them mad at me?

What are your service obligations? What's going to make your employer tsk at the inconvenience, vs stay up all night on the call with you, asking for an update every fifteen minutes? What costs anxiety, vs what costs money?

In other words: what is your real priority order for things to go wrong?

Get clear on this early. Get numerically clear on this early, if you can. How many minutes of downtime can you tolerate for this exercise? What's the conversion rate of scheduled to unscheduled? Weekend to weekday? Day to night?4

  1. Our app cannot lose data: ornithology itself will wither on the vine. Tweets are scientific posterity. They are also a bedrock of user and community faith. Therefore, the Postgres is your baby, the thing you will protect with your life and tuck in at night. This is usually how these things go; data above all.
  2. There are "critical" or "high-priority" regions where a rare bird or seasonal phenomenon is underway. Downtime in these regions hurts the business.
  3. Duplicate or corrupted writes are potentially harmful to real user data, but serving incorrect things for brief windows is a somewhat expected risk for our apps' users. So long as any errors are corrected and "tweeted" by the company account, this is at worst an embarrassment.
  4. Downtime in non-critical regions is probably fine, if scheduled well in advance. Management will grumble but concede when you argue the point in terms of the more important priorities.

People don't like thinking about things going wrong. So how do you get these answers without guesswork?

There are a couple of ways, but one very reliable way is to figure out where the engineering effort has already gone. Whatever gets more love is what matters more.

If it's a good outfit, the architecture will reflect these priorities.

So you ask:

What's your current CAP compromise?

The CAP theorem is a magnificent little parable about the constraints networked phenomena operate under. Briefly, it says, if you're splitting work among a collection of machines, you get to pick any two of:

  • collection of machine that always agree
  • collection of machines that answer quickly
  • collection of machines that don't factionalize into competing collections

Which two an org picks for its services, in which cases, will tell you what their priorities are.

Ornithologists want to know what's in the area within seconds, or at worst minutes; even if one time in ten the info is bad, they'd rather hear about it than not.

Therefore our architecture prioritizes Availability. We have network edges, geospatially sharded; aggregation to the central deployment takes minutes verging to hours for photodata.

Okay. With this, you feel like you have a handle on where you're at.

Where are we going?

Let's say our birdwatching company wants to become GDPR compliant, and is trying to move its center-servers to Europe. That's it, that's the whole thing. (And thank goodness, too, because we've got enough going on just trying to get this all done at all.)

(Well, while we're here, it sure would be nice to standardize bg with our other deployment stories.

Oh, and we've run into timing problems with our Redis/Postgres GIS-writing story three separate times in the past two years. Is there, like, a fix for that?

Of course, our secrets are kind of a mess, and it's going to be a bit of a problem for compliance…

Did I mention we also use Redis for our Bull queues? Yeah, Batch talks to it for that…oh, our Temporal? Yeah wait let me add you to our temporal.io account, go take a look. Just out of curiosity, how hard would it be to self-host Temporal? Just asking because of the licensing fees. You're migrating the Temporal region, right?)

The Gantt chart

Here's the secret to how this all works:

Write a dependency tree. then take it up in your hands; and peel it open like an orange. Split the leaves of the tree, and let them fall onto the calendar wherever gravity and linkage naturally takes them.

Lo: you have a Gantt chart.

Okay, here's what I mean:

Every step of this cutover is a source-target pair – i.e. the though you're moving, and where it's moving to. A start state, and end state. Each of these pairs makes a change window. Your job is to figure out the order these timestamps go in, and to do that, you've got to figure out how these change windows relate to each other. To do that, you need three pieces of information:

  • which services depend on which (and which features of their dependencies they need). For this you'll write a dependency graph.
  • what tasks are involved for each individual migration, and how long they'll take. This is just you todo, or your effort estimate if you're being fancy / paid by the hour.
  • when certain changes are being made, certain others cannot be made. Write out your matrix of change locks, or alternately your freeze protocol.5

Here's how you're going to use these three pieces of information, once you have them.

  • For any pair of services, either:
    • A depends on B (direct ancestry)
    • A and B are cousins (common ancestor)
  • If A depends on B, then A is inside B. Put another way: whenever you move something over, it should already have everything in the new place that it needs to start running. This will leave you with some ties to break, which you break with the next rule:
  • Now, if A and B are instead cousins:
    • If A takes longer than B, A starts earlier than B.
    • Of course, if they both take around the same amount of time:
      • If A starts a lock, start A later.
      • If none of these are a tiebreaker, it doesn't really matter. Do what's fun for you.

Like I said, peel the dependency tree open like an orange. This is the best possible way to phrase this sentiment. There are no better metaphors available.6

You shall communicate this to your supervisors/clients/worried onlookers. You shall especially especially stress THREE CRITICAL PIECES OF CALENDAR INFORMATION:

  • scheduled downtime
  • development freezes
  • cutover day

So what does this look like for ornithologyApp?

TO BE WRITTEN WHENEVER I NEXT FEEL LIKE RANTING ABOUT NEWLY OBSOLETE SKILLS 297.png

Footnotes:

1

god, Inkhaven, it's down to the damn wire today, isn't it? May I never speak of work related matters again. Let's go back to mourning our dead professors tomorrow, or something. EDIT [2026-11-20 Fri 19:09]: I have time today and fleshing this out will buy me time on the weirder harder things I am working on. Have some more cranky-old-man SRE war stories and leave me to wrestle with my logic-and-philosophy demons in peace! Begone with ye and yer overbearing daily word count requirements, I have thinking to do and procrastination to do it in!

2

eliding some detail about network partition, don't be pedantic at me about it before I have a chance to justify myself

3

You'd need to read every line of code they wrote, and every line they imported. You'd need to read these six textbooks cover to cover, and then these fifty papers published in the last five years to see what's changed about the network stack between the textbooks' publication time and now. You'd need to get on extended calls with AWS support, get to know them, take them and their bosses out for drinks, convince them to violate their NDAs just a little bit, just for fun. You'd need to create a little mental homunculus of every developer who ever worked at this company – hunt them down on LinkedIn, or Twitter, or across the Yukon, rifle in hand; you may possibly need to reify each one into a little straw doll, stuffed with paper printed over with hashes of the commits they've authored, affixed to a wreath of ethernet cables, hung over your bed to watch as you fall asleep.

4

In which timezone? That one sometimes gets you.

5

Sometimes, we write explainer posts in which we discover that we think of ourselves as idiots. Other times we endeavor for a measure of self-forgiveness and learning from past mistakes. Anyway, have a freeze policy of some sort. It's really easy to be a people-pleaser about this one, I've found; asking people to stop committing their work is daunting. You still need to do it.

6

Okay, fine, go read Critical Chain(Goldratt (1997) Critical Chain, Great Barrington, MA : North River Press, http://archive.org/details/criticalchain0000gold) for the actually understandable metaphor and well-worked example. Look, I never said I was good at explaining these things. I only ever promised, even implicitly, to be entertaining.