Latest / Talk Python To Me / #14: Moving from PHP to Python 3 with Patreon
Transcript
- 0:00Today, you'll learn how Patreon is helping people live their dreams, building amazing
- 0:04creations for the rest of us.
- 0:05It's time for Talk Python.
- 0:07This is show number 15.
- 0:09Today, our guest is Albert Hsu, and this episode is recorded Tuesday, January 2nd, 2015.
- 0:15Hello, and welcome to Talk Python To Me, a weekly podcast on Python.
- 0:46The language, the libraries, the ecosystem, and the personalities.
- 0:48This is your host, Michael Kennedy.
- 0:51Follow me on Twitter, where I'm @mkennedy, and keep up with the show and listen to past
- 0:55episodes at talkpythontome.com.
- 0:58This episode, we'll be talking with Albert Hsu from Patreon about migrating to Python.
- 1:03I'm really fortunate to have CodeChip and Hired sponsoring the show.
- 1:08Let me take just a few seconds to tell you about them.
- 1:12CodeChip is a platform for continuous integration and continuous delivery as a service.
- 1:16They encourage you to always keep shipping.
- 1:19Please take a moment and check them out at codeChip.com or follow them on Twitter, where
- 1:24they're at CodeChip.
- 1:25Hired wants to help you find your dream job.
- 1:28Hired is built specifically for developers looking for new opportunities.
- 1:31Check them out and get a very special offer at Hired.com slash Talk Python To Me.
- 1:36And you'll find them on Twitter, where they're at Hired underscore HQ.
- 1:40Let me tell you how we got to the show.
- 1:44It all started with me whining about bandwidth charges on Twitter, saying it was so expensive
- 1:49to run a podcast.
- 1:50Look at these things grow.
- 1:51And then Justin Spain from Chattanooga, Tennessee, who's at JWS Music on Twitter, said,
- 1:57why don't you start a Patreon campaign?
- 1:59Of course, when I read that, I thought, well, what's a Patreon campaign?
- 2:04Then it turns out that Justin was right.
- 2:05Patreon is actually perfect for things like podcasts, blogs, frequent videos, and even
- 2:10open source projects.
- 2:11Listeners, readers, and so on, pledge a small amount to each release, in my case, each episode.
- 2:17And when one of these episodes ships, a small amount of money is contributed back to me to
- 2:22help keep the podcast going.
- 2:23If you want to learn more about my campaign, you can find it at Patreon.com slash mkennedy.
- 2:30So fast forward a month, the guys at Patreon noticed my campaign and happened to be making
- 2:35a company-wide transition to Python 3 from PHP.
- 2:38So they reached out to me on Twitter, and we thought it'd be cool to talk about their port
- 2:43of their product to Python.
- 2:44And we talk about how that's going.
- 2:46In case you don't make it all the way through the whole show, it's going great.
- 2:50I also want to take a moment and say a special thank you to the 30-plus patrons who are already
- 2:55supporting the show.
- 2:56Right now, your contributions are covering a little more than the monthly bandwidth expenses
- 3:00for the show.
- 3:01This allows me to use my sponsorship money for extra benefits, such as creating searchable
- 3:05transcripts and things like that.
- 3:07But more importantly, your support has given me the confidence to push hard on making this
- 3:12podcast all that it can be.
- 3:14And of course, there's still a long way to go there.
- 3:16So thank you for the help.
- 3:17You might also be interested to hear that Patreon is hiring Python developers and data
- 3:22scientists.
- 3:23Check out patreon.com slash careers if you want to be part of a sweet team in San Francisco
- 3:29who are building out a business and putting a dent in the world using Python.
- 3:33At some point during the show, I make a statement that PHP is one of the most dreaded languages
- 3:39and technologies of 2015.
- 3:41I was quoting from the Stack Overflow 2015 developer survey.
- 3:45You'll find the links in the show notes.
- 3:46And I have a bit of a correction there.
- 3:48Sorry.
- 3:49It was Perl that was part of the most dreaded list, not PHP.
- 3:54PHP didn't make the top nine.
- 3:57However, I suspect maybe it's lingering just off stage at place 10 or 11 or 12.
- 4:02And in case you're wondering, what is the most dreaded technology on the list?
- 4:07It's Salesforce.
- 4:08All right.
- 4:09Finally, the Talk Python To Me t-shirt Kickstarter project is still running.
- 4:14It will be open for nine more days.
- 4:16So be sure to visit bit.ly slash Python shirt to reserve yours.
- 4:20It's a cool and comfortable cotton shirt that will tell the world about your unabashed love
- 4:25for Python.
- 4:25Now let's get to the conversation with Albert and Patreon.
- 4:30Albert, welcome to the show.
- 4:32Hi.
- 4:33Thanks for having me.
- 4:34Yeah.
- 4:34I'm really glad that you guys contacted me.
- 4:36And I'm looking forward to the conversation.
- 4:38We haven't really had much talk on moving from one technology into Python.
- 4:45And that's our main subject today.
- 4:47So thanks for being here.
- 4:49Thanks for reaching out.
- 4:50And we always, Patreon is a creator-first platform, and we'd always like to support our creators
- 4:55in any way we can.
- 4:56Yeah.
- 4:57So we'll get to Patreon in just a second and sort of how this show came into existence.
- 5:02But I always like to start off the show asking my guests who have achieved a lot in their
- 5:08careers.
- 5:08And how did you get started in programming?
- 5:11And how did you come to start using Python?
- 5:13So I actually got started with programming pretty early.
- 5:17I actually borrowed my brother's computer science A-B textbook when I was really young and just
- 5:23went through some of the exercises in C++.
- 5:25It wasn't the best way to learn things, but it got me introduced to a lot of really small
- 5:32things like how to print things out to a screen, how to do for loops.
- 5:35And back then, I was pretty entertained just by doing really simple programs like little small
- 5:40games where you can put your name and someone outputs your name right back at you.
- 5:44Yeah.
- 5:45I think we've all written those types of apps, and they're super fun.
- 5:48Just the feeling of satisfaction and accomplishment is surprising for you, right?
- 5:53Yeah.
- 5:54Especially when you're really young and your standards are lower.
- 5:57But as I sort of grew up, I started programming a lot more on calculators, on TI Basic.
- 6:02I decided to pursue programming as my major in college.
- 6:05And I was still pretty gung-ho about C++.
- 6:08I thought it was a hardcore language.
- 6:10I thought that all the hardcore programmers would do C++.
- 6:13Until freshman year, someone introduced me to Python, and I thought it was kind of a weak
- 6:20language because it didn't feel as hardcore.
- 6:22Yeah.
- 6:23I think that's a common feeling, or maybe misconception is a better way to say it.
- 6:27But a lot of people feel like the really tough guys do C++, and they're right down there in
- 6:32the memory and on the metal.
- 6:33And all you other guys are just fooling around, orchestrating our code or whatever that we write
- 6:38in C++.
- 6:39But I'm not sure that's really true or fair, is it?
- 6:42That was my impression at the time.
- 6:44And what really changed me is when I actually had to do a lot of project courses in college,
- 6:49I realized I could actually do things correctly and quickly.
- 6:54And in terms of performance or the standards of the code, much better in Python than I could
- 7:02in C++.
- 7:04And I just continued using Python whenever I could all through college.
- 7:08I didn't get a chance to use it professionally until about a couple years ago when I started
- 7:13at a company called Quora.
- 7:14Quora, is that the QA site?
- 7:17Yeah, that's right.
- 7:18Quora is a question and answer site.
- 7:20I started it pretty early and saw a lot of the really cool things that they were doing with
- 7:24Python.
- 7:25A lot of stuff with generators and with metaclasses and decorators.
- 7:29And it really turned me on to Python as a really serious language.
- 7:33And part of what I want to do at Patreon is take a lot of those more advanced Python techniques
- 7:39and bring it into our infrastructure.
- 7:40Oh, that's really cool.
- 7:42But when you got to Patreon, it wasn't originally in Python, was it?
- 7:47No, it was in PHP.
- 7:48It started in PHP because that was the fastest way to bring the product to life in the early
- 7:53stages.
- 7:54But as the product grew and as the engineering team grew, it started to become pretty clear
- 7:59that PHP wasn't going to scale with the team.
- 8:03Is that from a performance perspective or from an adding new features and maintainability
- 8:09perspective?
- 8:10The number one thing was maintainability.
- 8:13And it's not 100% like PHP's fault, but rather PHP allows you to do certain things that make
- 8:20the code way messier than you want your core code to be.
- 8:25A lot of things with PHP just allow you to do things very quickly.
- 8:29And when you're adding more and more engineers, when you're going from one engineer to two to
- 8:33three to ten, you don't necessarily want to do everything the fastest possible way.
- 8:39We did want to do things fast.
- 8:41In fact, the concept of shipping quickly is still important to our engineering culture.
- 8:45But we want to be able to ship quickly in a way that's maintainable and a way that uses the proper
- 8:50abstractions in a way that isn't copy pasting, I guess.
- 8:55Let's talk a little bit about what those differences are and stuff.
- 8:59But before we do, maybe you could tell everyone, what is Patreon?
- 9:03Yeah.
- 9:04Patreon is a subscription funding for creators.
- 9:07And the way it works is that patrons will pledge a set amount per release.
- 9:12Every time a creator publishes a new creation, so like a webcomic, a video, a blog post, a podcast,
- 9:17anything, funds are transferred from patrons to the creator.
- 9:21We launched in May of 2013.
- 9:24And as of summer 2014, we announced that patrons were sending over $1 million monthly to creators
- 9:32through Patreon.
- 9:32A million dollars a month.
- 9:34That's amazing.
- 9:34Yeah.
- 9:35And we're still growing.
- 9:36We just passed $2 million very recently.
- 9:38And the company itself is about 24 people.
- 9:42We're headquartered in Soma in San Francisco and actively hiring.
- 9:45Okay.
- 9:46And they're doing Python.
- 9:47And I suspect you'll reach a lot of intrigued Python developers out there.
- 9:51So that's a good message.
- 9:53Yeah, that's the hope.
- 9:54Yeah, excellent.
- 9:55So I'm personally using Patreon.
- 9:57And that's how we got to know each other.
- 10:11CodeChip is a hosted continuous delivery service focused on speed, security, and customizability.
- 10:19You can set up continuous integration in a matter of seconds and automatically deploy when your tests have passed.
- 10:25CodeChip supports your GitHub and Bitbucket projects.
- 10:28You can get started with CodeChip's free plan today.
- 10:31Should you decide to go with a premium plan, Talk Python listeners can save 20% off any plan for the next three months by using the code TALKPYTHON.
- 10:39All caps, no spaces.
- 10:41Check them out at CodeChip.com and tell them thanks for sponsoring the show on Twitter where they're at CodeChip.
- 10:52I was on Twitter complaining like I do sometimes about paying for bandwidth and stuff for my podcast because it's going up.
- 11:02It's kind of like doubling each month.
- 11:04And it's, you know, not a huge number now, but doubling a medium-sized number becomes a problem really quick, right?
- 11:10So I was saying, well, this is getting pretty expensive, OGs.
- 11:13And a guy, I believe his name is Justin on Twitter, says, hey, why don't you use Patreon?
- 11:19And that's the first I heard of you guys.
- 11:21So I'm like, wow, let me go create an account or a campaign on Patreon.
- 11:24I thought of other ways to kind of do this.
- 11:26Like maybe Kickstarter might be an answer.
- 11:28But to me, Kickstarter is the wrong thing because it's like you fund this thing once and there's like a big bang creation.
- 11:35And that doesn't really work for things like ongoing podcasts or sort of steady state stuff, like you're saying, like web comics or things like XKCD type stuff, right?
- 11:45Yeah, that's right.
- 11:46Our goal is that people who want to create things are able to make a living off those creations.
- 11:51And to do that requires sort of mimicking the structure that I guess like a job sort of has or mimicking the idea of having like ongoing support for your ability to create things.
- 12:05And I think it's a lot of the reason why I joined Patreon is because I believe in the mission.
- 12:11And a lot of the people who work here as well also believe in the mission.
- 12:15I think it's a really great mission.
- 12:16And it definitely makes having my podcast simpler.
- 12:20And I just want to say thanks to everyone out there who's contributed to my campaign so far.
- 12:25And I think what you guys are doing is really great.
- 12:27So I was super excited about it when I first heard of it.
- 12:29It just I hadn't heard of it before.
- 12:31So let's talk about PHP a little bit.
- 12:34So it was originally written in PHP.
- 12:35And to be honest, I don't have a ton of experience personally with PHP.
- 12:39But what are some of the pain points that you're solving with Python?
- 12:44A lot of organization of code.
- 12:47I think with namespaces, I think it's just I mean, it's a very simple feature.
- 12:52But being able to segment our code out into separate modules allows different teams to work on different aspects of the site.
- 13:00Secondly, with decorators or with like a sort of single points of entry for application.
- 13:09The way we're currently using Flask and the way the Flask does routing is like through decorators.
- 13:15And because we're doing everything through this standardized way, if we want to change something like if we want to say start recording response times and graphing that on a chart, we can just do that by modifying decorator rather than trying to input that into each individual PHP script.
- 13:31Right.
- 13:31Right.
- 13:31The way they do decorators with what is it?
- 13:33App.route as a decorator on all the methods that power the views.
- 13:37Yeah, that's right.
- 13:38Yeah, that's really cool.
- 13:39We just had Armin on the show for the previous show.
- 13:43So people hear more about him.
- 13:45I'm assuming it's pretty cool.
- 13:45But yeah, I'm a big fan of Flask.
- 13:47And you guys said you're doing Python 3, right?
- 13:50That's right.
- 13:51That was sort of one of the small risks that we took.
- 13:54Most of the other technologies that we use are pretty boring or at least like pretty standard like Flask or SQLAlchemy or Jinja 2.
- 14:01But we decided that we would go with Python 3 going forward because we wanted to make sure that our code base is going to be future proof.
- 14:10I think that's a really nice choice.
- 14:12And I see more and more people moving to Python 3.
- 14:15There's still a lot of folks doing Python 2.
- 14:18But it just seems a little wrong is not the word I'm looking for.
- 14:25But it just seems like something is out of balance where there's a lot of people working on Python 3 to push the future of Python.
- 14:32And then there's so many people who are actually not using it.
- 14:35Some of the biggest users of Python are not using kind of where the community is focusing its effort.
- 14:40And so I personally think any time you get a chance to use Python 3 is kind of helping the community move along, let's say.
- 14:48The way we went about it, actually, we took a look at the wall of superpowers and just saw what are the modules that we need to actually build our application.
- 14:59Most things that we needed are already implemented.
- 15:02The one thing that was missing was MySQL DB.
- 15:05And that was pretty easily replaceable by PyMySQL.
- 15:08And so it's been actually a really, really simple switch for us.
- 15:11The biggest sort of hump that we ran into is that, like, Stack Overflow or Google defaults to Python 2.7 in terms of its help.
- 15:19But it's been a dream for us to work with.
- 15:22Yeah, that's really great.
- 15:23So let's see.
- 15:25You're using Flask.
- 15:26It sounds like you're using MySQL.
- 15:28It's the back end.
- 15:29SQLAlchemy.
- 15:31SQLAlchemy is really fantastic.
- 15:33What else are you using?
- 15:34Any other cool parts of Python or libraries?
- 15:36Our starting point was just to mimic as much of PHP as possible.
- 15:42And so in terms of complicated technologies, we actively chose against using any of them.
- 15:49A lot of really standard modules like requests or Jinja 2.
- 15:52But nothing too out there yet.
- 15:55That makes perfect sense.
- 15:56Let's talk a little bit about the whole porting concept.
- 15:59Porting your code is basically a rewrite when it's this divergent of a technology, right?
- 16:06And so that's a pretty big risk.
- 16:08How did you guys decide that that was the path forward?
- 16:11Yeah, it was a pretty big risk.
- 16:13In fact, I've been burned by a lot of ports in the past.
- 16:16A previous project I've had was porting something from Python to Scala.
- 16:20And I think that's a much, much more difficult process to go through because you're putting basically a dynamic language into a static language.
- 16:27And that just adds a lot of weight to the process.
- 16:31We decided pretty early on that PHP wasn't going to be how we wanted to go forward with engineering.
- 16:39The decisions we had to make were, like, given the current PHP code base, could we refactor it into something that's more workable using, like, a modern framework?
- 16:48Should we port it to Python or should we port it to, like, I guess a crazier language like Scala or Java?
- 16:54We didn't want to, like, the ecosystem of PHP was, we found, much weaker than that of Python.
- 17:01I think a lot of the main consumers of PHP has mostly revolved around Facebook and a little bit around, like, the Wikimedia Foundation.
- 17:10But besides that, not a lot of support.
- 17:12Whereas Python has what feels like a more active developer community, a more active ecosystem.
- 17:17It lends us a lot more legitimacy for hiring engineers.
- 17:21It is more consistent of a language.
- 17:24And it was just different enough from PHP but close enough that, like, we felt comfortable doing a one-to-one translation from PHP to Python.
- 17:34Right.
- 17:35It was different, but it wasn't completely alien to make that transformation, huh?
- 17:39Yeah.
- 17:40The other option we had with Scala was just too different and, like, too many unknowns.
- 17:45And when it comes to ports, I think there's usually a pretty high probability that a port will fail.
- 17:52I've seen a lot of port projects just, like, fail in the past.
- 17:55And in order to prevent that from happening, I think we as a company decided we want to take as few risks as possible.
- 18:02Yeah, that makes a lot of sense.
- 18:04You'd mentioned, like, sort of developer happiness and things like that.
- 18:11There's a really interesting yearly developer survey by Stack Overflow that comes out, and they sort of rank technologies, what's growing, what are the jobs, what are technologies people love, and what are technologies people strongly dislike, let's say.
- 18:27It's a concern that they're working with it.
- 18:31And I think Python was on the list of the beloved technologies, and PHP might have been on the list of the ones to kind of stay away from.
- 18:38So you think it's easier to hire people because you can say, hey, come work on this cool Python 3 Flask project than it is to say, come work on this PHP project?
- 18:47When it comes to PHP, PHP has been really easy to develop new things, but it makes it extremely difficult to maintain that code after it's been developed.
- 18:59And I think that the gains you get with PHP are also seen a lot in Python, but the maintainability of Python is so much greater for us.
- 19:07Engineers, I think, rank maybe a little bit unfairly, certain languages as more hardcore than others.
- 19:16I think PHP ranks pretty low.
- 19:18I think there's a lot of unfair feelings towards PHP, especially since it's been developed and it's been actively used by companies like Facebook.
- 19:28Yeah, and things like WordPress, right?
- 19:30And there's some pretty amazing stuff out there.
- 19:33Yeah.
- 19:34But there's a lot of parts core to the language, a lot of inconsistencies, a lot of things like global namespacing, a lot of things like having to worry about security or magic quotes or PHP ionized that worked well in the past, but don't really hold up against the modern language.
- 19:51Sure.
- 19:52That makes sense.
- 19:53So you chose Python over the other options that you listed and obviously the ones that you didn't list as well, like over all the other possibilities.
- 20:01Does that mean that a lot of the people there had lots of Python experience and that's kind of what they wanted to move to?
- 20:07Or how did you as a group decide?
- 20:19This episode is brought to you by Hired.
- 20:22Hired is a two-sided, curated marketplace that connects the world's knowledge workers to the best opportunities.
- 20:28Each offer you receive has salary and equity presented right up front and you can view the offers to accept or reject them before you even talk to the company.
- 20:37Typically, candidates receive five or more offers in just the first week and there are no obligations ever.
- 20:44Sounds pretty awesome, doesn't it?
- 20:46Well, did I mention there's a signing bonus?
- 20:48Everyone who accepts a job from Hired gets a $2,000 signing bonus.
- 20:52And as Talk Python listeners, it gets way sweeter.
- 20:56Use the link Hired.com slash Talk Python To Me and Hired will double the signing bonus to $4,000.
- 21:04Opportunity's knocking.
- 21:06Visit Hired.com slash Talk Python To Me and answer the call.
- 21:09Yeah.
- 21:10As a group, we actually have a lot of really disparate skills.
- 21:23Some in Java, some in Ruby, some in JavaScript, and some only in PHP.
- 21:28There was no language that everyone was going to be really favored on.
- 21:35And as a result, we just had to make a decision.
- 21:37We chose Python because we knew it would be pretty safe.
- 21:40And we knew that, like, Python is a really easy language to just pick up over a weekend.
- 21:47Like, it's the tutorial on Python or the way that most people, like, learn Python is usually over a weekend.
- 21:53Getting the very basics of it are pretty easy.
- 21:56And getting into the depth is, like, a gradual learning curve.
- 22:00I think it is a super easy language to learn.
- 22:02Where the real work is learning all the standard libraries and all the popular packages, right?
- 22:08Like, really mastering things like SQLAlchemy and Flask.
- 22:11And, right, that's the real learning curve.
- 22:13But it's kind of unavoidable.
- 22:15Yeah, that's totally right.
- 22:16Nice.
- 22:17So you guys sort of chose Python because it would more or less make everybody happy.
- 22:22And it was a really good, safe choice.
- 22:24I think that's a pretty fair characterization.
- 22:26I've heard somewhere, I can't remember if it was when I was talking to the guys at PayPal or if I heard it from LinkedIn.
- 22:33But, you know, as people said, other places that they've chosen Python because it was everybody's second favorite language.
- 22:41Like, a lot of people really, really like Ruby.
- 22:43I've also worked with Ruby professionally.
- 22:46I like it as a language.
- 22:48But sometimes, like, yeah, we had to pick something that's good for everyone, not necessarily great.
- 22:54Right.
- 22:55Somebody's got their pet language that they're super happy about, but, you know, other people dislike it.
- 23:00And so, yeah, I think Python fits really well in those situations.
- 23:04What really helped us with Python also or making that decision was that the amount of movement in terms of data science or, like, with, like, SciPy or NumPy has been, like, much greater than a lot of other languages.
- 23:17And we knew that eventually if we wanted to do sort of like a data-driven approach to our projects or a data-driven approach to our roadmap, that getting our stuff in Python would lead to a lot of – would allow us to hire a lot more data science people or, like, allow them to onboard a lot quicker as well.
- 23:35Yeah, and crossover as well.
- 23:37So you might know the whole spectrum even better.
- 23:40There was a really interesting PyCon presentation from Fernando Perez, the guy who started IPython, at PyCon 2014.
- 23:49And he talked about how the adoption of Python and IPython and data science is so taking off.
- 23:57Maybe I'll link to that video in the show notes.
- 23:58But basically he said, you know, if you look at the technologies used in the stuff that's submitted to Strata, the big data conference, I think, in your town.
- 24:06And the data he had was basically showing that people used to be doing things like R and to a large degree that's been replaced by IPython, NumPy, SciPy, Matplotlib, all those types of things.
- 24:17It's really amazing.
- 24:19So are you guys thinking of using some of those technologies?
- 24:21You said NumPy for sure.
- 24:23Yeah, definitely.
- 24:25As we start bringing on – like, at this stage, we're just collecting a lot of data, like, with our – like, our page views.
- 24:32But we are pretty comfortable that, like, it's a well-trodden path of putting – or, like, integrating NumPy or, like, Matplotlib into our data once we have someone who's, like, working full-time on data science.
- 24:47It's a language that I think, like, sort of has, like, broad appeal outside of engineering.
- 24:51And that's, I think, really important to us.
- 24:53And I think having the data science component there really is powerful for you guys.
- 24:58I mean, you've got all these people who are creators, and you've got all these patrons that are supporting them.
- 25:04And just helping those people align better will just help your business.
- 25:09And it sounds like big data type stuff would be perfect for that.
- 25:11Yeah, totally.
- 25:12Okay.
- 25:13So you're doing this port to Python on Flask and Python 3, and that's cool.
- 25:17When did you guys start on it?
- 25:18We started as of late November in 2014.
- 25:24Okay.
- 25:25So at the time of this recording, it's June 2nd, so that sounds about, like, seven, eight months?
- 25:30Yeah, that's right.
- 25:31The first thing that we did was just getting to the first page.
- 25:35I think in our porting process, we wanted to have, like, immediate deliverables and, like, immediately put Python in front of users as soon as possible.
- 25:46So in terms of, like, the project, we just picked one page, a fairly low-risk page, which is our slash-about page, and just made it our only one goal just to see how fast we could get that page rendering in Python to production.
- 26:01That's a really interesting way to do it.
- 26:02So you're kind of taking a vertical slice instead of trying to, like, horizontally going through it.
- 26:07So you can get some piece of functionality shipped straight away.
- 26:09It seems like that would help a lot with mitigating the risk of, like, will this port ever be done?
- 26:14When it goes live, will it ever work?
- 26:16Things like that, right?
- 26:18Yeah, that's totally right.
- 26:19We were really afraid that if we took a horizontal approach, like, we built all the infrastructure around the web framework, we built all the infrastructure around the models, built the infrastructure around controllers, that at some point we would have to just, like, flip a switch.
- 26:34And that was really scary because there's, like, a lot of risk that we can't necessarily detect with, like, just unit testing or integration testing.
- 26:42Sometimes we just want things to be as close to production as possible.
- 26:48And as close to production as possible is sometimes just production.
- 26:52Yes.
- 26:53That's pretty close to production.
- 26:55So you had a pretty interesting approach.
- 26:59So you started with the something simple, and you're like, let's get this whole thing out there.
- 27:04How did that go?
- 27:05You had to get the app written, which is not a really big deal.
- 27:09But then you had to do kind of DevOps, database stuff.
- 27:11What was the process?
- 27:13How smoothly did this go?
- 27:14Right.
- 27:15The complicated part here was getting our existing site, which is still running on PHP and Apache, to work well with the Python Flask infrastructure.
- 27:24And the way we handled that was in Apache, we used a proxy pass on particular routes.
- 27:30In this case, for the about page, we used proxy pass slash about to our Python backend.
- 27:38Okay.
- 27:38And so you could just sort of bypass your main app and send it straight over to whatever WSGI server you got running Flask, right?
- 27:44Yeah, that's right.
- 27:45We started up at an entirely different tier using Nginx, Gunicorn, Flask, but pointing to the same data sources.
- 27:53And we were able to flip a switch just on and off of whether or not we wanted a particular page to go to PHP or to Python.
- 28:01Wow, that's really cool.
- 28:02So I guess you just flipped that switch at the proxy pass level.
- 28:05And it was still living in the original PHP site.
- 28:09And then you started adding features to the Python version.
- 28:11And would you flip it on and off to see how it would flip it on for a little bit, see if it's okay, and then flip it back?
- 28:16What was that like?
- 28:19We tried to just flip it on and just keep it there.
- 28:22Although, you know, in terms of like mitigating risk, it is really comfortable to have, to know that you can always flip back and forth between a correct version and like the Python version.
- 28:33Having this, we also did a lot of things with having the separate architecture.
- 28:38And so one way we actually did testing was, and this isn't our comprehensive test, but we would open up the site in PHP.
- 28:45We'd open the site directly by bypassing Apache completely and going directly to our Python infrastructure and just like tabbing back and forth between the two.
- 28:54And it makes a lot of differences really obvious.
- 28:57Just kind of a visual diff, if you will, huh?
- 28:59Yeah, exactly.
- 29:00That's cool.
- 29:01So you went through a whole process of like choosing the next page and so on, and we talked a little bit about that before the show.
- 29:07Can you maybe talk about that?
- 29:08You start with the About page, and then where do you go from there?
- 29:11Yeah, so the discipline that we tried or like the process we tried to go by was to start with low traffic, low complexity pages.
- 29:22And this just let us make sure that our web framework was the way that we wanted it to be, that we wanted like, you know, we could register the correctness of the site without a lot of risk.
- 29:32And that was like what the About page was about.
- 29:34Right.
- 29:34That almost tests your infrastructure more than anything, right?
- 29:37That everything's hanging together.
- 29:38Yeah, exactly.
- 29:40Made sure our proxy password correctly.
- 29:42Made sure we did session handling correctly.
- 29:43We just wanted to start with like, you know, rigorously testing like one small thing at a time while we were rolling this out.
- 29:50Okay, so after About?
- 29:52So after About, like we, and we were comfortable with, you know, for example, like logged out and logged in traffic being correct.
- 29:59We started going and just porting to high traffic and low complexity pages.
- 30:03So the stuff like our index page is pretty low complexity.
- 30:07It's mostly just featured artists.
- 30:08Our featured page is also like featured creators in our search page.
- 30:12This let us make sure that our scalability was in order.
- 30:17The complexity of this page is like, we didn't have to write a lot of additional code to make those pages correct.
- 30:23But we did have to like make sure like we need, how many servers do we need in order to support a certain amount of traffic?
- 30:30How much do we need to like mirror the amount of performance that the PHP side was having in Python?
- 30:38So performance, that's an interesting question.
- 30:40Have you noticed a difference in performance?
- 30:42It's actually slightly faster in Python because we're doing certain things a lot more efficiently.
- 30:48like we have, you know, one entry point into our DB as opposed to doing like MySQL underscore, MySQL underscore query or like MySQL, like a lot of the MySQL underscore functions in PHP.
- 30:59That goes along with also cleaning up the code base.
- 31:03But like certain things with refact, like with making things correct in Python, just had the side effect to make things faster.
- 31:10Yeah, that's really interesting because it's a simpler language.
- 31:13You might not, it might be easier to write it correctly or more optimally.
- 31:18Yeah.
- 31:18One thing that we did run into was that because the default state of PHP is to just stream all the data as it comes out into standard, like from standard out directly to the client's browser.
- 31:30And so on the PHP pages, you would see like stuff coming in right away.
- 31:36With Python, we, we used Jinja2.
- 31:39And so like we needed an entire template to render before we sent it down to the user.
- 31:43So we had to do a little bit of a things to make the performance feel as fast in Python as it did in PHP, like using generators instead of like sending down like one large HTML block.
- 31:54That's really the problem you experienced with almost any of the template, HTML template style things, right?
- 31:59As you're not streaming directly to the browser, they execute and then send it down.
- 32:04It's, it's a perception thing, right?
- 32:06Like it feels slower, even if in the end, the same amount of stuff is on the page in the same time.
- 32:11Yeah.
- 32:12Like for example, our creation pages in PHP took six seconds to render, but you didn't feel it because you would still see the, like the embed.
- 32:23Or you would see like the becoming a patron flow right away.
- 32:27And it ended up like the slow part of the page was rendering the comments.
- 32:32And that was also do like number of inefficient things we were doing with the data fetches.
- 32:36But when we reported that straight up from PHP to Python, we just wouldn't see a page load for six seconds.
- 32:42And that's too long.
- 32:43That's definitely too long on the web.
- 32:45Yeah.
- 32:45And so we just like, we implement our own version of like lazy loading and like made sure the comments would come in after all the really relevant parts of the page came in.
- 32:55And we also made some like, I mean, after we got that first part through, we started making some efficiency, like, like optimizations with the performance.
- 33:03But we decided that like, you know, finishing the thing was first, like finishing the correctness of the, finishing the correct page was the first thing we'd go for and optimize the data calls later.
- 33:14Right.
- 33:16Okay.
- 33:16Maybe we come back to some of the optimizations, but I'm, one of the questions that's coming to mind is, are you guys done?
- 33:21so we are 98% of the way through and, that's not necessarily an ideal situation, but we're about halfway through the project.
- 33:32We realized that like we could actually start implementing new things on top of the base that we, produced.
- 33:38So after we implemented the user page, the creation page, and, a lot of the other sort of high, like one of the, some of the higher complexity pages with higher traffic, we had most of the models in place that we could start actually building new things.
- 33:52The first thing we implemented was a, a really simple, feature for migrating, sub-able users from sub-able onto Patreon.
- 34:02And we've been launching, we've been developing an API service layer for, the web client and the mobile app to be, to, to be unblocked and allow them to, they, reach some amount of progress.
- 34:15where we're stuck right now in terms of the Python port is the long tail of like really low traffic, but like sort of high complexity pages.
- 34:23So like stuff like, like the settings page or stuff like with, like patron manager.
- 34:28Yeah.
- 34:28Are there a bunch of like internal pages that you guys have that are complex dashboards that from the outside we don't really see, but have to be moved over eventually?
- 34:37Yeah.
- 34:37We have a lot of internal dashboards.
- 34:40A lot of them have like a varying complexity.
- 34:41those are lower priority because we wanted, you know, the production pages to be out first, but eventually those will need to be ported to Python as well.
- 34:49Yeah.
- 34:50So at some point you'll want to turn off the PHP site if possible and only manage one thing, right?
- 34:55Yeah.
- 34:56Our, like our number one dream, like with the Python port is to be able to completely delete the PHP repo entirely.
- 35:02And that just means like number one, like the PHP is not running in production, obviously.
- 35:07But secondly, it means that like the Python reference is what we're going with going forward.
- 35:13So you're already doing new features on top of Python.
- 35:15So it's, it's already serving you pretty well.
- 35:18One of the hard cells with doing a port is that while the port is going on, you can't do a lot of ongoing feature development.
- 35:26And the product itself will seem to stagnate for a while.
- 35:30And it has to be like sort of understood from like everyone that like, that's the way it has to happen.
- 35:35Like it can't do development in PHP and then like sort of backport that into Python later.
- 35:41It's going to slow down development of both, both systems.
- 35:44Yeah.
- 35:45And you guys came out, you said what, 2013?
- 35:47Yes.
- 35:48That's May, 2013.
- 35:49Yeah.
- 35:49And so if you're going to do this in 2014, you've got a year old product and you're saying, we're not going to change this for six months.
- 35:57That's kind of crazy in web time.
- 35:59So you had to do something, right?
- 36:01Yeah.
- 36:01It was kind of painful at like trying to sell that at first.
- 36:04But the idea is like we're going for long-term value and our long-term value depends on like engineering feeling like they're working with a language that makes them happy.
- 36:11Yeah.
- 36:13And that's, that's worth a lot, right?
- 36:14I mean, that means keeping the good developers.
- 36:16People are excited about their projects.
- 36:18Like it's, it's really a big deal.
- 36:20Probably easier to fix bugs as well.
- 36:23Yeah, definitely.
- 36:24We use an external service called Rovar that just like lets us identify like, well, any error that happens in production just immediately goes to that service and produces like a stack trace and like, you know, as much information as we can about the request and the headers.
- 36:40And it just lets us debug really quickly.
- 36:42What other infrastructure have you put in place?
- 36:45You guys have like automated tests and stuff like that?
- 36:47Yeah, we do the simple things like unit testing.
- 36:49We have a staging environment.
- 36:51We do some of the more creative things we do is like we have this concept of a walk test where for every page that we, or every route that we implement on the site, we just have a bunch of users of different profiles.
- 37:04Like we have a dummy patron account or a dummy creator account and just have them load the page.
- 37:10And that just makes sure that like the page loads with the 200.
- 37:13It's a really lightweight way of testing if like every code path or like every possible view, every possible viewer of a page will actually render.
- 37:24But it is like it's a really high leverage test.
- 37:27It's for the amount of effort.
- 37:29That's surprisingly effective because if something goes wrong, a lot of times it's a 500.
- 37:33Yeah, exactly.
- 37:34It ends up being about like 40 lines of code to actually implement that.
- 37:37But it catches a surprising amount of bugs.
- 37:39Yeah.
- 37:40You don't want people to see 500s on your site.
- 37:43That doesn't encourage confidence.
- 37:46The second thing that we did was we did this thing called dark moding, which was while the PHP service was still running or while the PHP website was still running, we would take all the requests for the Python pages that we were reporting.
- 38:00So like if we were reporting over the slash user page, we would record all the requests that were coming into slash user.
- 38:08And then we would just replay all of those, all that traffic onto a detached Python instance.
- 38:14And so before we flip the switch or before we flip the proxy pass from Apache to point slash user at the actual Python backend, we would sort of run dummy traffic through our Python code base with a read only database user.
- 38:29And just make sure that like no matter, like we would take real traffic and make sure at least that they all rendered.
- 38:36Wow.
- 38:37That's pretty cool.
- 38:37So another super lightweight way to do testing, but you just take all the traffic and you feed it over there.
- 38:44And again, it had better not return 500 and things like that.
- 38:47Right.
- 38:47Like these are the actual types of query string parameters we're seeing.
- 38:50These are the, you know, the route data that's coming in, that kind of stuff.
- 38:54Right.
- 38:54Yeah, exactly.
- 38:55Like this is the cookie.
- 38:56This is the logged in user.
- 38:57These are the headers.
- 38:58A lot of these things were like, we were able to leverage our existing system.
- 39:03And like, if we didn't have an existing user base, we would have had a harder time with that.
- 39:08But because we did have an actual live product, it gave us a lot of confidence that when we ship something live, that it would, you know, comfortably stand up to the traffic.
- 39:16Yeah.
- 39:17Nice.
- 39:18Did you have to do anything special for scaling to handle the load?
- 39:21Surprisingly, no.
- 39:23A lot of the scalability can be handled, or we found that scalability could be handled nowadays just by ups, like vertically scaling our MySQL instance.
- 39:34It was kind of a little bit disappointing to me because I really like performance tuning.
- 39:38But it actually, like we're on AWS and we're on using RDS for our database and it made things like extremely easy.
- 39:47Right.
- 39:47Right.
- 39:48And I haven't used RDS on Amazon too much, but that's relational database as a service, right?
- 39:54And so you can go over there and can you just turn a knob, just say, I need more database and you get it?
- 39:59Yeah.
- 39:59If you want to upgrade something from four cores, 16 cores, like basically one switch does it.
- 40:04Yeah.
- 40:06The cloud is awesome, isn't it?
- 40:07Yeah.
- 40:07Do you guys have it like geo-replicated anywhere or is it in one particular data center?
- 40:15We haven't replicated across availability zones, but not across regions right now.
- 40:20Sure.
- 40:20Okay.
- 40:21Makes sense.
- 40:21Are there any special techniques or things you've learned porting PHP to Python?
- 40:27Any tips and hard-earned things you can share with the listeners?
- 40:32Well, when it started out, we, so again, we didn't have a lot of Python experience or a lot of like deep Python experience within the company.
- 40:42So the first thing we had to do was sort of like, or the first thing like I did was try to get people really excited about Python.
- 40:48And when I started programming in Python, the thing that turned me on like the most to it was Peter Norvig's writing a spelling corrector in 21 lines.
- 40:59That, and I think like it was a really good sort of like intro to the advanced features of Python or what like sort of canonical Python looks like.
- 41:09Granted, there are a lot of tricks that like are also used in that that like aren't necessarily the most maintainable, but it's actually, it's a really cool demo.
- 41:16It's a really cool demo of the language and of like all the features.
- 41:20Yeah, that's really cool.
- 41:21And I'll put that in the show links, the norvig.com slash spelling dash corrector dot HTML.
- 41:26Yeah, I'll put that, I'll put that in the notes.
- 41:28In terms of like what tricks we use from porting from PHP to Python,
- 41:36Because people were still picking up Python as they were building out the different ported pages,
- 41:41we built out a lot of different things to sort of mimic the behavior of PHP in Python, but in a more correct way.
- 41:49So for example, like the context globals in Flask would mimic the sort of globals that you would see in PHP.
- 41:57Ternary operators, we just wrote a separate function that mimicked the structure of ternary operators in PHP,
- 42:04but using a function in Python.
- 42:06And like whatever we could do to like lower the cognitive load of going from PHP to Python,
- 42:12made things go like a lot simpler.
- 42:15Yeah, that makes sense.
- 42:16That seems like a really good idea.
- 42:18Did you do anything like PyFlakes or any of the sort of PEP 8 type checking tools to see how people are doing there?
- 42:27We use, pretty extensively, we use PyCharm inside the company that does the PEP 8 checking for us.
- 42:33And it's actually, I usually did development, I mean, I've usually done development on just like Vim or Emacs,
- 42:39but I actually really like PyCharm.
- 42:42I think it does a pretty good job of things that it wouldn't have caught with a normal text editor.
- 42:47I can't agree more.
- 42:49I use PyCharm all the time.
- 42:52I love PyCharm.
- 42:53And I used to use Emacs, but it's all about PyCharm for me these days.
- 42:58You know, if it takes an extra second to load, there's a whole lot more goodness on the other side of that, right?
- 43:02Yeah, it really saves a lot of time.
- 43:04Yeah, you know, if it saves you one bug a week, it's probably saved you an immense amount of time.
- 43:09We're actually going to have the PyCharm guys on the show here pretty soon, so excited about that as well.
- 43:13Really cool.
- 43:14Yeah, they're doing good work, and they have a free version.
- 43:17I don't know if everyone knows, but they've got like a community version and a pro version.
- 43:22It's pretty affordable, that thing.
- 43:23The pro version is definitely worth it.
- 43:25Yeah, it's definitely worth it.
- 43:26But if you're not convinced, you know, the free version is hard to say, well, I can't try that.
- 43:30It's too expensive.
- 43:31Nice.
- 43:32So overall, you feel like you've made a good choice?
- 43:36Looking back, you've got eight months of experience.
- 43:39You've got a running site.
- 43:40You've had to live with the thing for a while.
- 43:41What are your thoughts?
- 43:42Yeah, I think one thing that I do wish is that the site were 100% ported right now.
- 43:50It would make certain aspects of the operations in architecture much simpler.
- 43:56But I'm not unhappy, like I'm actually pretty happy with the place that the port is in right now.
- 44:01I think the number one thing is always going to be developer happiness.
- 44:04Like if our developers are happy, then that just makes things a lot easier.
- 44:09Yeah, I think you're totally right.
- 44:11It's very hard to undervalue enthusiasm.
- 44:14Being excited about something can really affect the way that you work when you're doing creative things like programming.
- 44:22And think just like small things like onboarding new users onto Python or new engineers onto Python.
- 44:27It's much easier because it's a much more consistent language.
- 44:31PHP has a bunch of really small quirks that are increasingly becoming very specialized knowledge.
- 44:37A lot of inconsistencies with the standard library.
- 44:40And very small things are easy to learn, but all these sort of active cognitive load of onboarding to a new language.
- 44:47And Python has been much, much better with that, especially with Python 3.
- 44:50Yeah, Python 3 feels pretty cleaned up.
- 44:52I think that makes a lot of sense.
- 44:54All right, Albert, I think that might cover it.
- 44:57Anything else you want to add on this whole adventure you've been on?
- 45:01Not much.
- 45:03I think we pretty well covered it.
- 45:06So, you know, I'm sure there's a lot of people out there with PHP sites that have considered moving to Python.
- 45:12And I'm sure this conversation will be helpful.
- 45:14Yes.
- 45:16I want to reiterate, of course, it was a very, very serious choice for us.
- 45:19We spent a lot of time, like, thinking about it.
- 45:22But, like, once we made the decision, or, like, once we decided that that was the right place to go, we just got started right away.
- 45:29Were people pretty excited once you kind of decided to do it and start going?
- 45:33I think there was a lot of burnout from PHP, and I think there's a lot of excitement around Python.
- 45:37So, yes, definitely.
- 45:38Yeah, very, very cool.
- 45:39All right, before I let you out of here, there's a couple of questions, one of which you've actually answered already, that I always ask my guests at the end.
- 45:47One is, what's your favorite PyPI package or sort of thing out there that you want to tell people, like, hey, you should go check out X?
- 45:54I'll have to think about that.
- 45:59Like, I don't want to say requests, because I think that's a pretty difficult answer.
- 46:05Request is pretty amazing.
- 46:07I learned from the show with Kenneth Reitz that requests have been downloaded 40 million times.
- 46:12I mean, that's unbelievable to me.
- 46:14Yeah.
- 46:15Oh, I think for us, RoeVar has been, like, amazingly good and, like, amazingly easy to set up.
- 46:21Okay, awesome.
- 46:22And RoeVar, that's R-O-V-A-R.
- 46:24R-O-L-L-B-A-R.
- 46:27And it's, like, I think this is probably the startup that has, like, only a few people working on it, somewhere and so on.
- 46:33But, like, it just, like, saved us so much time in having to, like, build out a sort of error-detecting infrastructure.
- 46:39Excellent.
- 46:39And it's just always watching, always got your back, which seems like a really powerful thing when you're doing a port like this.
- 46:47And you're just probably a little nervous all the time in the beginning.
- 46:52Yeah.
- 46:53It's, like, very, very comprehensive and that, like, you know, maybe a bit noisy, but, like, really gives us a lot of confidence.
- 46:59Yeah.
- 46:59That's fantastic.
- 47:00The other question I always ask is, what's your favorite editor?
- 47:03But we already had our PyCharm conversation.
- 47:05Yeah, definitely PyCharm.
- 47:07I, like, highly recommend.
- 47:07Yeah.
- 47:08So, I definitely recommend people go and check out Patreon.
- 47:12Albert, you guys have done a fantastic job.
- 47:15And if you're out there creating any sort of thing that has short, multiple release cycles, like, even if you're doing an open source package, it seems like that's something you could create a Patreon campaign about and put up there.
- 47:27If people want to support it, they can sort of, hey, every time you ship a new version, you know, here's five bucks or something.
- 47:32Yeah.
- 47:33We have people supporting creators that do anything from, you know, making YouTube videos to making Dwarf Fortress.
- 47:39And so, like, we welcome any creator who wants to use us.
- 47:41That's great.
- 47:42Yeah, it's been a great experience for me, and I definitely recommend.
- 47:45If this is the type of thing that would help with your project, then definitely check them out at Patreon.com.
- 47:50Albert, thanks for being on the show.
- 47:53It's been great, man.
- 47:54Yeah, thank you.
- 47:55Yeah, bye.
- 47:56This has been another episode of Talk Python To Me.
- 48:00Today's guest was Albert Hsu, and this episode has been sponsored by CodeChip and Hired.
- 48:04Thank you guys for supporting the show.
- 48:06Check out CodeChip at CodeChip.com and thank them on Twitter via at CodeChip.
- 48:12Don't forget the discount code for listeners.
- 48:14It's easy.
- 48:15Talk Python.
- 48:16All caps, no spaces.
- 48:17Hired wants to help you find your next big thing.
- 48:20Visit Hired.com slash Talk Python To Me and get five or more offers with salary and equity right up front
- 48:26and a special listener signing bonus of $4,000.
- 48:30Also, don't forget, awesome t-shirts await you at bit.ly slash Python shirt or just visit the website and click on shirt in the footer.
- 48:39You can find the links from the show at Talk Python To Me.com slash episodes slash show slash 14.
- 48:45And be sure to subscribe to the show.
- 48:48Open your favorite podcatcher and search for Python.
- 48:51We should be right at the top.
- 48:53You can also find the iTunes and direct RSS link feeds in the footer of the website.
- 48:57This is your host, Michael Kennedy.
- 49:00Thanks for listening.
- 49:01Smix, take us out of here.
- 49:03Stating with my voice.
- 49:05There's no norm that I can feel within.
- 49:07Haven't been sleeping.
- 49:08I've been using lots of rest.
- 49:10I'll pass the mic back to who rocked it best.
- 49:12First, develop, first, develop, first, develop, first.
- 49:16First developers, developers, developers, developers.
- 49:21developers, developers, developers, developers, developers.
- 49:25you