0:00:00Hello and welcome to Developing Perspective. Developing Perspective is a podcast discussing
0:00:04news of note in iOS development, Apple, and the like. I'm your host, David Smith. I'm
0:00:08an independent iOS and Mac developer based in Heron, Virginia. This is show number 137,
0:00:13and today is Thursday, August 8th, 2013. Developing Perspective is never longer than 15 minutes,
0:00:18so let's get started.
0:00:19All right, so I'm going to be talking about catastrophic failure today. It's a thrilling
0:00:25tale involving much sadness, much weeping, much gnashing of teeth that I had yesterday.
0:00:31So that was Wednesday, August 7th.
0:00:34If you're a feed wrangler user, you would have noticed that the service was down for
0:00:37about, I think it was about a half an hour, 35 minutes, I think is where I ended up with
0:00:41the actual outage being.
0:00:44And so I'm going to kind of walk through what happened.
0:00:46It was certainly a first for me.
0:00:48And it's one of those things that you kind of, you prepare for, you plan for, but you
0:00:53you really, really hope that this day never comes.
0:00:58And so when it does come, it's kind of an event.
0:01:00And I thought it'd be interesting
0:01:03to kind of walk through what happened
0:01:04and to talk about how I prepared for it,
0:01:05what happened, what I've done,
0:01:09and just kind of hopefully just put that out there
0:01:11and be transparent.
0:01:14Obviously, a lot of you, I think, are also customers,
0:01:15so maybe it's interesting to hear what happened.
0:01:17All right, so a bit of background first.
0:01:19I'm a, in addition to doing iOS and Mac,
0:01:20I've done Ruby on Rails, which is a web framework.
0:01:25I've worked professionally for,
0:01:28it's coming up in I think about seven or eight years.
0:01:30I started learning and working with Ruby on Rails
0:01:33back just before it went 1.0.
0:01:35So I think it's quite a few years ago.
0:01:37And before I was an iOS guy,
0:01:40I was a professional Ruby on Rails consultant
0:01:41or I worked at a company working as a Rails guy.
0:01:43And I'm pretty familiar with it,
0:01:47and I've been doing it for a long time.
0:01:46I've worked through all the different changes to the language and to the way that it works.
0:01:51I would say I know Rails pretty well.
0:01:55I'm not the scary expert in Rails, because I'm a bit too much fingers in too many pies.
0:01:57I focus a lot more on iOS and Mac kind of stuff now.
0:02:04So it's hard to-- I'm not quite as completely in that world as I used to be.
0:02:07But I'd say I'm pretty good, more than competent.
0:02:12If I was looking at a technical book, you know, in the back, they have the novice, intermediate, advanced,
0:02:15a little thermometer.
0:02:17I'd probably be in the advanced section on the thermometer.
0:02:20So I know Rails pretty well.
0:02:22So yesterday I was doing some work,
0:02:24and part of what this did is it included
0:02:27a couple of what Rails calls database migrations.
0:02:29And database migrations are always something
0:02:31you want to be a little careful with,
0:02:32but essentially what they do is in Rails,
0:02:35you describe a, every time you want to make
0:02:37a database change, you describe it into a file
0:02:40that's designed to be kind of running sequence.
0:02:42And then when you run that migration, it goes through, works out what the most recent one
0:02:47that you've run is, and then runs them through all the new migrations that happen beyond
0:02:53that.
0:02:54So this is typically things like adding columns to a database table, adding an index, that
0:02:58kind of thing.
0:02:59And so this is kind of what we had.
0:03:01The work I was doing included one of those.
0:03:04And then essentially what I do when I have a database change like this that's part of
0:03:08some logic or some code that I'm updating.
0:03:11I hit run my deploy script, and off it goes,
0:03:16and it does this migration as part of the rollout process.
0:03:20And so yesterday I've been doing this change,
0:03:24kind of something I've done millions of times,
0:03:26take it to my kind of staging database, run it there,
0:03:27everything looks good, no problems,
0:03:31things are looking good in terms of the code
0:03:33and the performance, I'm like, "Yeah, this is great."
0:03:35So I hit deploy.
0:03:37Things are going along like normally.
0:03:40The code cycle part of it kind of happens first,
0:03:39kind of a two-phase process, and it rolled out the code, things looking good, and it
0:03:42gets to the database part. And that's where things got interesting. So at that point,
0:03:50I've watched probably thousands of these migration scripts being run over my years as a Rails
0:03:55developer, and immediately I knew something was funny. Something wasn't going quite right,
0:04:03because it was telling me about how it was creating automatic primary keys.
0:04:08And based on what I was doing, that shouldn't have been part of it.
0:04:13What I was doing, it was also affecting tables that weren't related to the changes that I was making.
0:04:18So I'm like, "Wait a second. What's going on?"
0:04:23And I immediately just have alt-tab over to a browser where I had feeder-angler running,
0:04:28or I try to refresh the page and I get 500 back,
0:04:33like this system is down, what is going on?
0:04:37I look over to the migration, it's finished, it's done.
0:04:40I look at it and I'm like, what happened?
0:04:42So I open up my production logs,
0:04:45I look in the database area, and I realize that
0:04:47rather than simply applying the small subset of changes
0:04:52to the dataset that it was supposed to do,
0:04:54the migration had actually gone through,
0:04:57and, well actually, maybe a better way to start,
0:05:00to say, to tell a story.
0:05:02So I open up my production log,
0:05:03and I see the two words that anyone who's ever done
0:05:06any database work, or any web work,
0:05:08never wanted to see, and it's a drop table.
0:05:12So yeah, what it had actually done,
0:05:14is it had gone through and dropped and recreated
0:05:18every table in Feed Wrangler,
0:05:20which is awkward because having dropped and recreated every table in the database, it
0:05:26means that there was no data.
0:05:28All the data is gone.
0:05:30All the data was completely gone from the system.
0:05:36All my user table, my articles, user status, everything, just gone.
0:05:41And so at that point, I had a moment of panic.
0:05:45I think the only experience I can think of that was a similar kind of-- similar to this viscerally,
0:05:50if you're a parent of a small child, you probably experienced this, where you see your kid about to
0:05:56do something that's going to hurt them slightly. So the classic one is if you see them, they're
0:06:01about to sort of fall out of a chair, or they're about to trip over something, and you have that
0:06:06moment of just like, "Ah!" And you just freak out. I mean, what are you going to do? And then you go--
0:06:14So I have that moment of freak out, and I'm like, "What just happened? It's all gone."
0:06:18So immediately I go into the database, and shut down the database, and then in the hopes
0:06:24that it hadn't yet propagated off to my hot standby slave.
0:06:29So I go in there, and of course the slave had already propagated, the slave had no data either.
0:06:34And so now you have an interesting situation.
0:06:39thing. You kind of have, like a good reasonable backup strategy is kind of like an onion,
0:06:46I guess you could say. It's got many layers. You're dealing with different failures and
0:06:50different probabilities and different intensities of failures at different levels in your backup
0:06:55strategy. So at your first level, you're kind of worried about things like database fit,
0:07:01like disk errors, disk failures, those types of things. And that's what something like
0:07:05having a hot stand by a read slave is really helpful for.
0:07:10So if my master database died for whatever reason,
0:07:13like just the hard drive's dead, something happened,
0:07:15which hopefully isn't that likely given that it's on a VPS,
0:07:20it's on a rated disk drive, but these things happen.
0:07:23If some crazy disk error happens
0:07:26and it isn't a logical failure, it's a physical failure,
0:07:28then the read slave would have been fine.
0:07:31I could have just told it to become a master
0:07:30and turn it into the primary.
0:07:32So that's great, I would have been able to do that.
0:07:35So that's that first level of backup I have.
0:07:37Then you have a thing in Postgres where you can do
0:07:39point in time recovery with right ahead log archiving.
0:07:44You have that kind of thing.
0:07:45And then I have on top of that,
0:07:48I have the just like system level backups,
0:07:52which is, I essentially run something that is
0:07:55taking whole machine snapshots on regular basis,
0:07:59and then it archives them at regular intervals.
0:08:04I think there's a couple that run every couple hours,
0:08:06then it keeps the most recent ones for a week,
0:08:12and then it keeps one of them for each week for a month
0:08:17or something like that.
0:08:21It's kind of a cascading system.
0:08:22And so now after the initial panic works out,
0:08:26this is what I'm trained for kind of mode,
0:08:31of like, what do I do?
0:08:33How do I recover this situation
0:08:36in the way that is least impactful to users?
0:08:38And obviously, in parallel to this,
0:08:42I'm sitting there on Twitter and in other ways
0:08:44trying to communicate with customers and saying,
0:08:46yeah, there's an outage, things gone wrong.
0:08:49And at first, I didn't really know
0:08:51how bad it was going to be,
0:08:53and so my messages are kind of more vague.
0:08:54It's just like, sorry about the outage,
0:08:52I'm working on it.
0:08:54The next one's like it's gonna be a couple of,
0:08:55it's gonna be at least a few minutes
0:08:56'cause I need to recover from a database state.
0:09:01And then at one point, so then I kind of,
0:09:04while I'm doing that kind of customer side,
0:09:06I'm also focused on what should I do?
0:09:09So logical recovery is out of the question
0:09:13because like I said, the read slave
0:09:15had also had this happen to it.
0:09:16So for some reason it had propagated off
0:09:20into the read slave as well.
0:09:22And so then I had to do some kind of lower level recovery.
0:09:27So the first part I could do was kind of a point in time
0:09:28thing with Postgres where you take the write ahead logs
0:09:31and replay them to a certain point
0:09:34and right before the failure happened.
0:09:36And I looked at that and I could have tried to do it.
0:09:40And so I was like, okay, well, I'll start looking at that.
0:09:44And then line node, which is where I'm,
0:09:46manages the backup system for me that I suppose ended up
0:09:49actually being the thing that I used,
0:09:50also lets you, you can take a backup
0:09:52and create a spin up a whole new machine
0:09:54that's a clone of that snapshot point in time.
0:09:56So I go into Liner and I say,
0:09:57"Hey, rebuild this, you know, my most recent database
0:10:01"as a whole new machine, and just sort of start that process."
0:10:05'Cause it takes a few minutes while it copies a lot of data
0:10:08and gets the machine set up.
0:10:09So I was like, "Okay, I'm gonna kick that off,
0:10:11"I'm gonna have that going as my fallback,
0:10:13"and I'm gonna immediately start jumping
0:10:14"into the actual recovery."
0:10:18So I started looking at the point-in-time recovery.
0:10:23And long story short, it ended up not working
0:10:24quite as quickly as I would have liked.
0:10:27I think I probably could have gotten into work,
0:10:29but it's a very fiddly process,
0:10:31at least from me not being a professional Postgres DBA,
0:10:33to get it working exactly right.
0:10:37And from a data integrity perspective,
0:10:38I was a little bit concerned of leaving the database
0:10:40in an inconsistent state or an unstable state,
0:10:42or things that will ultimately come back and bite me.
0:10:45And so instead, the main line node came back up.
0:10:48I sort of fired up the database,
0:10:53and it wasn't as bad as I feared.
0:10:55It was only a couple of hours,
0:10:58or maybe several hours, probably,
0:11:00I think it was about four hours-ish,
0:11:01four or five hours of data that had been lost.
0:11:03So that's not great.
0:11:07The nature, at least, of RSS syncing
0:11:08is that the data that most of what it's containing
0:11:11is widely distributed across the internet,
0:11:14and I'm just caching it.
0:11:13comes back up, I can go and re-download all the articles.
0:11:15And users are mostly just missing their annotations,
0:11:19whether they've read it or not, stars, those types of things.
0:11:23I had, I think, two users who created accounts
0:11:25during that period that I had to go in and manually fix.
0:11:27But generally, it wasn't too bad.
0:11:30Got that spun up.
0:11:31Actually, as a random bonus, I ended up--
0:11:33it was a bit of a silver lining.
0:11:34I upgraded the hardware that the machine runs on,
0:11:36which I think I've been meaning to do for a while.
0:11:38But I hadn't done it because it would have required
0:11:40a few minutes of downtime.
0:11:41So I figured, hey, while it's all systems down,
0:11:46let's go ahead and run the upgrade.
0:11:49So I did, so it's running on faster hardware now,
0:11:51and it went pretty well.
0:11:54You never really want to test your backup regimen.
0:11:57It's the kind of thing that you,
0:11:59or you never want to have to go beyond testing.
0:12:01I've played with these before.
0:12:04I've done restores, my backups,
0:12:05and I've kind of gone through this process a little bit.
0:12:06But to actually have to go and rebuild the entire dataset
0:12:07from backup is terrifying.
0:12:10And I'm just glad it worked.
0:12:13Things are back up and running now.
0:12:14Things are actually faster than they were before the outage
0:12:16because, like I said, I upgraded all the hardware
0:12:19that it's running on.
0:12:20But I definitely don't want to do that again.
0:12:23And so I definitely won't be going anywhere
0:12:25near database migrations in Rails for quite some time.
0:12:28I still haven't worked out what happened.
0:12:31I'm sure there was just something in the way
0:12:32that it was configured.
0:12:34I'd recently done a Git merge into that repository
0:12:37that I think maybe have messed something up.
0:12:40But actually, I think I know somebody
0:12:42who can say this better than I did.
0:12:43And just replace the word "season pass"
0:12:47with "database" in this clip.
0:12:48And I think you'll have a pretty good sense
0:12:50of what I'll be doing for the next while.
0:12:53- Okay, let's never touch that website again.
0:12:55Does the season pass migration thing?
0:12:58Obviously is pure evil.
0:13:00We can never go to that page again.
0:13:01Don't even load that page,
0:13:02because if we accidentally load that page,
0:13:03for all we know, it's going to scramble
0:13:05our season passes again.
0:13:05And then I had to start the whole process all over again of rearranging everything.
0:13:09Not a good user experience.
0:13:13Exactly. So we're not going anywhere near migrations for a while.
0:13:17We're just going to stick with what we know. I'm going to be running some SQL.
0:13:21You need to add a field to a database. I will be going into Postgres. I will be running exactly
0:13:25the alter command that I know is safe and won't destroy things.
0:13:29I'll be retyping the birds drop table again in my life.
0:13:33hopefully things are going well.
0:13:38One thing that I think that was really encouraging
0:13:41coming out of this, and I know this is certainly part
0:13:43of just having a fairly geeky customer base,
0:13:45is I tried to be very honest about what was happening
0:13:47during the process and kind of what happened
0:13:49after the process, and being very explicit about it.
0:13:51It's not just kind of like, something happened.
0:13:53It's kind of like the dev center outage,
0:13:55where it's this very vague, like no one really knows
0:13:56what's going on.
0:13:58I try to be very specific.
0:13:59I didn't get quite as many details as I did
0:14:00just now on the show, but I try to be very explicit.
0:14:01I think a lot of people, customers, really appreciate that.
0:14:06Saying like, "Yep, sorry man, that happens.
0:14:08Hope you hope tomorrow's a better day for you."
0:14:11Which is just really encouraging to me.
0:14:14And I think it's a good example of just being honest
0:14:15as best you can is often just what customers want.
0:14:17They understand that you're human at the end of the day
0:14:21and you're just going to do your best.
0:14:23All right, that's it for today's show.
0:14:24As always, if you have questions,
0:14:26comments, concerns, or complaints,
0:14:27I'm on Twitter @_davidsmith,
0:14:28david@developingperspective.com.