Latest / Talk Python To Me / #401: Migrating 3.8 Million Lines of Python
Transcript
- 0:00At some point, you've probably migrated an app from one framework or major runtime version to another.
- 0:05For example, Django to Flask, Python 2 to 3, or even Angular to Vue.js.
- 0:11This can be a big challenge.
- 0:13If you had hundreds of active devs and millions of lines of code, it's a huge challenge.
- 0:19We have Ben Barito from Yelp here to recount their story of moving 3.8 million lines of code from Python 2 to 3.
- 0:28But this is not just a 2 to 3 story.
- 0:30It has many lessons on how to migrate code in many situations.
- 0:34There are plenty of gems to take from his experience.
- 0:36This is Talk Python To Me, episode 401, recorded January 18, 2023.
- 0:56Welcome to Talk Python To Me, a weekly podcast on Python.
- 1:00This is your host, Michael Kennedy.
- 1:01Follow me on Mastodon, where I'm @mkennedy, and follow the podcast using @talkpython, both on fosstodon.org.
- 1:09Be careful with impersonating accounts on other instances.
- 1:11There are many.
- 1:12Keep up with the show and listen to over 7 years of past episodes at talkpython.fm.
- 1:18We've started streaming most of our episodes live on YouTube.
- 1:21Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified about upcoming shows and be part of that episode.
- 1:30This episode is brought to you by Cox Automotive.
- 1:33Join their team and use your technical skills to transform the way the world buys, sells, and owns cars.
- 1:39Find an exciting position that's right for you at talkpython.fm/cox.
- 1:42And it's also brought to you by User Interviews.
- 1:45Earn extra income for sharing your software development opinion at User Interviews.
- 1:51Head over to talkpython.fm/userinterviews to participate today.
- 1:55Ben, welcome to Talk Python To Me.
- 1:58Thank you.
- 1:58Thank you so much for having me, Michael.
- 2:00We're going to talk a little bit of legacy code, a little bit of very, very large code bases,
- 2:05and how you might not have to permanently live in the past, which I think would be really welcome to a lot of people.
- 2:12I just talked a little bit about this before I hit record, but even though your topic is specifically
- 2:17how the story of move from Python 2 to 3 and this, like, making your whole code base modern,
- 2:23I do think that this idea of how do I move from one code base to another code base is super relevant to lots of folks
- 2:29who might not be going from Python 2 to 3, but maybe from Flask to FastAPI or vice versa, or those types of things.
- 2:36So I think the techniques that you're going to talk about here are more broadly applicable than just a 2 to 3 migration.
- 2:42And it's really cool how you all migrated 3.8 million lines of code without interrupting development.
- 2:49That's kind of nuts.
- 2:50Yeah, I did it, and it still seems ridiculous.
- 2:52You lived it, and it seems like a dream. Amazing.
- 2:55Before we get to all that, though, let's start with your story.
- 2:57How did you get into programming and Python?
- 2:59Took a job at Yelp. Yelp was a Python shop.
- 3:01Before that, I had a couple internships, and I went to Georgia Tech, and I mostly did Java.
- 3:06So it was sort of a new experience for me.
- 3:08You know, Python is one of those, like, beginning languages that everyone loves to throw around.
- 3:12So I had done, you know, I dabbled in a little bit, but when I first started really getting, like, deep into the language when I started it at Yelp,
- 3:22and I've definitely made it, it's sort of become, like, I've become sort of a local expert on it.
- 3:28So I've been able to build up a lot of knowledge about, like, you know, a lot of weird edge cases and, you know, stuff like that.
- 3:34You may be familiar with it.
- 3:36There's a t-shirt that's kind of a joke, a meme.
- 3:39It says, I learned Python.
- 3:40It was a great weekend.
- 3:41Yeah.
- 3:42And yet, I've been doing Python for many years, and I'm still learning new stuff.
- 3:46Even today, I learned some interesting new Python things.
- 3:50So which is it?
- 3:51Do you learn it in a day, or is it, like, this deep journey?
- 3:54I think most programming languages have some amount of, you know, width and depth.
- 3:59I think, you know, Python definitely has the advantage of being, you know, a relatively straightforward language.
- 4:04One of the nice things, obviously, is that, like, instead of using a lot of weird keywords, it has, like, you know, words.
- 4:11Like, you know, instead of being, like, oh.
- 4:13Like, or a pipe.
- 4:15Yeah, or, yeah, or instead of double pipe and stuff like that.
- 4:18Like, those are the things that I think definitely help people.
- 4:21Personally, you know, me coming into it, that wasn't, like, as big of a deal for me because, like, I was already familiar with all that stuff.
- 4:27But, like.
- 4:27You're coming from a very symbol-heavy world of Java, which is not as symbol-heavy as C++, but it's got a lot of abstractions in what it builds, for sure.
- 4:36Yeah.
- 4:36I will say, like, I think there are certain things that Python does.
- 4:40I will say Python is not, like, a perfect language by any stretch of the imagination.
- 4:44But I will say one thing about Python that I think is really cool is it did, sort of, before many other languages, managed to integrate a lot of, like, functional paradigms.
- 4:53Like, list comprehensions or comprehensions in general are, I think, one of those features where it's just, like, this doesn't exist in a lot of other, sort of, more popular languages.
- 5:02Yeah.
- 5:02And they're really, really fluent and powerful in a way that, like, you kind of miss when you don't have it, right?
- 5:08And so, like, I think that's something that's really cool about Python.
- 5:11But Python itself, you know, being a language with the legacy that it has, you know, I mean, we're going to be talking about the two to three differences which have their own nuances to them.
- 5:20But, like, it's always going to have some weirdnesses to it.
- 5:22And some of those things are, like, just like, oh, someone made a decision, you know, 30 years ago that, like, still kind of reverberates today.
- 5:29And so that means that, like, it has this depth to it, you know, you have to really learn the depth in order to fully understand all of the problems that exist.
- 5:38Like, dealing with not necessarily problems with the language, but, like, you know, when you're building software, you run into problems that you have to solve.
- 5:44Right.
- 5:44And so that's, like, the main, I think that's true of all languages to an extent, especially, you know, popular ones and older ones.
- 5:51But, yeah, I do think that Python, more than a lot of languages, really is able to straddle the line of, like, being like, oh, it's approachable, but also you can do a lot of, you know, really interesting and powerful stuff with it.
- 6:02Yeah, you compare that with, like, Java.
- 6:04Java, you've got to understand functions.
- 6:06You've got to understand classes, possibly namespaces, like, just to write the first line of code.
- 6:13Whereas Python, you can work with it for, like, you know what, this is really clumsy to repeat this.
- 6:18Maybe I'll learn what a function is.
- 6:20And then I can start using that.
- 6:21But you don't know what a class is.
- 6:22You don't care about it.
- 6:22You kind of, like, slowly layer on the stuff as you need it, rather than you've got to jump in and go with it all at once.
- 6:30Yeah, for sure.
- 6:31Yeah.
- 6:31Interesting.
- 6:31So you're still at Yelp?
- 6:33Yes.
- 6:33Yeah.
- 6:34I'm in our, in a conference room in our San Francisco office right now.
- 6:38Excellent.
- 6:38And what are you doing there?
- 6:40So I work on a team that's called Core Services.
- 6:42Our team is responsible for a lot of infrastructure, mostly Python-focused, though not exclusively.
- 6:50We do a lot of our sort of, like, internal Python infrastructure.
- 6:54So, you know, we'll be responsible for making sure that we can upgrade to new Python versions.
- 7:00We've got, we own our internal PyPI.
- 7:02We recently, this is a cool thing that has happened since my talk, so I didn't mention it, is we recently built a system to automatically import certain packages from a public PyPI.
- 7:16And that has saved us some headaches.
- 7:18And then we own some other stuff, like, you know, we've dealt a lot with sort of the general service contract at Yelp.
- 7:24So, like, being like, okay, what, what does it mean to be a service?
- 7:26How do you, how do you be a good citizen there?
- 7:29And a lot of other things, like, testing tools, a lot of, like, sort of, like, oh, I need to test against multiple services.
- 7:36We have a testing tool that, like, automates a lot of the steps to, like, sort of get those all connected together so you can test against them.
- 7:42Yeah, that sounds like a really fun set of task you're doing there.
- 7:45So you said you have an internal, we're going to dive into code and stuff, all this whole migration.
- 7:50But, you know, kind of sidebar, like you said, you have this internal private PyPI server.
- 7:55What's the details around that?
- 7:57Like, how, obviously, you're whitelisting things that can be brought inside saying, we're going to put those onto our server.
- 8:04And you can, like, request, and you can choose when to let the new one in and so on.
- 8:08But, you know, what's the, what's the software and how do you put that together?
- 8:12Right.
- 8:12A number of years ago now, we switched to a piece of software that I don't think is used pretty much anywhere else,
- 8:19which was built by one of my teammates who named Chris Keel.
- 8:24So Chris Keel built essentially a PyPI implementation called Dumb PyPI.
- 8:30It's called Dumb PyPI because unlike some other PyPI servers, the way that it works is you just sort of give it a list of distributions
- 8:39and then it just generates all of the HTML pages.
- 8:42So instead of, instead of being like, oh, I'm a server and I'm like, you know, going to handle this request and blah, blah, blah,
- 8:48and like run some code, it's literally like, okay, here are the HTML pages.
- 8:51And I see, it's like a, like a static site generator for PyPI backend.
- 8:56Yeah.
- 8:57Yeah.
- 8:58And we've been using that for a really long time and maybe like four or five years now.
- 9:03And it's, you know, it's serviced pretty well.
- 9:06It's really nice in my opinion, because it's the only service that my team actually owns.
- 9:11So it, and it never pages us.
- 9:13So that's great.
- 9:13I love that it never pages us.
- 9:15It can't go down.
- 9:16Yeah.
- 9:17Not really.
- 9:18Well, it can't, it would be good that if it goes down, but also it doesn't.
- 9:22That's the great part.
- 9:23It just, it just doesn't.
- 9:24So Chris's, Chris's software works great.
- 9:26Yeah.
- 9:26That's a really cool idea.
- 9:28And so you tell it certain versions or, or do you just limit it to the libraries and
- 9:33let it pick the latest versions of whatever's on real PyPI?
- 9:36So the way that we do it is we have a whole system, which like imports packages.
- 9:42We actually rebuild all of our wheels.
- 9:44It's kind of for kind of hard to explain reasons.
- 9:48So what we'll do is we'll like, someone will say, Hey, I want this version of this package,
- 9:52or maybe they'll just say, Hey, I want this package.
- 9:54And then we'll just pull down the newest one at the time and we'll do some like security
- 9:59bedding on it.
- 10:00So we have some like automated security stuff and basically just make sure that it's like
- 10:03not malicious.
- 10:04And then we build the wheels and then we upload those to the S3 bucket that like backs our PyPI.
- 10:12Right.
- 10:12So we just do that in terms of like how we decided it's basically just sort of like, we, you know,
- 10:19make sure, you know, we do the security check.
- 10:21We do like, there's a few other things.
- 10:23Like we make sure we have all the dependencies.
- 10:24We make sure we have a, that it has like a license that we're okay with, with using internally.
- 10:30And so all of those things are checked.
- 10:32And then we have, as I mentioned, we have this sort of like automated import system.
- 10:37So like certain packages, we'll just, we'll try to download them.
- 10:40They might fail, you know, one of those checks and then we won't upload it.
- 10:43But like, you know, so we'll just like import it.
- 10:45We'll try to import it.
- 10:46And so certain packages, we'll try to get the newest one.
- 10:49Some packages, you know, how we haven't set that up for one reason or another.
- 10:53Some packages, there's certain packages that are just like difficult to build.
- 10:56And so we avoid importing them.
- 10:58Right.
- 10:58You're just, we got this one working.
- 11:00It's fine.
- 11:01Yes.
- 11:02Yes.
- 11:03And so like some are difficult to build.
- 11:05Some are just like, oh, this is a package we've never used before.
- 11:08So we just like, don't use it.
- 11:10Yeah.
- 11:10So, or we don't have it.
- 11:11Yeah.
- 11:11You talked about how many dependencies your projects have and stuff and that'll be fun.
- 11:16But let's maybe take a step back and just talk about, you know, Python at Yelp.
- 11:20You've, this main project that you have, it was running on Python too.
- 11:25It's kind of obvious, but some of the reasons are obvious.
- 11:28Some are not.
- 11:28Like why did you care what version of Python it's on?
- 11:31That's a good question.
- 11:32I mean, I think the main reason was just sort of like we saw the writing on the wall,
- 11:37the running on the wall was the end of life or Python too.
- 11:39Right.
- 11:40And I think everyone else, we knew that other people were going to follow that.
- 11:43Right.
- 11:43There was, I remember in 2019, when I was looking into this, there was a thing, I think it was
- 11:49called like the Python pledge or something like that, where basically like packages would
- 11:53like open source packages would say like, Hey, we're going to drop Python three, you know,
- 11:57after end of life at some like, you know, either the day of or, or a few months later,
- 12:02or something like that.
- 12:03And so we were sort of looking at that and being like, well, we use some of those packages,
- 12:06you know, and eventually we might want to upgrade them.
- 12:09Yeah.
- 12:09You're about to get frozen in time around mid 2020.
- 12:12So you're, you maybe don't want that.
- 12:15By the time that I did my, my talk, I remember, I think it was early 2021 or something, you know,
- 12:21pip had dropped support for Python too.
- 12:23So that was like one of those things where it was just sort of like, yeah, there's not,
- 12:27there's not a realistic ecosystem in which you are able to use like open source and upgrade
- 12:32your stuff, you know, for security patches or whatever, you know, I want this new feature.
- 12:37Oh, sorry.
- 12:38That's Python three only, you know, kind of thing.
- 12:40So that was like the main motivation.
- 12:42Right.
- 12:42And then I think some secondary stuff was just sort of like, as you build, you know,
- 12:47as time marches on and like people stop being familiar with like Python two and it has some
- 12:52quirks, you know, for Python three, you definitely have the problem of like, okay, now you have
- 12:56to like, if you're hiring people and they're working on Python two, you have to train them
- 12:59up on those quirks in a way that like you wouldn't necessarily have to do if you're using a modern
- 13:04language that other places are using.
- 13:06So those are the, I think the main motivations personally, I think I had like a small motivation
- 13:11myself, which was just sort of like, I hate seeing things like be left behind like this,
- 13:16you know?
- 13:16Yeah, sure.
- 13:17Very emotional thing, but yeah, that's part of the reason I pushed for it.
- 13:21Well, there's the training thing.
- 13:22I mean, there's obviously the, just the infrastructure stopping, stopping the updates, but there's the
- 13:28training side of helping people who are new come, but there's also the, how do you hire
- 13:33the very best engineers?
- 13:35It's really hard to get an amazing Python engineer to come and say, you're going to do
- 13:40amazing work from 2008.
- 13:42You're going to love it.
- 13:43You know what I mean?
- 13:44Right?
- 13:44Like if they're working on some new package that they're inspired about, instead of trying
- 13:48to bring that in and like, you know, help make that better and also boost what you're
- 13:52doing.
- 13:52It's like, well, we can't use that because that you only don't Python three.
- 13:55Like, well, of course I created it this, you know, two years ago.
- 13:57Why wouldn't it be Python three only?
- 13:59And there's a lot of knock on effects like that, right?
- 14:01Yeah.
- 14:01Did you see the performance stuff from 2.11 or even from 2.11?
- 14:06Sorry, 2.11.
- 14:073.11 or even 3.10?
- 14:08Where, where you're like, you know, there might actually be fewer servers as well if we do this?
- 14:14That's definitely something that we are, you know, we want to do.
- 14:18That specific issue is something that we're, we're sort of, we're trying to move towards
- 14:22being able to use those versions of Python right now.
- 14:25It's always a process just because of various, you know, internal things, but it's definitely
- 14:30something that has been, that has been talked about as well.
- 14:32Like, yeah, if we could use new versions of Python, maybe things will be faster.
- 14:36Things will be more efficient.
- 14:38Trying not to spend too much money is definitely a thing that we, we think about.
- 14:42So that's definitely exciting.
- 14:43Yeah.
- 14:44When I did the episode on 3.11, we talked a lot about the performance there and it's, it's
- 14:49impressive.
- 14:49It's, you know, 40, 50, 60%.
- 14:51And I won't steal your thunder.
- 14:53I know at the end, you've got some nice performance boosts that you got even from the changes that
- 14:58you made.
- 14:59But there was somebody in the audience that pointed out, like, not only is this faster,
- 15:02which is nice for us, right?
- 15:04It's nice that we have to pay less for servers.
- 15:06It's nice that our code runs a little bit faster, but it's also good for the planet, right?
- 15:11If we just all start using newer, faster foundations, then necessarily we just use less energy to
- 15:18do the same thing that we're already doing, right?
- 15:19Yeah, that's definitely, I like that.
- 15:22This portion of Talk Python Nemy is brought to you by Cox Automotive.
- 15:27With brands like Kelly Blue Book, AutoTrader, Dealer.com, and more, Cox Automotive flips
- 15:33the script on how we buy, sell, own, and use our cars.
- 15:38And now the team at Cox Automotive is looking for software engineers, data scientists, scrum
- 15:44masters, and other tech experts to help create meaningful change in the industry.
- 15:48Do you want to be part of a collaborative workplace that values your time and work-life balance?
- 15:54Consider joining Cox Automotive.
- 15:56Visit talkpython.fm/cox today.
- 16:00Thank you to Cox Automotive for sponsoring the show.
- 16:03Let's talk about Python at Yelp.
- 16:06So you've got this repo, this big project called Yelp Main.
- 16:11Let's start there.
- 16:12Sure.
- 16:12Yelp Main is what it sounds like.
- 16:15It is sort of the original repo at Yelp.
- 16:18That's when you're a startup in 2004.
- 16:20You kind of just make a repo, right?
- 16:23And it's your web app.
- 16:24You probably made a Subversion repo.
- 16:26Because you didn't know that CVS stuff.
- 16:29We're doing Subversion.
- 16:30I don't remember when we switched from Subversion.
- 16:33But it was Subversion.
- 16:35I don't know if it was before Subversion.
- 16:37I don't know if we actually started out in Subversion.
- 16:40Okay.
- 16:41Because I didn't start until 2014.
- 16:42Sure.
- 16:43But yeah, it's definitely Subversion was, I know there was some old Subversion stuff.
- 16:47But so you have this one, you know, sort of web app.
- 16:49And the web app is a server that serves, that originally served everything.
- 16:56So, you know, there's a bunch of stuff.
- 16:58Like, you know, you can sort of think of as like Yelp.com, right?
- 17:01Like, if you go to www.yelp.com, then you're looking at what you think of as Yelp, right?
- 17:07It's like, oh, I can search for businesses.
- 17:09I can look at their reviews.
- 17:10I can write my own reviews, that kind of stuff.
- 17:12So it's that, but it's also other stuff.
- 17:14It's also our business owner site.
- 17:17So biz.yelp.com, which is where business owners, like, look at their own businesses and, like,
- 17:21are able to see the metrics and, like, you know, buy ads and stuff like that.
- 17:25There's our admin site, which is, you know, where a lot of anybody,
- 17:29we have our sort of user operations people whose job is at least partially to do some moderation
- 17:34and stuff like that.
- 17:35So, like, we need to be able to have those tools.
- 17:37And then there's also what we call internal API.
- 17:42And internal API is a way for internal stuff to get the data that's in Yelp name.
- 17:49So that's what that is.
- 17:51And that's like its own separate sort of site.
- 17:53And, but these are all in the same repo.
- 17:55They all run in the same process.
- 17:57That's, and yeah, sorry.
- 17:58No, I was just going to ask, is this kind of the monorepo style or it's, it's truly
- 18:03a monolith in the sense that it's kind of all the same app.
- 18:06It's truly a monolith.
- 18:07There is some amount of stuff where it's like, oh, we have like different containers running
- 18:12like different entry points.
- 18:13But like the code is all kind of tangled up together.
- 18:16So there's not really a meaningful delineation between different components in a way that you
- 18:22could really separate them out in any meaningful way.
- 18:24So like my understanding of like what I would define as a monorepo, I wouldn't really call
- 18:29it that.
- 18:29I would just call it, I would call it just a large app.
- 18:32Yeah.
- 18:33It's a huge, huge, huge app, huge repo.
- 18:35Yeah.
- 18:35Yeah.
- 18:36Okay.
- 18:36So in your talk, you said that you have six different sites with 2000 different endpoints,
- 18:42which it's a lot.
- 18:44I don't think it's completely excessive or anything like 2000 URL endpoints for, for all
- 18:49those different services and like all those different admin apps.
- 18:52So it seems it's a lot, but it's not insane.
- 18:54And then you have these background batch services.
- 18:57What story of those?
- 18:59It's just sort of anything that you need done.
- 19:01As I said, this was just sort of like, this is the one repo, right?
- 19:04And so there's a lot of things that you want done that aren't necessarily done in the context
- 19:09of a web request or don't make sense to do synchronously.
- 19:12So a lot of that is just sort of like, okay, you know, I need to like do this like really
- 19:17complex report or something, right?
- 19:19You know, I want to get some metrics that like involve collating a bunch of data, doing a
- 19:23bunch of joins against a bunch of tables.
- 19:25Okay.
- 19:26Well, I'm not going to have just like a web request do that.
- 19:28I'm going to put that in like a separate process.
- 19:30And we originally, as you can imagine for that type of application, we just called them
- 19:36just batches.
- 19:36Yeah.
- 19:37Like a patch, a batch job, right?
- 19:39That name is stuck despite the fact that now batches don't necessarily do that type
- 19:43of work.
- 19:44They're just sort of anything that you want to do in the background.
- 19:46And that could be something like, oh, the first of the month we do our like ad billing,
- 19:51or we might have some process where it's just sort of like, oh, we want to like update this
- 19:58cache, you know, based on like data like stuff, but we don't want to do it inline in a web
- 20:03request.
- 20:04We can do it asynchronously.
- 20:05So it's really anything that is not in the context of a web request.
- 20:10I suspect most major apps, most companies have that kind of stuff too, right?
- 20:15They've got to.
- 20:16I mean, everyone has some version of it.
- 20:18Whether or not they do it exactly the way that we do it is a separate question, but I'm
- 20:22not really sure.
- 20:23But yeah, I think part of the story is, do you deploy them all out of the same code base?
- 20:26Or are they, you know, a bunch of different jobs and repos?
- 20:30Or how's that fit together?
- 20:32That's probably where the, it varies.
- 20:33Yeah.
- 20:33I mean, for us, we have, I mean, I said 800 batches and I was referring specifically to
- 20:38the batches that are still in the Yelp main repo.
- 20:40And like I said, all of these things are kind of tangled together.
- 20:43So it's not like, oh, you can just like pull a batch out.
- 20:45Like that's like talking about like, well, how do you get the data that it needs?
- 20:49And like, what does that look like?
- 20:51And blah, blah, blah.
- 20:52How does it get the data access layer?
- 20:53And how does it get a hold of the logging thing that's over here and all that kind of stuff?
- 20:57Right?
- 20:57Exactly.
- 20:58So like, so those 800 batches, but we also have tons and tons of batches that are in services.
- 21:04So they live in service repos and they run and they're, they're in totally separate code base.
- 21:09I don't know what that number is.
- 21:10I'd have to figure it out.
- 21:11Yeah.
- 21:12It's definitely a lot.
- 21:12It's probably, it's almost certainly more than that, than we have in Yelp main at this point.
- 21:16But that paradigm exists all over Yelp and not just in this repo.
- 21:20Yeah.
- 21:20Well, I think these are a lot of value to having that code together, right?
- 21:25If you break this out into a whole bunch of different repos, you've got dependency management,
- 21:29versioning, deployment, like there is some value to just saying like, just let it live together.
- 21:34We'll upgrade it together.
- 21:35But it, it does make for some striking headlines when you talk about how many lines of code got
- 21:40upgraded at once, right?
- 21:41Yeah.
- 21:42I mean, I think that when you're talking about like, why do we solve them all?
- 21:45The answer is mostly just because it's really hard to not have one.
- 21:49Once you have one, you have to do all the work to move it out.
- 21:53And there are disadvantages.
- 21:54Like you said, it's sort of like, okay, now, as soon as you have a new repo, it has its own
- 21:58set of dependencies that you have to keep up to date.
- 22:00And, you know, you have to do other sort of maintenance on it.
- 22:04Generally speaking, we consider that better though, still, because it's sort of like, it's always
- 22:09better.
- 22:09Like imagine if I'm in, in this giant monolith and I'm like, oh, I need to upgrade this package.
- 22:14And it's like, okay, well you want to do a major upgrade.
- 22:17And this package is imported in a thousand places.
- 22:20How you need to deal with that migration.
- 22:22Whereas if it's like, oh, I'm in my service and this, and I need to do this package upgrade
- 22:28and it's imported in 10 places.
- 22:29That's like an afternoon instead of like, you know, a quarter of a year or something.
- 22:35Right?
- 22:35Yeah.
- 22:36So there's definitely advantages to that.
- 22:38It does add, it's sort of like more work overall, but you can do it in a more granular way.
- 22:43So it allows you to unblock people faster, essentially.
- 22:47So like, we definitely want to move away from the monolith and we have been doing that.
- 22:51Like compared to when I started at Yelp, we have way, way less code that is important running
- 22:56in Yelp main.
- 22:57There is still a ton that's important in there.
- 22:59Like I mentioned in my talk, like almost inevitably someone has to like call into an internal
- 23:03API to get our, get data out of it.
- 23:05So that's something that like, we definitely want to fix at some point, but it is a process
- 23:10and that process is generally speaking, like we're getting to a point where like some people
- 23:15who work at Yelp don't really work in Yelp main anymore.
- 23:17Like they just don't have to deal with it, especially not on a day-to-day basis.
- 23:20Right.
- 23:21Sure.
- 23:21And you mentioned your talk.
- 23:22I don't know if I said this beginning, but you gave a talk at PyCon 2022, which is definitely
- 23:27it was a very popular one and highlights some of these things there as well.
- 23:30So I'll be sure to link to that so people can check it out.
- 23:33And you talk about people developing in Yelp main, some of them not, but there's still a
- 23:38lot happening there.
- 23:38You said 20 pushes a day, 800 simultaneous developers.
- 23:44And yeah, that's, that's no joke.
- 23:47That's a lot of traffic on a repo.
- 23:49Yeah.
- 23:49I think since I did that talk where we've been going, we've been trending down in terms of
- 23:54number of changes per day, but it would still probably close.
- 23:57Like somewhere in the eight, like 15 to 25 a day.
- 24:01So it's less like that's an appreciable percentage less, but it's still a lot of changes per day.
- 24:06Yeah.
- 24:07Yeah.
- 24:08And you also said you have 700 Python package dependencies.
- 24:11We talked about the private PyPI.
- 24:13So when you say you have 700 dependencies, that's if I go into the virtual environment and type,
- 24:18you know, pip list, I see 700 things.
- 24:20Yep.
- 24:20Okay.
- 24:21It's a lot.
- 24:21It's a lot.
- 24:22It was an ordeal dealing with me.
- 24:24Especially coming from a long time ago until present, right?
- 24:28In terms of code, code compatibility, right?
- 24:31Some of those things you depended on.
- 24:33Maybe their new versions have moved to Python 3, but maybe with breaking changes.
- 24:37Others, they might just not have a Python 3 version.
- 24:40Mm-hmm.
- 24:41And how'd you deal with that?
- 24:42There were basically, in terms of like open source stuff, there were basically like three
- 24:47ways that we dealt with that.
- 24:48So one is just like upgrade and like deal with whatever the upgrade entails.
- 24:53I don't think we really ran into any issues where we were like, oh no, we have to do this
- 24:58like massive breaking change, you know, migration.
- 25:01That wasn't really a problem that we ran into, thankfully.
- 25:03So a lot of those were just sort of like figuring out what packages need to be upgraded and just
- 25:08like sort of doing the upgrade, making sure that they test pass and that kind of stuff.
- 25:11So that wasn't too bad.
- 25:12The other one, which was a little bit more annoying was, like you said, some packages just
- 25:17stopped updating before they got Python 3 support.
- 25:23And we were relying on them.
- 25:24So we had to be like, okay, well, can we replace these with something that, you know, fixed?
- 25:29And there were a few examples of packages where it sort of stopped getting development.
- 25:34And then someone was like, oh, that I see where the problem, like that's a problem for me.
- 25:39So I'm going to fix that.
- 25:40And so luckily a lot of people had already done that work and they, there were like forks
- 25:44or sort of drop-in replacements.
- 25:46Sometimes not exactly drop-in replacements, but like, you know, close enough that we could
- 25:50like do, do the small amount of work that was needed.
- 25:52It's one of the advantages of being a little bit later to the party is let other people
- 25:56bump into those problems and maybe they fixed them for you, right?
- 26:00That probably happened most of the time, honestly.
- 26:01That was definitely a good chunk of the time.
- 26:03I couldn't tell you I'd have to like go back and like run the numbers on like what percentage
- 26:07of the time that was.
- 26:08But like, we definitely, yeah, there was definitely a good chunk of things where we're just sort
- 26:11of like, oh, someone already made the fork or whatever.
- 26:13And we can just use that.
- 26:14And that was, that was nice.
- 26:16It was okay.
- 26:17That's, that's, you know, that one checked off.
- 26:19And then the final sort of grouping was stuff where there, what that wasn't available.
- 26:25So it was like, oh, this package is Python 2 only.
- 26:28And no one ever made a replacement.
- 26:30So we need to deal with that.
- 26:32Luckily, we, none of those were in a position where we were completely unable to deal with
- 26:38it.
- 26:38Like we didn't run into anything where we were like, oh, this is just like, this is like
- 26:42a blocker.
- 26:42But there were things where we were like, oh, this thing needs to be replaced with something
- 26:46else that does something similar or maybe right after right away.
- 26:51Like very often we ran into code where it was like, oh, this is using this thing.
- 26:55And then you'd start looking into it and you're like, oh, actually this code is like this like
- 26:59branch or whatever that uses this package isn't actually used anymore.
- 27:04So we can just delete all that code and like not have to think about it.
- 27:07So that's, that's how we dealt with it.
- 27:09Yeah.
- 27:10That's a nice way to upgrade it.
- 27:11Let's just get rid of it.
- 27:12Yes.
- 27:12Were there any packages that you're out there that didn't have Python 3 support and
- 27:17you're like, yeah, really, we really depend on this one that you upgraded and contributed
- 27:22back or were you able to just move on?
- 27:24There was nothing that we ran into that was like an absolute blocker like that.
- 27:29So we didn't end up contributing anything in terms of open source other than there were
- 27:35some packages that are like on our GitHub, like the Yelp GitHub that we did do upgrades
- 27:40for.
- 27:41Sure.
- 27:41That was, you know, that was the only sort of open source work that we, I think we really
- 27:45ended up doing.
- 27:45Yeah.
- 27:46So luckily, I mean, I don't know if this is lucky or not, but it's definitely, it happened
- 27:50so that we didn't have to do that.
- 27:52Yeah.
- 27:52That's good.
- 27:52I mean, it would be nice if you ran across that and helped solve it for someone, but you
- 27:57don't have to even better.
- 27:58Testing.
- 27:59One of the challenges of, well, first it's good to have tests, but one of the challenges
- 28:04of these upgrades is you wanted to do this without disrupting development.
- 28:09You wanted to keep adding new features.
- 28:11You didn't want to say, hey, everyone, stop making any progress or bug fixes for six months
- 28:18and we're all just going to do this until we're done.
- 28:19Right.
- 28:20You wanted to keep it moving.
- 28:21But in order to do so, you've got to run the test because you're making wholesale changes
- 28:25to millions of lines of code.
- 28:27So that's pretty nerve wracking.
- 28:28Right.
- 28:28And you're swapping out its dependencies in big ways.
- 28:32And yet running tests, you all have a lot of tests and they take a while to run.
- 28:35Right.
- 28:35Yeah.
- 28:36We have about a hundred thousand tests in Yelp main, a little under.
- 28:40And yeah, if you were to run them serially, at least when I wrote my talk, it was about
- 28:4535 hours total.
- 28:46But we have a test runner framework called Jolt that we run internally.
- 28:51And what it does is it basically like puts those tests up into bundles and then runs those
- 28:56across a bunch of machines.
- 28:57And so you're basically able to get all of the tests run for Yelp main in about, give or
- 29:04take an hour and a half.
- 29:05Okay.
- 29:05That's pretty good for running a hundred thousand tests.
- 29:07That's still a long time to have a test run though.
- 29:09Right.
- 29:10So you probably need it.
- 29:11You can't just get immediate feedback.
- 29:12Minor change.
- 29:13How'd that go?
- 29:14Minor change.
- 29:14How'd that go?
- 29:15You kind of, it'd be a little more thoughtful than that.
- 29:17Right.
- 29:17Yeah.
- 29:18I mean, I think that in terms of, and this sort of gets into like testing theory is that
- 29:22like you start to get an idea of like what changes are like affect what other things
- 29:29like sometimes you're not, you're not going to have a perfect idea, but like if you're
- 29:33like, oh, this is a thing.
- 29:35That just affects everything.
- 29:36Then you're going to run all the tests.
- 29:38But we did have the ability to run tests.
- 29:40If we were like, okay, we want to just run tests under Python three.
- 29:43We could do like, oh, I'm just going to run this, you know, test module under Python.
- 29:47Right.
- 29:47I can do that.
- 29:48And so like, if you were literally just like, oh, I'm checking, I'm like fixing this test
- 29:53under Python three, then you could just do that.
- 29:55You could just be like, oh, I'm iterating very quickly by like changing the code and then
- 29:59running the test under Python three.
- 30:01And then, you know, oh, it passes.
- 30:03Okay.
- 30:04Let me double check.
- 30:04It passes under Python two as well.
- 30:06And then you can commit that and then like put that into PR.
- 30:10And then we do require.
- 30:12So one of the things is we do require running all doing a full jolt run for every pull request
- 30:17to Yelp me.
- 30:18So in order to do so, you have to run that anyway.
- 30:20But like, while you're waiting for that to run, you can work on something else.
- 30:24Sure.
- 30:24And you're high confidence.
- 30:26You run a couple.
- 30:27Okay.
- 30:27That makes sense.
- 30:27So run a couple of local tests, 10, 100, 500, whatever.
- 30:31Once you're happy with that, then you put it as a PR and CI figures out what happens.
- 30:36Yeah.
- 30:36Okay.
- 30:37And I think that ultimately, like there, when we were really early on and we were working
- 30:41on like the really foundational stuff, but that was like the causing the most issues.
- 30:45That was the time when we're like, oh, we really got to run all the tests.
- 30:48But once you get down to the nitty gritty pretty early on, actually, you really don't
- 30:53need to think about how it affects other things.
- 30:55Like it's mostly just sort of like, yeah, you know, this module affects its own tests and
- 30:59that's pretty much it.
- 30:59Okay.
- 31:00Yeah.
- 31:01I'm sure you get a feel for it over time.
- 31:02Like these are the kinds of far reaching changes and these are the kinds of things I
- 31:06can stay really focused on.
- 31:07This portion of Talk Python To Me is brought to you by User Interviews.
- 31:13As a developer, how often do you find yourself talking back to products and services that
- 31:18you use?
- 31:19Sometimes it may be frustration over how it's working poorly.
- 31:22And if they just did such and such, it would work better.
- 31:26And it's easy to do.
- 31:28Other times it might be delight.
- 31:30Wow.
- 31:30They auto-filled that section for me.
- 31:32How did they even do that?
- 31:33Wonderful.
- 31:34Thanks.
- 31:34While this verbalization might be great to get the thoughts out of your head.
- 31:38Did you know that you can earn money for your feedback on real products?
- 31:42User Interviews connects researchers with professionals that want to participate in research studies.
- 31:47There is a high demand for developers to share their opinions on products being created for
- 31:53developers.
- 31:53Aside from the extra cash, you'll talk to people building products in your space.
- 31:58You will not only learn about new tools being created, but you'll also shape the future of the
- 32:03products that we all use.
- 32:04It's completely free to sign up and you can apply to your first study in under five minutes.
- 32:09The average study pays over $60.
- 32:11However, many studies specifically interested in developers pay several hundreds of dollars
- 32:17for a one-on-one interview.
- 32:18Are you ready to earn extra income from sharing your expert opinion?
- 32:22Head over to talkpython.fm/userinterviews to participate today.
- 32:27The link is in your podcast player show notes.
- 32:30Thank you to User Interviews for supporting the show.
- 32:32The other requirement you said that you had was that any changes must be rollback safe.
- 32:40Can you speak to that?
- 32:42I'm thinking like database migrations or that, right?
- 32:46What are you thinking here?
- 32:47Yeah, I mean, it's I think database migrations are a good example of that type of thing.
- 32:51We didn't really run into a situation where we actually had to do any schema changes to databases,
- 32:57although there was a thing where we had to do we had to make some changes to some data such that it would be parsed properly under both Python 2 and 3.
- 33:06But yeah, what you always want to do is you want to say like, okay, if I undo this later, maybe like a week later, someone realizes, oh, this change made a problem, has a problem.
- 33:16We don't want to be in this vision where we say, oh, we can't undo that.
- 33:19Something else, you know, it depends on it and we can't we can't undo it.
- 33:23And so that was like a main thing.
- 33:25It was just sort of like, don't do these things where you're just sort of like, oh, once we do this, we can't go back.
- 33:30Like, no, don't do that.
- 33:31Right.
- 33:31If you need to like do some extra work where you like build up scaffolding or whatever, then like do that work instead.
- 33:38And it might take a little bit longer in the in the in the long run, but it makes us have less risk.
- 33:43Yeah, I'll save diving into this for later in our conversation.
- 33:47But one of the things that you were able to do because of that is you were able to run apps simultaneously in two and three and use URL reverse proxy like Nginx or something to say this part of the web app runs Python 3.
- 34:00And this one over here is running Python 2 and filter the traffic and switch it based on how it's performing or behaving.
- 34:07If it goes wrong, you can switch it back quick.
- 34:09If you didn't have that compatibility, it would be like, all right, today we pull the switch junk and then like you deal with the consequences for how long Yelp is down.
- 34:18Right.
- 34:18So that's an interesting consequence of this idea that it should be able to be roll back rollbackables.
- 34:25You can actually run both versions and then sort of migrate more cautiously.
- 34:29You had a cool picture and let me put it on the screen for us here where you talked about the four different steps, the phases and timeline.
- 34:39And how much time you spent in there.
- 34:42Want to talk us through this?
- 34:43Yeah, sure.
- 34:43So this is just sort of like if you want to think about, OK, you've got some Python 2 code and you want it to get it to Python 3.
- 34:52It's very easy to think about it in a sort of atomic way as you just sort of like, oh, make it Python 3 compatible.
- 34:57And it's like, OK, it makes sense on small stuff.
- 35:00You know, if you're like, oh, I got my 500 lines back and I'm going to migrate to Python 3 today, you know.
- 35:05But on big stuff, when you're talking about millions of lines of code, you want to think about it in terms of in sort of level of compatibility.
- 35:11And so the three levels that we had to deal with here were parseability, which basically just means if you try and run this module with Python 3, will it fail with a syntax error or not?
- 35:24OK. And so that's the main thing.
- 35:27And parseability, it turns out, is pretty easy to fix because there were not a lot, huge number of syntax changes.
- 35:32And they're pretty easy to detect and fix in an automated way.
- 35:35Yeah. Did you use some tooling like PyUpgrade or any of those types of things?
- 35:40PyUpgrade we used a little bit.
- 35:41It's not super designed for this, but there was a one specific thing that was really nice about it, which is that it could detect octal literals.
- 35:50So if you put like zero and then a number that's an octal literal in Python 2, that's not a lot in Python 3.
- 35:56So you have to do zero O number.
- 35:59And it was able to detect those really easily and like fix them, which was really nice.
- 36:04Those things, it sounds like, oh, well, that's not that much work or that much help.
- 36:07But when you're doing it across millions of lines of code, anything you can automate, it's got to be really welcome, right?
- 36:13There's a relatively common pattern.
- 36:15The reason that I remember that one is there was a relatively common pattern where like people would create like date time.
- 36:20objects and then they would write year, month, day.
- 36:23And if the month or a year was single digit, they would prefix it with a zero, which works in Python 2.
- 36:30They probably didn't mean to make it octal, but that's what they did.
- 36:33Yeah.
- 36:33And so it kind of worked.
- 36:36And so people and so that that existed in a lot of places and it was like a popular pattern.
- 36:40But yeah, so PyUpgrade was useful in that way.
- 36:43It was useful later on when we were like blowing away all the sick stuff because it's able to fix all those things automatically, which is nice.
- 36:50Or most of them.
- 36:51But Python modernized was where a lot of most of our automation went because it could fix a lot of this stuff.
- 36:57Yeah.
- 36:57Yeah.
- 36:57So that was priceability.
- 36:58Importability is similar is that you try to import it and then you say, you say like, okay, this is failing with an import error.
- 37:06Like, or something is making it fail to import, like usually running code at the top level.
- 37:12And that was a little bit longer.
- 37:16A lot of that was fixing standard lib imports.
- 37:19You may be making most of those use six shims.
- 37:22If they change the six shim for that.
- 37:24And then some of it was also upgrading the packages so they could be used under Python 3 and like imported.
- 37:31But there was a little bit of like top level stuff where it was like, oh, this like top level thing is like calling like dict.iter items or something.
- 37:39And you got to fix that.
- 37:40Yeah.
- 37:40So that's, that probably gets maybe a little into the functional parity, which if people look at your talk, they'll see there's a couple weeks of the parsability, maybe a month or two of the importability.
- 37:52Then a whole bunch of the functional parity.
- 37:55And it reminds me of when I was learning C++ way, way, way back.
- 37:58And I got really excited because I finally got some complicated code to compile.
- 38:03Not really knowing like, oh, no, no, no, no, no.
- 38:06You're only the beginning of figuring out what's wrong with this.
- 38:09The compile is the part where it shows you what's wrong.
- 38:11Now it's like the mystery tour.
- 38:13And like, this is after that, right?
- 38:15This is like kind of once you get past parsing and importing, then you're into the how are they different behaviorally?
- 38:21Yeah.
- 38:21And this is, it's just sort of like, I alluded to this earlier, but basically the idea of you run all of your tests.
- 38:29And luckily we had already built up a lot of infrastructure that was really useful to us.
- 38:33So one of the things that Jolt was able to do is it was able to do some like normalization of like tracebacks and then be like, oh, these tracebacks are like similar enough that I'm going to group them together as like a single error and say like, oh, this many tests are failing this sort of traceback.
- 38:51Okay.
- 38:52That was really useful because it was, we were able to just sort of be like, okay, here's where the error is and it's going to fix this many tests or at least unblock this many tests.
- 39:01Yeah.
- 39:01So that was about a year of basically going through all of those test failures and figuring out, okay, why do they file fail under Python three and just fixing them?
- 39:12So a lot of it was like, oh, this thing's supposed to be a string, but it's bytes or vice versa or.
- 39:19They're calling dot items, but it's, that used to be a list and it's not a list anymore.
- 39:23Yeah.
- 39:24So you can index it.
- 39:25Yeah.
- 39:26So there's all sorts of nitty gritty things that you just have to go through and fix them.
- 39:30Some of them are automatable, but like you really need to, but not everything is.
- 39:35And some of them are more subtle.
- 39:37Yeah.
- 39:37What was your target Python three version?
- 39:39So we originally targeted three, six at the time it was the newest version.
- 39:45When we started the project, it was like the newest version that we had available.
- 39:48That was that we were like, we're like, you know, we're sort of ready for, if you will.
- 39:53Yeah.
- 39:53During, during the project was obviously a long project.
- 39:56We were able to get three, seven available.
- 39:58And it was actually really great because we were like, I don't know, I'm less than a month
- 40:02out from when we were like, oh, we're going to start doing the rollout.
- 40:05And my coworker, Chris, who wrote Dump API was working on this project at the time.
- 40:10And he was like, you know what?
- 40:11I bet we could migrate this to Python three, seven.
- 40:13And I'm like, go for it.
- 40:14Let's see.
- 40:14Let's see how hard it is.
- 40:15And he did it in like a day.
- 40:17So it was just like, it was just like, oh, he just upgraded it.
- 40:20It was like, I think there were like maybe a few three, seven does have like that
- 40:23one backwards incompatible incompatibility where it makes asymptote keywords.
- 40:26So there were like a few packages where he needed to upgrade.
- 40:29But like he was able to do it like really quickly.
- 40:31And we were just sort of like, okay, and now we're going to roll out to three, seven.
- 40:34So that was nice that it was, it was sort of like we were working on three, six for most
- 40:38of it.
- 40:38We were, we switched to three, seven near the end and it just sort of worked.
- 40:41And it says the foundation for going to the next version after that, right?
- 40:44It's actually really weird.
- 40:45Chris is working on that again.
- 40:47He's going to be trying to upgrade us to three, eight like this week, basically.
- 40:51Okay, cool.
- 40:52That's really, really excellent.
- 40:53What was the emotional state of you and the team as you were going through that year of
- 40:59fixing?
- 41:00Nope.
- 41:00It's list of dick dot items, not list dot items or dictionary dot items.
- 41:05And probably excited in the beginning, but you know, six months.
- 41:09And what was that like?
- 41:10Or making progress or like, oh God, it's still here.
- 41:12We're not done.
- 41:13I knew what it was going to be like going into it.
- 41:15Like I was like, I mean, not exactly, but like, I was like, I know that it's going to be
- 41:19this thing where it's like, we're going to make some progress and then we're going to,
- 41:21it's going to taper off because of the way that these things work.
- 41:24And, but it was definitely like, it was sort of like, you were just sort of doing your tasks
- 41:30every day and each task in and of itself was not valuable.
- 41:33Right.
- 41:33It was sort of like, oh, well, I fixed three tests today, you know, kind of thing.
- 41:37But ultimately I was able to see like where the end was.
- 41:42So for me, I was like, I was like, yeah, we're going to do this.
- 41:45We're going to do it.
- 41:45I think not everyone on my team was necessarily like as sort of buying the prize as I was, which
- 41:51is fine.
- 41:52I think we ended up, we ended up swapping out.
- 41:54Basically everyone on the team ended up working on it at one point or another, but it was only
- 41:58me and, and another one of my colleagues who, who worked on it basically the whole time.
- 42:03So I think, you know, part of it was that some people were like, okay, I'll work on that a
- 42:08little bit, but I don't want to only work on that.
- 42:10And that's totally understandable.
- 42:11Like, I think that this type of work is kind of tedious and this is sort of like, this is
- 42:16another argument against monoliths is sort of saying like, if you have to do this, when
- 42:21you need to do these, these type of migrations, it becomes really punishing on software engineers.
- 42:25Like if you haven't done linting ever, and then five years into it, you like, oh, let's
- 42:30get, see what's wrong with you.
- 42:31We're at the lunch, you're like a hundred thousand years.
- 42:33Like, you know what?
- 42:33We're not doing that.
- 42:34We're just, we're just going to ignore those.
- 42:35Let's just stay.
- 42:36Cause you can't just stop and go do a hundred thousand fixes.
- 42:40And this is, there's more value on the other side of this.
- 42:42So it's, it makes a lot of sense, but it must've been, felt pretty good to get it all done though.
- 42:47It really did.
- 42:47I mean, it was, it's sort of weird how these projects work is that like, you're sort of
- 42:52like, you're doing the work, you're doing the work.
- 42:54And then like one day you're just sort of like, and we're done.
- 42:56And it's been a year and a half of my life, you know, like, but exciting.
- 43:01It was, I had multiple people tell me, they said to me, Hey, it's so cool that you, that,
- 43:06you know, we were able to do that because I never thought it would happen.
- 43:10Yeah.
- 43:10It's kind of amazing to do something that some people are like, this won't ever happen.
- 43:15But I did, it happened and we made it happen.
- 43:17And I think that that was, you know, really great.
- 43:20Let's talk a little bit about how you were able to, to run this on Python two and three.
- 43:25What do you do?
- 43:25You basically create two virtual environments, one from each setup and then each version and
- 43:31then run test there, try it out there.
- 43:34Yep.
- 43:34That's basically it.
- 43:35I mean, there is a technique to having like code that runs under Python two and three, which
- 43:41is that, you know, you basically have to make sure that you're using compatibility layers.
- 43:45And we use six for that.
- 43:47I, that was something that me and most of the people on my team had some pretty significant
- 43:52and experience doing, because that's basically how we wrote all of our like libraries or internal
- 43:57libraries.
- 43:58And, and actually a lot of our like source ones as well, because, you know, you want
- 44:02for a long time there, you were like, okay, I want to have Python two and three compatibility.
- 44:06So having code that works under both was like pretty normal.
- 44:09Yeah.
- 44:09Making sure that that code is sort of can run under Python two and three and then building
- 44:14the virtual one, there was a little bit of nuance or like a, there was a snag there, which
- 44:18is that like something that comes up every once in a while when you're doing this kind of stuff.
- 44:23And this still, this is still a thing that happens to this day is you have, you have to
- 44:27deal with backport packages.
- 44:28So there's like the futures backport, which was the concurrent, which like concurrent futures
- 44:35was added in might've been three.
- 44:36Oh, I don't remember exactly what version of Python three Python it was added in.
- 44:40And then there was like a few other backports, functools 32 backport for adding some of the
- 44:46stuff in Python three, three twos, functools, like LRU cache, which is something we used a
- 44:51lot of.
- 44:51So those were both packages where we needed to actually install them in Python two, because
- 44:56like there are packages somewhere in our, you know, depth tree that needs them.
- 45:01So what we had, what we ended up doing is we, it was, we made this like silly little, little
- 45:06script that it just sort of like took our requirements file and then filtered out the things that don't
- 45:11under install under Python three and just spit out a new one.
- 45:14And that's the one builder Python three virtual input.
- 45:17And so that's how we have Python two and Python three virtual and they're like really similar, not exactly the same, but close enough.
- 45:24And then we can run, run the tests against either one of them.
- 45:27Nice.
- 45:27Or, and then eventually we would do, you know, do the rollout.
- 45:30It doesn't like one of the challenges had to do with caching and you have a, a way in which you were using pickle to stuff some results into memcache.
- 45:40Is it memcached D or memcached like past tense?
- 45:43I never know.
- 45:44I never know how to pronounce that, that one.
- 45:46I looked at their website like a year ago or like, I guess two years ago or something when I was actually working on this.
- 45:52And I'm sure that I know, I'm sure that I read it because it said it there.
- 45:57I remember, but I don't remember what the answer is.
- 45:59Yeah, no worries.
- 45:59All right.
- 46:00So let's go with memcached.
- 46:01I'll call it memcached.
- 46:02So you were, you were previously, you were pickling things.
- 46:06You were cpickling, but then that just became pickling.
- 46:09But at some point, it's one thing to say at the database query level, we'll deserialize and serialize an ORM object to match the schema.
- 46:17It's a whole nother to say the binary shape of this thing is the same across Python versions, which is highly unlikely, right?
- 46:24Which is pickle.
- 46:24It's basically impossible.
- 46:25Yeah.
- 46:26That was like the, yeah, that was one of the big problems that we had.
- 46:28So we're basically taking up, we were basically like, so we'd pickle, there's like a cache key and then there's a cache value.
- 46:33We'd pickle both and then the cache key, we would, we would like hash so that it could be like, you know, a specific binary sequence.
- 46:41And then that would, and then we'd, we'd key into that, you know, to get stuff out of the, out of the cache.
- 46:49And, but it turns out that for a multitude of reasons, both the key, like you said, the key is not going to be binary the same.
- 46:56So like, that's one of the problems.
- 46:57And the other problem is that there's a lot of like weirdnesses when you end up like either reading Python two pickles in Python three or reading Python three pickles in Python two.
- 47:08It seems like pickles are kind of meant to be transient.
- 47:11They're not meant to sort of be long-term storage because there's not a lot of guarantees around their parsability.
- 47:16Yeah.
- 47:17We were like, okay, well, what's, what's a thing that we can do where we don't have to start being like, okay, now we have to write complicated serialization and stuff.
- 47:26And we were like, well, probably JSON, JSON will work.
- 47:29And so this is something I worked on for about three months or something was just migrating all of our caches to, to use JSON instead of pickles.
- 47:37Yeah, you had this kind of fallback mechanism or this slow upgrade mechanism that said, try to get the JSON version from memcache.
- 47:46And if you got it, awesome, go with that.
- 47:48But then fall back and try to get the binary pickle, but then immediately replace it with the JSON version so that it just grows over time.
- 47:57I mean, thinking about that much code and that many services, there must just be a ton of startup cost if you just kick all the servers over and clean the cache.
- 48:05We've never tried it.
- 48:06I think everyone's a little bit too scared, but it's definitely like not something we wanted to do.
- 48:11And we wanted to be able to be like, okay, for when we cut over to Python 3, we're not just going to lose all of our caches.
- 48:16I think this is actually a really great example of something we were discussing before the recording started of like doing a sort of like incremental upgrade.
- 48:24And one of the other things I didn't super get into with in my talk is that like one of the things that I felt was a really cool technique, and this really depends on whether or not this is worth it.
- 48:36It depends on like how you end up, what the value of your like uptime is basically compared to your dev time.
- 48:42But what I did is I sort of logged.
- 48:45What I would do is I would like for every cache, I'd be like, okay, I'm going to try to log this to JSON.
- 48:50And then if it failed, I wouldn't just fail.
- 48:52I'd like do the normal stuff.
- 48:54I'd do all the pickle stuff, whatever.
- 48:56But then I'd log it somewhere.
- 48:57And so that way, I could just like look at this log and be like, oh, here's where my errors are.
- 49:01So it wasn't just like, oh, I would do I would like ship changes and then like, see if there were actual errors on prediction is like, there's no errors on prediction.
- 49:10There's just errors in this log that I can like fix and like iterate on and no, you know, user ever sees a sees a 500.
- 49:19Not everything can fit into that.
- 49:20But I think that that's a really I think that's a really useful.
- 49:23Yeah, that is really cool because no matter how much testing you do on something this big, it's not until you really put it out there, you see that 100% sure it's going to hang together.
- 49:31But if it can fail silently in a way that people don't see, but you you get notified about this and can start working on it.
- 49:39That's yeah, that's really valuable.
- 49:41Another thing that you did that I thought was pretty clever was the way that you did the rollouts where you were able to say, even though this is one huge monolith of code, that doesn't mean it breaks.
- 49:53Evenly, right?
- 49:54Once you get it past the parsability stage, there could be some URL endpoint that's going to fail if you request it and another that works totally fine.
- 50:01All right.
- 50:02So what you were what you all did is you created a reverse proxy.
- 50:06And I was imagining Nginx.
- 50:08What were you actually using here?
- 50:10So it's kind of Nginx.
- 50:11It's open Resty, which is a framework where you can write plugins for Nginx in Lua.
- 50:20So you can you can do some sort of, you know, general logic in that.
- 50:24So you were basically able to say, you know, when you go to Yelp dot com slash something or API dot Yelp dot com or whatever it is, as far as a user, it's the same.
- 50:32But some of those URLs are hitting the Python 3 version of this large monolith app running and some are hitting the Python 2.
- 50:39And you could move it URL, URL endpoint endpoint at a time.
- 50:44Right.
- 50:44Yeah.
- 50:45Talk to us about that.
- 50:45That's pretty clever.
- 50:46Yeah, this is a super cool technique.
- 50:49So we already had the reverse proxy layer.
- 50:52We had the routing service.
- 50:53This is something that we had built for just sort of consolidating a bunch of logic in a general place where like everything could rely on it.
- 51:01But it was a really great place for us to be able to put this logic as well.
- 51:06And I'm going to say say him again.
- 51:09Chris Keel on my my colleague on my team came up with this idea as well.
- 51:14So it's it's such a great idea.
- 51:16And it applies, I think, really generally.
- 51:18Like you can just sort of say like, OK, anytime I'm doing some sort of rollout where the setup is such a what in such a way that like I can't like do it within my application.
- 51:27Like there's something about the application setup you can if you have this external layer, then you can then you can pretty easily do it.
- 51:34And yeah, it was basically just sort of like, you know, we would have a configuration and it would say like, OK, this like prefix endpoint or like this endpoint prefix would go to Python 2 or this one would go to Python 3.
- 51:47And we can actually even be a little bit more granular that we could actually give it a percentage of the time.
- 51:51So basically like, you know, 20 percent of the time it goes to Python 2, 80 percent of the time it goes to Python 3.
- 51:57And so we could do these sort of slower rollouts if people wanted to be more careful.
- 52:01I see.
- 52:02So maybe it goes like it's on Python 2.
- 52:04Now 1 percent of the traffic goes to Python 3.
- 52:07Is it dying or no?
- 52:08It seems OK.
- 52:09It seems OK.
- 52:10All right.
- 52:10Now 20.
- 52:11Now 80.
- 52:12Like you could like slowly move it over.
- 52:14So if it fails, at least it fails just for a few people.
- 52:18And you can you don't even roll it back.
- 52:20You just stop sending traffic there and fix it, which is really good.
- 52:24Yeah.
- 52:24Yeah.
- 52:24Very clever.
- 52:25And it certainly makes sense for large projects.
- 52:27But what's great is it lets you start getting your Python 3 version in production way earlier.
- 52:32Right.
- 52:33You're not waiting on the last endpoint.
- 52:34You just need the first endpoint.
- 52:36I mean, probably you didn't do this very like one URL works.
- 52:38Put it out there.
- 52:39But like you could do it much sooner than you would otherwise.
- 52:42Right.
- 52:42For various sort of practical reasons, we didn't do we didn't want to actually start
- 52:48the rollout until we were like, oh, all of the tests pass under Python 3.
- 52:52Because we didn't want people to be like, oh, I'm running my tests and they're not passing
- 52:57and that's bad.
- 52:58And I mean, they're going to like ignore them or try to fix them in a bad way and stuff like
- 53:02that.
- 53:02But like, I mean, it was like a two month process where we were like from the first endpoint
- 53:07to the last endpoint.
- 53:08It was like two months.
- 53:08And so that was able that was really nice because it was like, oh, we would dissect
- 53:14issues and then we would but we would keep rolling out other stuff.
- 53:17And then, you know, the teams or we could try and fix the issues.
- 53:21And so.
- 53:22Very neat.
- 53:22That's great.
- 53:23All right.
- 53:24Let's wrap this up.
- 53:25We're getting short on time here.
- 53:27You had some clear benefits, even though you went to Python 3.6, which I think you'll
- 53:32see those benefits again if you go to 3.11.
- 53:34All right.
- 53:35But even so, going from where do you go from 2.7 to 3.6?
- 53:40We went from 2.7 to 3.7.
- 53:422.7 to 3.7.
- 53:43Right on.
- 53:43OK, cool.
- 53:44And you said it got faster and used less memory.
- 53:47That's pretty good.
- 53:48I don't remember the exact numbers.
- 53:49It was in my talk.
- 53:50I stole from your talk.
- 53:5115 to 20 percent speed up and 20 percent less memory.
- 53:54That's that's tangible.
- 53:56That's right.
- 53:56That's right.
- 53:57Yeah.
- 53:57I remember this is something I didn't mention in my talk, but I thought I think it's kind
- 54:00of interesting.
- 54:01So we have some stuff that is, you know, more CPU heavy, which we send to what we call VIP
- 54:11instances.
- 54:12So VIP like containers have more memory and more CPU allocated towards them.
- 54:19And so I remember I talked to someone who was involved in like doing a lot of that sort
- 54:24of like operational stuff.
- 54:26And after that migration, they like looked at numbers and they were like, oh, we can
- 54:31now scale down the VIP to what the old normal one was.
- 54:36And the normal one is now scaled down even more.
- 54:38Oh, that's cool.
- 54:38Yeah.
- 54:39Which was super cool.
- 54:40So it was like super good to do that.
- 54:42And I think that beyond just sort of like, oh, this like gave us this immediate or this
- 54:48gave us this like outcome.
- 54:50It's like we weren't going for this outcome, but I think it really shows how like this type
- 54:54of work, like if you're like, you know, I think very often it's easy to look at like
- 54:58base level infrastructure work is like, oh, well, it's just maintenance and you just need
- 55:02to do it and blah, blah, blah.
- 55:03And, you know, it's not really benefiting anything.
- 55:05And it's like, no, like we did this and it like saved money on our bottom line, you know,
- 55:10and not necessarily everything is going to be like that.
- 55:12But like, I think that thinking about base level infrastructure is like it does have a
- 55:17benefit.
- 55:18It might not necessarily be obvious before you do it.
- 55:22But, you know, this is an example of, OK, if you're doing your upgrades, you get to take
- 55:27advantage of all the really hard work that all of the people on the Python language team
- 55:31have done to make the, you know, make it more efficient and faster.
- 55:35Yeah.
- 55:35And it probably opens up other possibilities.
- 55:37The previous show I just did, which not out yet, so you wouldn't know, but was talking
- 55:41about rough the linter written in Rust for Python.
- 55:45But, you know, you have this ability to integrate with more modern tools and modern language.
- 55:49It's like, oh, if we got to rewrite this section and Rust for that computation, it's trivial
- 55:54now where probably it wasn't before.
- 55:56I would imagine.
- 55:57I haven't tried it in grading by the seven with, you know, things like that.
- 56:01But I bet it's not as easy as the new tools, you know?
- 56:04Yeah, for sure.
- 56:04All right.
- 56:05Well, let's leave it here.
- 56:06I think that's all the time we got to talk about it.
- 56:09But, you know, you must be enjoying it, enjoying work on the projects and the features more now.
- 56:14You can just kind of the world is your oyster again.
- 56:17Yeah.
- 56:17I love using the project that I've been working on actually lately is we've been adding a lot
- 56:22of type annotations internally.
- 56:24That's, you know, a Python 3 feature right there.
- 56:26Yeah, absolutely.
- 56:27You can use f-strings.
- 56:28You can use type annotations.
- 56:30You can start using tools like mypy, not just standard type annotations just for editors.
- 56:35But yeah, Pydantic, for example, all those things, right?
- 56:40Very cool.
- 56:40All right.
- 56:41Now, before you get out of here, I got two questions.
- 56:43I always ask at the end of the show, if you're going to write some Python code, what editor are
- 56:48you using these days?
- 56:48I'm a VIN person.
- 56:49Do all my development in VIN.
- 56:52Right on.
- 56:52And then notable PyPI package.
- 56:55Give a shout out to Python Modernize.
- 56:57But anything that stands out you want to give a shout out to like that?
- 57:00I mentioned Python Modernize.
- 57:01Great, excellent tool for what it is.
- 57:03I also give a shout out in my, I give a shout out to a couple other things in my talk.
- 57:08But I think they're definitely worth giving a shout out to still, which is PyUpgrade, which
- 57:13we mentioned earlier.
- 57:14It has a lot of really nice features.
- 57:17But one of the sort of other things is kind of the other half of Python Modernize is that
- 57:22it can take your sort of six shim filled code and turn it into sort of normal Python recode.
- 57:28And then another tool by the same, same former colleague of mine, Anthony Stille, is pre-commit.
- 57:35They're modernized as a pre-commit hook.
- 57:36Packrate is a pre-commit hook.
- 57:38That's a, that's a thing that we use extensively internally.
- 57:40Super, super nice to be able to like, you know, do all those sorts of things and, and, and
- 57:45do it in an incremental way, which is something that was really valuable.
- 57:48And then the last one, this is just completely random one, but I just love it is more iter
- 57:54tools.
- 57:54One of my favorite packages.
- 57:56We have like an internal package that has a lot of the like functions that are in more
- 58:01iter tools, but they're worse or like quirky in some way that I, that I don't like.
- 58:05And so that's something that was like, when I first found out about it, I was like, oh man,
- 58:10this is great.
- 58:10And, and I think it's pretty popular now, but like, I think it's, it's one of those things
- 58:14where it's just sort of like, oh, these, all these little functions that you're like, oh,
- 58:17I could write that.
- 58:18And it's like, you could, but you'd probably write it, you know, with bad edge cases or
- 58:21something.
- 58:22It's just, it's a great, great library.
- 58:24And it's better if you don't have to write it.
- 58:26That's for sure.
- 58:26Yes.
- 58:27All right.
- 58:27Well, Ben, thanks for being on the show.
- 58:29Final call action.
- 58:29Maybe some other people are out there facing this transformation they got to do.
- 58:34Like I said, not actually Python two to three, but you know, some major foundation in their
- 58:38code base to another, what do you tell them?
- 58:40Figure out a way to make it incremental.
- 58:42That's really, I think the main takeaway for me is that incremental changes.
- 58:47changes have multiple benefits.
- 58:49They're making you less risky.
- 58:51You're able to do these types of changes in a way like where you don't necessarily have
- 58:56to be like, oh, we have to schedule two years of work.
- 58:58It's like, no, you can do, you can do it, you know, a chunk at a time when you have time.
- 59:03And also it just like generally makes your, you have less errors.
- 59:08Absolutely.
- 59:09All right.
- 59:10Well, thanks so much for being here.
- 59:11It's been great to have you on the show.
- 59:12Appreciate it.
- 59:13Thanks so much for having me.
- 59:15This has been another episode of Talk Python To Me.
- 59:18Thank you to our sponsors.
- 59:20Be sure to check out what they're offering.
- 59:21It really helps support the show.
- 59:23Join Cox Automotive and use your technical skills to transform the way the world buys,
- 59:28sells, and owns cars.
- 59:30Find an exciting position that's right for you at talkpython.fm/cox.
- 59:36Earn extra income from sharing your software development opinion at user interviews.
- 59:41Head over to talkpython.fm/user interviews to participate today.
- 59:45Want to level up your Python?
- 59:47We have one of the largest catalogs of Python video courses over at Talk Python.
- 59:51Our content ranges from true beginners to deeply advanced topics like memory and async.
- 59:56And best of all, there's not a subscription in sight.
- 59:59Check it out for yourself at training.talkpython.fm.
- 1:00:02Be sure to subscribe to the show.
- 1:00:04Open your favorite podcast app and search for Python.
- 1:00:07We should be right at the top.
- 1:00:08You can also find the iTunes feed at /itunes,
- 1:00:11the Google Play feed at /play,
- 1:00:13and the direct RSS feed at /rss on talkpython.fm.
- 1:00:17We're live streaming most of our recordings these days.
- 1:00:21If you want to be part of the show and have your comments featured on the air,
- 1:00:24be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:00:28This is your host, Michael Kennedy.
- 1:00:30Thanks so much for listening.
- 1:00:32I really appreciate it.
- 1:00:33Now get out there and write some Python code.
- 1:00:35I'll see you next time.
- 1:00:35Bye.
- 1:00:35Bye.
- 1:00:36Bye.
- 1:00:36Bye.
- 1:00:36Bye.
- 1:00:36Bye.
- 1:00:37Bye.
- 1:00:37Bye.
- 1:00:37Bye.
- 1:00:37Bye.
- 1:00:38Bye.
- 1:00:38Bye.
- 1:00:38Bye.
- 1:00:38Bye.
- 1:00:38Bye.
- 1:00:39Bye.
- 1:00:39Bye.
- 1:00:40Bye.
- 1:00:41Bye.
- 1:00:42Bye.
- 1:00:43Bye.
- 1:00:44Bye.
- 1:00:45Bye.
- 1:00:46Bye.
- 1:00:47Bye.
- 1:00:48Bye.
- 1:00:49Bye.
- 1:00:50Bye.
- 1:00:51Bye.
- 1:00:52you
- 1:00:53Thank you.
- 1:00:55Thank you.