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