Latest / Talk Python To Me / #352: Running Python in Production
Transcript
- 0:00Do we talk about running Python in production enough?
- 0:02I can tell you the Talk Python infrastructure, courses, podcasts, APIs, and so on get a fair
- 0:08amount of traffic, but they look nothing like what Google or Instagram or insert big tech
- 0:13name here's deployments look like.
- 0:15Yet, mostly, we hear about interesting feats of engineering at massive scale that, while
- 0:20impressive, often is outside the world of most Python devs.
- 0:25On this episode, we have three great guests who do think we should talk more about small
- 0:29to medium-sized Python deployments.
- 0:31Emily Morehouse, Hennick, and Glyph.
- 0:34I think you'll enjoy the conversation.
- 0:35They each bring their own interesting perspectives.
- 0:38This is Talk Python To Me, episode 352, recorded January 12, 2022.
- 0:44Welcome to Talk Python To Me, a weekly podcast on Python.
- 1:01This is your host, Michael Kennedy.
- 1:03Follow me on Twitter, where I'm @mkennedy, and keep up with the show and listen to past
- 1:07episodes at talkpython.fm.
- 1:09And follow the show on Twitter via at Talk Python.
- 1:12We've started streaming most of our episodes live on YouTube.
- 1:16Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified about upcoming
- 1:21shows and be part of that episode.
- 1:23This episode is brought to you by SignalWire and Tonic.ai.
- 1:27Please check out what they're offering during their segments.
- 1:30It really helps support the show.
- 1:31Emily, Hennick, Glyph, welcome to Talk Python To Me.
- 1:35It's so good to have you here on the show.
- 1:38And I'm super excited about talking about running Python in production.
- 1:42And I'm glad that it's more than just one of you, because I think everyone has their own
- 1:47perspective and their own context and whatnot.
- 1:50You know, do you work for a small company or a large company or do you have many people on
- 1:55the team or just a couple, right?
- 1:57And I think that really influences what you might cover, some of the decisions you might
- 2:01make and so on.
- 2:02But before we get to that, let's just start off with a little bit of background.
- 2:06Emily, it's been a while since you've been on the show.
- 2:08Maybe, you know, tell people a bit about yourself.
- 2:10Yep.
- 2:11So I'm Emily Morehouse.
- 2:12I am the director of engineering at Cuddlesox.
- 2:14We are a digital product development company.
- 2:18So we kind of touch on anything from web, mobile, IoT, DevOps.
- 2:23We really touch the whole stack and get to work with a lot of different industries.
- 2:28And then I also am a Python core developer and the PyCon chair for this year.
- 2:33Yeah.
- 2:33You just happened to grab that role right when, you know, COVID hit and conferences got insanely
- 2:41complicated and uncertain.
- 2:43How did you juggle all that?
- 2:45It was a really big bummer.
- 2:46I think because PyCon is really such an important piece of our community and getting to see people
- 2:52in person and connect on a regular basis.
- 2:54But of course, we wanted to do the thing that was going to keep everyone the most safe.
- 2:59So kind of last minute going online and then doing a full online conference and then still
- 3:04hoping that things will settle down this year so that in person is something that feels very
- 3:09safe for us to do.
- 3:10But I was grateful.
- 3:11I actually wound up staying on for this third year as chair just so I could have that sort
- 3:15of like last hurrah of hopefully getting to be in person.
- 3:18Yeah.
- 3:19Yeah.
- 3:19Yeah.
- 3:20I hope so.
- 3:21Awesome.
- 3:21Well, thanks for all your hard work on it, even if we didn't get a meet in Pittsburgh.
- 3:24Glyph, you want to go next?
- 3:26I'm Glyph.
- 3:26I am probably best known for Twisted.
- 3:29I've worked on a variety of production Python environments in my career.
- 3:33I am currently in the process of exploring some options for something independent, all
- 3:40of which are secret and I can't really say anything about here yet.
- 3:44Most recently of Pilot.com.
- 3:46They are a fantastic company and I very much recommend people work there.
- 3:50And we also ran a ton of Python in production over there.
- 3:53I'm sure that folks in the Python podcasting space have probably heard me occasionally before,
- 3:58so I won't belabor my introduction.
- 4:00Yeah.
- 4:00Sounds good.
- 4:01Well, good to have you here again.
- 4:02Henrik, welcome.
- 4:03Welcome.
- 4:03Yes.
- 4:04Thank you for having me.
- 4:05I think more or less my first Python podcast in my life.
- 4:09Well, it's awesome to have you.
- 4:10You do so much writing and you have such an influence on through like conferences and presentations.
- 4:16You should definitely be here.
- 4:18So it's long overdue.
- 4:20Welcome.
- 4:20It's great to hear because I don't think about it like myself.
- 4:23But so I'm Henrik.
- 4:24I work for a small web hosting company.
- 4:27We are like a traditional web hoster.
- 4:29I've been working there for now like 14 years, which is a very long time, which is like a thousand
- 4:33years in Silicon Valley time, I think.
- 4:35Everything I do, I do in Python basically there.
- 4:38Like from web services to simple web pages over proxies, applications, you name it.
- 4:45We use Python for it.
- 4:46Oh, fantastic.
- 4:46Do you like control VMs and provision VMs and stuff and that kind of thing?
- 4:51Or what type of work are you doing?
- 4:53We are more on the, no, we don't sell VMs.
- 4:57We don't sell anything where you can have root on it.
- 5:00So we're selling a platform basically.
- 5:02Like mostly PHP.
- 5:03Like it is what it is.
- 5:06Yeah, sure.
- 5:06At least you can control it all in Python.
- 5:08Yeah.
- 5:09Well, fantastic.
- 5:10And so the reason we're all here today actually is it's your fault, Henrik.
- 5:13So you wrote this article back about a year ago.
- 5:18Yeah, check the date.
- 5:19Yeah, I know.
- 5:20We've been talking about getting the four of us together for a while, haven't we?
- 5:24It's been a bit of a journey.
- 5:26So we didn't mean for it to be that long, but I don't think there's anything that is dated
- 5:31about this.
- 5:32So it's totally fine.
- 5:33What I meant is that it was like right before Corona.
- 5:36Like when I was, I was writing this article on my phone while listening to a podcast in
- 5:42a van going to a husky farm in Finland.
- 5:45A husky farm like the dogs?
- 5:48Yeah.
- 5:48Yeah.
- 5:48I did a husky safari basically.
- 5:50Like riding husky sleds, mushing.
- 5:52Yeah.
- 5:53Oh, that sounds interesting.
- 5:55It was.
- 5:55It was my last trip before Corona.
- 5:57So, which makes it kind of funny because I talk about conferences later on, which, yeah.
- 6:02Yeah.
- 6:03That kind of got put on hold, but well, we can replace it with things like this and other
- 6:08conversations.
- 6:09So in this article, you talked about the title is Python in production.
- 6:13Of course, we'll link to it in the show notes.
- 6:15And you said you were missing a key part from the public Python discourse and would like to
- 6:19help change that.
- 6:20Basically, we should have more conversations about running in productions.
- 6:24So let me see if I get this right.
- 6:26You're a huge proponent of microservices.
- 6:28Everything should just be a bunch of small microservices and everyone else is doing it
- 6:32wrong.
- 6:32I'm just kidding.
- 6:33You actually don't take a different view than that.
- 6:36But we're going to go through, you know, sort of some of the themes in your article, some
- 6:41of the other ones out there.
- 6:42And then also just all of us talk about sort of what we're doing in production, some of the
- 6:47considerations and trade-offs.
- 6:48So a lot of fun there.
- 6:50Let's talk about cloud computing first.
- 6:53I'll pick one of these out of here and then we can touch on the whole microservice monolith
- 6:58thing as well.
- 6:59You know, Glyph, I'll just pick you.
- 7:01We have this trade-off, right?
- 7:03We could go and create a VM, set up our own system, and it's totally portable.
- 7:07It could run in a data center.
- 7:08It could run in the cloud or whatever.
- 7:10Or we could go all in with Lambda and other, you know, very specialized services tied to AWS
- 7:16or to Azure or whatever.
- 7:19What are your thoughts on this whole running in the cloud story?
- 7:21There's as many dimensions to that question as there are services in AWS, which is to
- 7:28say like a higher order than ALF null infinity.
- 7:31The way that I look at that question is you have to look at each service kind of one at
- 7:37a time.
- 7:37And the way that I would generally suggest people decide whether or not it's a good idea to adopt
- 7:42a particular service has to do with the way that their operational footprint works in terms
- 7:49of overhead.
- 7:50So for example, should you run your own Postgres or should you use RDS?
- 7:56Almost always you should just use RDS because the operational footprint of that is Amazon configures
- 8:03and manages the tremendous complexity of operating a relational data store in production.
- 8:08And when you need to set that up for development, because like part of production is having a
- 8:14development environment that matches closely enough that it works well and that you can test
- 8:19things and know for sure that you're getting like adequate test coverage is you can just run a
- 8:25Postgres Docker container.
- 8:26And functionally for your infrastructure, it's probably the same.
- 8:29You rarely need to do like deep configuration that is like meaningful to your application
- 8:35between your local development Postgres container and your RDS instance.
- 8:39As that slider moves further and further towards like, well, actually our data store configuration
- 8:44is really part of our application.
- 8:46Well, actually we need to like tune things very closely.
- 8:49Even running your own data store might make sense.
- 8:51That's a pretty unusual circumstance, but that you can look at that for other
- 8:56aspects of your platform as well.
- 8:58Routing, like load balancing, caching.
- 9:01Is that part of your app?
- 9:03Do you care about it in development?
- 9:04If it breaks in an interesting way, is that going to like take you down?
- 9:09And look at each of those issues for each cloud service.
- 9:13How much, how expensive is it going to be for you to replicate it in development?
- 9:16And how accurate is that reflection going to be of what's in production?
- 9:20And always try to pick the answer that is the lowest overhead for your particular team
- 9:25configuration.
- 9:26That said, the tricky part is this changes as your team grows.
- 9:32Right.
- 9:33And as your service gets more complex.
- 9:35One of the things that I imagine I'm going to touch on a few times is that probably the
- 9:39most interesting Python in production experience I had was running pilot.com's application, which
- 9:44started in a very different place than it ended up.
- 9:47And I'm very happy with the way that that went.
- 9:49But we started in an incredibly like super macro service, just one big Python container
- 9:55and like nothing else towards picking up application load balancers and lambdas and all kinds of
- 10:04other stuff that eventually became part of that infrastructure as the team grew.
- 10:08We had more of a dedicated infrastructure, like operational footprint that we could actually
- 10:12manage because it was staffed.
- 10:13Yeah, that makes a lot of sense.
- 10:14It definitely changes as your team changes.
- 10:17Emily, what do you think?
- 10:18What's your view on this?
- 10:19How much of the cloud should you bite off?
- 10:21And where's the trade-offs?
- 10:23I agree with a lot of the things that Gliff said.
- 10:25I think that once you get to the point where you're adding complexity to your local development
- 10:30environment, that's usually a red flag for me.
- 10:32And you have to be doing something that gives you a lot of value.
- 10:36So for example, we'll use like Firestore as an offline database for mobile applications.
- 10:42And whether you're using that or you're using CouchDB, whatever choice you're making there,
- 10:48you're going to have some sort of added complexity locally.
- 10:51So yeah, I totally agree with like RDS is a really easy swap.
- 10:54And if it's RDS on AWS or moving to GCP or Peroku or whatnot, your portability between
- 11:03those different ecosystems is going to be pretty straightforward.
- 11:05But if you want to rewrite your Lambda functions to use Cloud Run instead, like it's not just a
- 11:13drag and drop sort of thing.
- 11:14Right.
- 11:15You don't just change a connection string and now it's all good again.
- 11:18Yeah.
- 11:19And I think it's going to depend on, you know, like where the company is at.
- 11:23Again, for us, like we're often looking at what our client needs.
- 11:28So if they're a client that doesn't have a technical team that they just kind of want to
- 11:32like let this run on its own and they don't want to manage it, like that's going to impact
- 11:36whether we choose Heroku or AWS.
- 11:38So like really looking at where you're at now and what sort of support you need in the future
- 11:43is a big question to ask for that decision.
- 11:46Which way does that gauge go for you if they are kind of hands-off and not super technical?
- 11:51Do you give them Heroku or what do you give them?
- 11:53Yep.
- 11:53If they're non-technical, we give them Heroku.
- 11:55If they are technical, even then that kind of depends.
- 11:59A lot of times it's AWS or GCP, just kind of depending on what other pieces of the ecosystem
- 12:04that they need.
- 12:05Or since we work with a lot of existing tech companies, a lot of times they say,
- 12:08hey, we are a GCP company or an AWS company.
- 12:12And then we just say, cool, we can do either.
- 12:14Right.
- 12:14And if they're already there, you might as well just keep going with that, right?
- 12:17Yeah, definitely.
- 12:18Yeah, absolutely.
- 12:19But I will say that like 95% of the time, anything that's like web application or API based,
- 12:26it's going to be in a Docker container anyway, just to give us that portability.
- 12:30Sure.
- 12:30Hynek, thoughts?
- 12:31I have very, very little first-hand experience with cloud services because we use none.
- 12:37It would be kind of odd for a cloud hosting company to use somebody else's cloud.
- 12:41Although I know that people are doing it.
- 12:43It totally happens.
- 12:44People are more or less reselling the big cloud.
- 12:47That's true.
- 12:47Yeah.
- 12:48Wrapper.
- 12:48Yeah.
- 12:49We run our own hardware in own cages in a shared data center, like military grade.
- 12:55I once almost got tasered because I took a photo from the outside.
- 12:59Security came running immediately.
- 13:01So the one thing we run outside is Sentry because that makes sense.
- 13:08And I didn't want to run it anymore myself.
- 13:10But there's also the thing that Europeans in general and Germans in particular are not very
- 13:16excited when you put their data on other people's servers, particularly of US companies.
- 13:22So often it is also like a competitive advantage for us to just say our data literally does not leave Berlin.
- 13:29Right.
- 13:30That's certainly something that here in the US, it's easy to kind of forget about.
- 13:36Right.
- 13:36Oh, these just the thing of, oh, it's just the big clouds.
- 13:38Right.
- 13:38These are big cloud companies.
- 13:39But really, those are US cloud companies.
- 13:42Right.
- 13:42And if you're in Europe or somewhere else, that's another angle to think about.
- 13:46Right.
- 13:46I have maybe one thing to add as a user.
- 13:49That as a user, I don't care that US East 1 is down.
- 13:53But you will know.
- 13:57You'll still know.
- 13:57Yeah.
- 13:57This is what I see happening.
- 13:59Right.
- 13:59Again, people rely too much on cloud services.
- 14:01that half of the internet is down when some of that many people are not talking about.
- 14:06Yeah, for sure.
- 14:07So maybe we can wrap this up real quick.
- 14:10But I do want to add just one thing.
- 14:12A roller out there in the audience says, I prefer my $5 DigitalOcean VM and just my Nginx,
- 14:17MongoDB, Postgres, Python.
- 14:19So how often do you think about, you know, especially, I guess, you, Emily, how often do you think about
- 14:25price?
- 14:26You know, if you look at the price for AWS, it can add up.
- 14:30And for some companies, that doesn't matter.
- 14:31Right.
- 14:32Just having infrastructure is great.
- 14:34But for others, you know, maybe they don't have revenue yet or they're not profitable and
- 14:39they're really trying to squeeze by.
- 14:41Like, where do you land on like, let's save you some money.
- 14:44We could do this for $10, but we're going to do it for $500 because it's the right architecture
- 14:49to run this distributed thing.
- 14:50You know, what are your thoughts?
- 14:52What do you tell your customers?
- 14:53Sure.
- 14:54The cost benefit often comes down to picking an ecosystem that's going to be super stable.
- 15:00for them where we can say, hey, yeah, this is going to cost you a few hundred dollars
- 15:03a month.
- 15:04But if you need somebody to step in and start to manage your system for you, you know, a
- 15:11couple of developer hours will easily outshine their cost for their cloud hosting.
- 15:16So that kind of puts it in perspective.
- 15:18A lot of these clients are already people who have spent multiple thousands, you know,
- 15:23tens to hundreds of thousands of dollars actually building their software in the first place.
- 15:27So as long as you're, you know, on a much lower order of magnitude, you're typically okay.
- 15:32Yeah, that's true.
- 15:33If you, especially if you're not technical and you've got to hire someone in to kind of
- 15:37fix it, then yeah.
- 15:39Then any sort of failure is a big problem.
- 15:41This portion of Talk Python To Me is brought to you by SignalWire.
- 15:46Let's kick this off with a question.
- 15:47Do you need to add multi-party video calls to your website or app?
- 15:51I'm talking about live video conference rooms that host 500 active participants, run in the
- 15:56browser and work within your existing stack and even support 1080p without devouring the
- 16:01bandwidth and CPU on your user's devices.
- 16:04SignalWire offers the APIs, the SDKs and edge networks around the world for building the
- 16:08realest of real-time voice and video communication apps with less than 50 milliseconds of latency.
- 16:14Their core products use WebSockets to deliver 300% lower latency than APIs built on REST,
- 16:20making them ideal for apps where every millisecond of responsiveness makes a difference.
- 16:25Now, you may wonder how they get 500 active participants in a browser-based app.
- 16:29Most current approaches use a limited but more economical approach called SFU or selective
- 16:34forwarding units, which leaves the work of mixing and decoding all those video and audio
- 16:38streams of every participant to each user's device.
- 16:41Browser-based apps built on SFU struggle to support more than 20 interactive participants.
- 16:47So SignalWire mixes all the video and audio feeds on the server and distributes a single unified
- 16:52stream back to every participant.
- 16:53So you can build things like live streaming fitness studios where instructors demonstrate
- 16:58every move from multiple angles.
- 17:00Or even live shopping apps that highlight the charisma of the presenter and the charisma of
- 17:05the products they're pitching at the same time.
- 17:06SignalWire comes from the team behind FreeSwitch, the open-source telecom infrastructure toolkit
- 17:12used by Amazon, Zoom, and tens of thousands of more to build mass-scale telecom products.
- 17:17So sign up for your free account at talkpython.fm/signalwire.
- 17:22And be sure to mention Talk Python To Me to receive an extra 5,000 video minutes.
- 17:26That's talkpython.fm/signalwire.
- 17:29And mention Talk Python To Me for all those credits.
- 17:32One thing that I'd love to add on to that is, well, two things.
- 17:35First of all, on the notion of price and sort of related to which technologies you should use,
- 17:42I think the question you constantly need to be asking is really never ask about one side of
- 17:47the equation.
- 17:48Never ask about features or price.
- 17:50You always want to be looking at a price-performance ratio.
- 17:54And that performance shouldn't necessarily, in fact, usually should not be like metrics like gigabytes
- 17:59or throughput or anything like that.
- 18:02You should be looking at, do you need what the product offers?
- 18:06And what is it going to save you time on?
- 18:08So like when Emily says, if it's going to save you development time, that is gold.
- 18:12You always want to go err on the side of saving development time.
- 18:16Developers are very expensive.
- 18:17We're very finicky.
- 18:18And anything that you develop, you also need to maintain.
- 18:21So one of the big benefits of cloud services is think of that price, not just in terms
- 18:25of like development cost, but are you going to need to maintain it?
- 18:28And on the flip side, do you need this thing at all?
- 18:31Quite like Hinnick was talking about having, you know, just not using cloud at all.
- 18:36And yet he successfully develops and deploys many services in production and they all seem
- 18:41fine.
- 18:42And so I think that there's often kind of this tool obsession where we look at features,
- 18:47features, features, and assume that features equals benefits.
- 18:49But features are only benefits to you if you need them.
- 18:52If you don't need them, they're additional costs.
- 18:54You have to learn stuff about every single one of those features.
- 18:58The time your developers spend learning the surface of the AWS API is a cost you have to
- 19:04think about.
- 19:04And so like, it's quite often just better to not use the cloud because it's cheaper to
- 19:09not figure it all out.
- 19:10If you know how expensive it's going to be in your own infrastructure.
- 19:14Or as Emily pointed out, if it's in a Docker container, you may run it in the cloud now,
- 19:18but it's fairly portable and not super tied to it.
- 19:21Paul Everitt out in the audience has a quick question.
- 19:24He says, we talk about pinning dependencies to control change.
- 19:27But when we talk about cloud computing, we say let things like AWS handle it.
- 19:31You know, you're sort of, that's kind of a dependency on their compatibility of each one
- 19:35of those services you take on.
- 19:37What do you think about, you know, stability of those APIs and those services over time?
- 19:42I think Azure maybe is a little more changing than AWS.
- 19:46Things come and go, but still it's something to consider, right?
- 19:49It's another thing you've got to deal with churn on, I guess.
- 19:51Yeah.
- 19:52And I think it depends on like how quickly you're jumping on new services.
- 19:56So we actually started using ECS right after it was released and it's come a long way since
- 20:01then.
- 20:02And both like the product and our perficiency has come a long way.
- 20:05So I think that taking any sort of like new service with a heavy dose of skepticism and
- 20:10making sure that it's something that is really stable, that's going to fulfill the need.
- 20:15It's an important thing to look at.
- 20:17Yeah.
- 20:17That's a really good point.
- 20:18All right.
- 20:18Let's move on.
- 20:18We touched on this enough.
- 20:20I think let's talk about microservices.
- 20:22I was joking with Hennick about that at the beginning.
- 20:26So we have this spectrum.
- 20:28We can have just one code base, one process that runs in uWSGI or Gunicorn or whatever,
- 20:34where we could have a little Lask API that does user management and login, another part
- 20:40that does, you know, the catalog or whatever.
- 20:43We could have a bunch of these little services, these microservices, and then put them all
- 20:47together.
- 20:47I have thoughts on this, but where are your thoughts?
- 20:50My opinion at this point is, I think, quite public.
- 20:53I think you should start with a monolith first for this simple reason that microservices come
- 21:00with a lot of adjacent complexity.
- 21:02We basically just talked about with cloud services, right?
- 21:05Like you cannot have microservices without service discovery.
- 21:09You cannot have microservices without tracing because every error becomes like a, I thought
- 21:14it's once called a distributed murder mystery.
- 21:17When you're trying to find the fault of it, there are things that people don't think about, like retries need to be kept.
- 21:27Otherwise, you're going to get exponential growth and you denial service yourself and stuff like that.
- 21:34So, I mean, it's a general good idea to have as few moving parts as possible, which already someone said about cloud computing.
- 21:42And because more moving parts are always harder to make reliable, right?
- 21:46And Martin Foller calls it the microservice premium, which I like.
- 21:50And it's again, it's a trade-off.
- 21:52Is this premium worth it to you?
- 21:55And I think you need a lot more experience to make this trade-off than many people think.
- 22:02That's my experience.
- 22:03Yeah.
- 22:04You probably start simple and then with just two or three pieces and then you end up with 20 and you're like, well, how do we get here?
- 22:10Yeah.
- 22:10Yeah.
- 22:11And they don't really know why, right?
- 22:12Like if people want boundaries, like I cannot speak for huge teams because one of the peculiarities of my job is that our team is very small with a lot of responsibility.
- 22:20But there are big teams that have boundaries that do not come with a network partition.
- 22:25So, yeah, it's a trade-off.
- 22:27And I think that most people need more experience to actually make this trade-off.
- 22:31Yeah, I would, I very much agree with that.
- 22:34particularly the people who tend to be asking this question are often asking it because they're at a small company.
- 22:42They have a small team.
- 22:43They saw a really cool white paper or a presentation by somebody at Google or Netflix.
- 22:48And they're like, wow, all this stuff about microservices sounds great.
- 22:52Fault isolation and distributed tracing and, you know, use whatever language you want.
- 22:58And I'll get back to that one in a second.
- 23:00And again, like I said before, you will need to think about everything in terms of cost benefit and not just benefit.
- 23:07And the folks at Google and Netflix are talking about 10,000 person teams and like, how do you manage complexity at that scale?
- 23:16How do you deal with the problems that come with that type of organization?
- 23:20And so asking like, I also, even the shape of this debate has long bothered me because the terms that we're using, right?
- 23:28Do we want monoliths or microservices?
- 23:32Asking that question is like saying, well, when we have a wheel, do we want it to be like an 18-wheeler, like truck wheel?
- 23:40Or do we want it to be like one of those wheels that comes on like a micromachines car?
- 23:43And the answer is, I don't know.
- 23:46Like, what are you putting on the vehicle that this wheel is going to be attached to?
- 23:49Like, it really depends.
- 23:51The question of like, how big do you want your service to be?
- 23:54Which is, I think, a better question than do you want a microservice or a monolith?
- 23:57It comes down to what is the surface area to volume ratio of your team?
- 24:02It takes about 12 people to run a microservice, I would say.
- 24:06Like a dozen people per service is roughly what you should be thinking about.
- 24:10Plus, there's the fixed overhead of a microservice architecture where you need service discovery and tracing and logging and like a whole bunch of other stuff,
- 24:18which you probably need in today's modern fancy cloud environment if you're going to be able to leverage services like Honeycomb and CloudWatch and like just manage all your logs and not have to deal with that yourself.
- 24:29Then you're talking about maybe a six-person team that can just do infra.
- 24:34And if you are at a three-person startup and thinking, huh, that sounds like a lot of people, you want a monolith.
- 24:41You want one piece of code you can maintain because the benefit of having something like a very fine-grained microservice architecture is that you can say, we're going to have each team own its little piece.
- 24:54And we're going to move a lot of the complexity of orchestrating from code to configuration because our operations team can like deal with the configuration and manage their process around testing configurations.
- 25:07But if you're a small development team, you want code you can write unit tests for.
- 25:11You want code you can run and understand the way that you run and understand everything else.
- 25:16And if you push everything into YAML files and INI files and cloud APIs, what does your development environment look like anymore?
- 25:22How do you test those changes?
- 25:24Right. Even developing on your own machine becomes tricky.
- 25:26Yeah, exactly. Yeah.
- 25:28Yeah. I think the big takeaway is that the team needs to match what microservices are optimized for.
- 25:33Yeah, exactly.
- 25:34That's a really good point.
- 25:35Emily, I suspect the people you suggest use Heroku probably are not receiving 10 microservices over there, are they?
- 25:42No, definitely not.
- 25:44I think one of the things that we typically have built in is a certain amount of ability to scale independently.
- 25:50And so we typically do have two different workers on Heroku.
- 25:53So we're going to have, you know, a Django application and a Celery task worker.
- 25:58And then we know that we can kind of scale those two independently.
- 26:00But that's where we really see the division of load.
- 26:05So that's my lens that I look at monolith versus microservices with is really, do I need to scale them independently?
- 26:14Yeah. And I certainly think having some kind of, we're going to kick off the long running work over there.
- 26:19So it's not happening as part of a web request.
- 26:21That certainly makes sense.
- 26:23Even things just like sending a group of people an email often takes too long if the group is large enough before the request will time out and wreck your servers and all sorts of stuff.
- 26:32So yeah, it makes sense.
- 26:33But I think developer experience is a really big one.
- 26:35We have had the pleasure of working with another like very large tech company, like multiple hundreds of employees, and they had a monolithic Rails app.
- 26:46And it was absolute hell to work with as a developer because you're constantly like having hundreds of PRs open at a time.
- 26:53You open a PR and within 20 minutes, you have a merge conflict with somebody else.
- 26:57And you really, at that point, it makes sense from a developer perspective too, to be able to divide it up and say, okay, like, this is your area of expertise.
- 27:06This is your area of expertise.
- 27:07And at least set up those partitions.
- 27:09But you can do that in a monolith as well.
- 27:12It just takes a little bit of like awareness and slice in the problem a little differently.
- 27:16Yeah.
- 27:17So let me think of a, let me throw out an idea that I just thought of that I'm not sure I'm advocating this or even that it is a good idea.
- 27:26But one of the problems you have is sort of you have this big monoliths, like you were touching on, Emily, is a lot of people are changing the same bits of code and they're kind of in all over the place.
- 27:35So the microservices is one way to solve that problem.
- 27:38What about trying to think about, you know, could we package up some of the functionality of what our application does or our area into Python packages that we can then install and use in the main app?
- 27:51That idea?
- 27:51Good idea?
- 27:52I mean, it's interesting, but it's also another level of complexity, right?
- 27:55Yeah.
- 27:55Yeah.
- 27:56You got to run your own private server or something.
- 27:58I would actually say that that is a prerequisite to microservices.
- 28:03Specifically, one of the things that people often forget about the whole service architecture thing, and this comes down to the future.
- 28:10Remember, I said I was going to talk about choose your own language kind of thinking before.
- 28:14One of the things that people often choose microservice architecture for badly is this idea that they want to experiment with different programming languages because they want to use the right tool for the right job.
- 28:25And number one, just the cognitive overhead of jumping between Haskell and OCaml and Python and Rust on your back end is way, way higher than most people think.
- 28:35But even forgetting about the sort of human cognitive overhead, your service architecture, your service fabric needs to be logging and recording metrics and dealing with load balancers and dealing with data stores in a consistent way.
- 28:47And that task by itself is complex enough that you probably need a library, which means every supported language in your environment needs to have packages installed that are maintained by your infrastructure team and not by your application teams.
- 29:00And that means before you can even think about microservices, you have to be able to split your workflow into multiple different package repositories, different source control, different teams, different CI.
- 29:12Like you need to be able to do that first before you can reasonably split things across like multiple actual services.
- 29:19That doesn't necessarily mean you need to like not have a quote unquote monolith because you can put a monorepo into that kind of multiple package, multiple library workflow.
- 29:29And that's also fine, but you do need to be able to have multiple work streams going that end up in the same service package.
- 29:37This portion of Talk Python To Me is brought to you by Tonic.ai.
- 29:40Creating quality test data for developers is a complex, never-ending chore that eats in the valuable engineering resources.
- 29:48Random data doesn't do it.
- 29:50And production data is not safe or legal for developers to use.
- 29:54What if you could mimic your entire production database to create a realistic dataset with zero sensitive data?
- 30:00Tonic.ai does exactly that.
- 30:04With Tonic, you can generate fake data that looks, acts, and behaves like production data because it's made from production data.
- 30:11Using their universal data connectors and a flexible API, Tonic integrates seamlessly into your existing pipelines
- 30:18and allows you to shape and size your data to scale, realism, and degree of privacy that you need.
- 30:24Their platform offers advanced subsetting, secure de-identification, and ML-driven data synthesis
- 30:31to create targeted test data for all your pre-production environments.
- 30:36Your newly mimicked datasets are safe to share with developers, QA, data scientists, and, heck, even distributed teams around the world.
- 30:44Shorten development cycles, eliminate the need for cumbersome data pipeline work,
- 30:48and mathematically guarantee the privacy of your data with Tonic.ai.
- 30:53Check out their service right now at talkpython.fm/tonic or just click the link in your podcast player's show notes.
- 31:00Be sure to use our link, talkpython.fm/tonic, so they know you heard about them from us.
- 31:08Another thing is versioning across the services, right?
- 31:10The definition, like if you're using SQLAlchemy, the user shape has to match all the parts that talk to the database that might touch a user object or something like that.
- 31:19So I guess I'll wrap it up with a quick thought that for me, microservices feel like I'm trading code and developer complexity for operational and DevOps complexity.
- 31:29And I personally feel much more comfortable managing and working with code complexity than like infrastructure complexity.
- 31:36But if your team and your organization is all about managing infrastructure complexity and DevOps, and you have a bunch of junior devs, maybe microservices make sense.
- 31:45I don't know.
- 31:45It kind of depends.
- 31:46But my vote's for the monolith side because I'd rather manage the software complexity.
- 31:50Let's talk about security.
- 31:52I mean, we've had some crazy stuff.
- 31:55I think it's log4jmeme.
- 31:58There's a .com.
- 31:59I think that is a .com.
- 32:01Yeah.
- 32:01So like security is clearly on the, it's something we always have to think about, but something, right, that recently log4j obviously being a Java, not Python thing.
- 32:11But it's the one thing that makes me nervous about running stuff in production.
- 32:15Honestly, we've got stuff like StatusCake or various other things that you can fire up or uptime or whatever that will tell you if your site is down and send you notifications and things like that.
- 32:27But the security one is a little bit scary.
- 32:29So how do you approach thinking about this?
- 32:32You know, Henrik, maybe you go first hosting other people's code is like a next level is like meta security.
- 32:38Yeah.
- 32:38The one flag I want to wave here is defense in depth, which is something that's very dear to my heart and which I feel is, yeah, which could be a bit more popular.
- 32:48Sure.
- 32:48Because every significant attack nowadays is a multi-stage one.
- 32:52It doesn't matter if it's like owning your Chrome or owning a server.
- 32:56It's usually multiple stages.
- 32:58So you shouldn't make it as hard as possible to the attackers, even though they have entered your infrastructure at this point.
- 33:07So for me, it means that I treat our own network, which is very private.
- 33:11You need a VPN to get in and everything as if it has intruders inside it.
- 33:15And that's our standard.
- 33:16So you should hash your passwords as the maintainer of Argon2CFFI, of course, using Argon2, but use whatever.
- 33:24We use TLS even in private networks, because I know that cloud providers have virtual LANs, which are also often encrypted.
- 33:32But still, it's just another layer.
- 33:34You cannot have enough layers to protect yourself at this point, because if someone intrudes you, you don't want them to sniff passwords out of your traffic and things like that.
- 33:43The list goes on.
- 33:44Yeah, it definitely does.
- 33:45Emily, security thoughts?
- 33:47Yeah, luckily, this isn't one that we've necessarily had to worry too much about.
- 33:51I think the worst thing that's happened for us is DDoS attack, and that's about it.
- 33:55So for me, I think definitely staying on top of dependency management, keeping things up to date, which is not necessarily always the easiest thing.
- 34:04Especially the Python 2.3 transition, upgrading Django is sometimes a little bit more complex than you'd want it to be.
- 34:11But I think that getting those security updates and making sure that you're on an LTS version is really important.
- 34:16LTS being long-term support.
- 34:18Yeah, absolutely.
- 34:18Yeah.
- 34:19So one of the things that I think, you know, I made the, I was picking on the log4j thing.
- 34:24But one of the problems that made this a little bit harder, I mean, this is going to be something we live with for a long time.
- 34:30It's going to be a nightmare.
- 34:31But the consequences of it.
- 34:33But one of the problems was that the fixed version of log4j, which for those who didn't know, the log4j problem is if you can basically get a server to print a message with any of your input, like this URL was invalid, or this email tried to log in and failed, you can own the computer.
- 34:54Which is really, really bad.
- 34:55So it has to be fixed, like straight away.
- 34:57But the problem was, the fixed version was on a newer version, like Java 8.
- 35:02So if you were running Java 7, you had to both not just upgrade your library, but then upgrade your whole runtime, which might be problematic.
- 35:09So Emily, that makes me think that, you know, you probably, one of the good rules to go by is don't let your frameworks get too far out of date.
- 35:18Like you don't have to be on the latest Django, but don't stay on Django 1 when Django 4 is about to be released.
- 35:24Or don't stay on Python 3.6 when you could be on the newer one or something like that.
- 35:31How do you all feel about that?
- 35:32Yeah, and I think that, like looking at it from an open source maintainer's perspectives, making sure that you have the ability to kind of hotfix previous versions and be very clear about which versions you're supporting and which ones you're not.
- 35:45That way, you make it easy for a user to know, like, yeah, I'm not going to get the security update and I need to upgrade and have that done ahead of time to stay on top of things.
- 35:55Yeah.
- 35:55And AgraGliff, old frameworks, what do you think?
- 35:57I think that this is a, I don't think I can find this right away, but I remember one of my more popular tweets was one of those sort of two buttons memes where the guy can't choose.
- 36:07And on one side, you've got get owned because your dependencies are out of date and you have no way to immediately update them or get owned because you're automatically updating from an upstream that you don't know if you can trust or not.
- 36:18And that's kind of, so the way that I sort of split that difference in practice is you really want to make sure that it's not just about like regularly upgrading because you can always say like, oh yeah, we'll regularly upgrade.
- 36:35But you've only got a fixed budget for security, right?
- 36:38Like it's possible to spend all of your time spinning your wheels trying to increase the cost for attackers across every possible access.
- 36:44I'm sorry, access.
- 36:46Yeah.
- 36:46But eventually you got to ship features and deliver stuff.
- 36:48Like that's really.
- 36:49Exactly.
- 36:50It's a balance.
- 36:51Yeah.
- 36:51Thinking about Hinnick's suggestion of defense in depth, the way that I like to think about that is you want to raise the bar to a certain minimal level in a bunch of different areas.
- 36:58And then not get too obsessed with getting that last 5% of security on each possible access.
- 37:05So for dependencies, the way that I think about that is have the, you know, very widely available automation that already does this stuff like depend a bot.
- 37:14Make sure you are getting those PRs automatically pin everything so that you're never dealing with a library upgrade in the middle of future development.
- 37:24Your library upgrade work should always be, I am upgrading this library now.
- 37:28And 90% of the time, if you have that set up where you've got a build that is running on every PR that builds your whole dependency structure, that's got everything pinned and hashes pinned and everything.
- 37:41And then is also regularly receiving these PR updates.
- 37:45Most attackers who are doing things with supply chain attacks aren't all that clever.
- 37:49And so they will just end up trying to pop your CI and you'll see that you'll get some kind of error.
- 37:55You'll probably notice.
- 37:57Not necessarily attackers can be very sophisticated, but like you want to have everything, every library running in your nicely isolated CI environment on your GitHub actions or whatever first.
- 38:11And again, you want that those changes to all be like same code with the old dependencies, same code with new dependency.
- 38:17And every so often you'll get one very expensive upgrade that you really got to do and you got to make time for.
- 38:22If you're not upgrading all the super easy, almost free, like just hit the green button on the PR that's working.
- 38:30If you're not doing that all the time, then when you do get to those big upgrades, you will be upgrading 50 dependencies at a time.
- 38:37Yeah, it's going to be rough.
- 38:37Yeah.
- 38:38You really need to think about the cost to you as the defender.
- 38:41And the way that you reduce that cost on dependency upgrades is spending just a little bit of time every week, tending that automation and looking for those upgrades that are really going to take some development work.
- 38:52And there are fewer than you might think, like quite often feels like a really big task because most people get stuck in this, oh no, it's time to do the dependency upgrades this quarter.
- 39:02And you have like a seven week project that you're like trying to figure out which dependency is the one that's making all your tests fail.
- 39:08And you're like changing 50 lines in your requirements.txt all at once.
- 39:11If you don't do that, and by the time you're upgrading the one library that really does have a big breaking API change, it's not actually that hard as long as everything else is already up to date.
- 39:21Yeah.
- 39:22And usually there's one or two libraries that are massive, like Gingo or Flask.
- 39:26And then it's all the little dependencies that probably require no effort on your part.
- 39:30One other thing that I switched to, you talked about Dependabot, which is really great.
- 39:36And I have Dependabot turned on for my stuff, but I started using pip compile where it'll go and basically you give it an in file and it'll build your requirements.txt.
- 39:46And it'll even say like, this thing is here because it depends.
- 39:50You know, you installed Flask.
- 39:51That's why it's dangerous is here, for example.
- 39:53And I really like having that because it's just, you know, this week I'll go and I'll run it and it'll tell me what the new requirements are.
- 40:00I'm actively knowing that's happening.
- 40:02I'll sort of process it and go with it.
- 40:04What do you all think?
- 40:05Emily, are you using Dependabot or something else?
- 40:08Yeah, we do use Dependabot.
- 40:09I think another interesting like integral piece of being able to upgrade your dependencies is having tests that give you the confidence that you can.
- 40:17So do you feel confident to say, yes, our upgraded dependencies passed our test suite, therefore we can upgrade?
- 40:24Or is there something that is going to require somebody else to go in and look at it?
- 40:27But yeah, I think we've come a really long way in terms of dependency management.
- 40:31I do not miss the giant requirements.txt files that had all the dependencies of dependencies of dependencies all the way down and you didn't know what you would install versus another library.
- 40:42Yeah, exactly.
- 40:42I also like things like pip compile because it lets you have a little bit more control over the child dependencies versus relying on a top level library like Django to specify their own requirements in a way that works for your organization.
- 40:59Yeah, absolutely.
- 40:59So I also use Dependabot, like I said, and if you go and run pip-tools and then you commit that back to the repo, Dependabot will notice that that's been upgraded and it will automatically close the PR.
- 41:10So there's kind of a nice match between them as well.
- 41:13Yeah, the answers to all these questions are really are so much simpler than they used to be, you know, five, six years ago.
- 41:19I've been using requires.io for probably almost a decade and Dependabot is much better, largely because it defaults just sending you those individual upgrades and you can really tune how much stuff it's going to try to do at once.
- 41:34So yeah, mostly the answer on this is like, make something that builds your Docker container or whatever your fully realized application artifact is, run it all the time and have part of that process be like, freeze your dependencies, pin everything.
- 41:48You need to make sure that everything is pinned so that you get very reliable, repeatable builds.
- 41:51But having done that, you can really just bask in the, you know, cornucopia of tools that we have available to do this now that make it all pretty easy.
- 42:00Yeah, it's definitely getting easier and easier.
- 42:02Let's talk about performance a little bit.
- 42:03I guess maybe I'll show just really quickly, I'll throw out there that at sneak.io, S-N-Y-K.io, they've got some stuff where you can put in like a package or something like that.
- 42:14Let's see.
- 42:15I don't remember where you go to do it, but you can basically put in like a Python package.
- 42:19It'll give you a security report for it.
- 42:20So that's, I don't know how accurate that turns out to be for everything, but it's something.
- 42:25But let's talk about performance.
- 42:26And one thing I'd like to touch on is.
- 42:28Actually, can we just say one more thing about security before we move on?
- 42:31Yeah, go for it.
- 42:32Because Hennick mentioned encryption and not trusting your local network at the beginning.
- 42:35And one other thing I wanted to mention, speaking of tools that are much better than they used to be.
- 42:39One popular idiom is to like have a production mode that has all your encryption on and a development mode where you like just turn it all off for convenience.
- 42:50And I'm a big fan of setting up like an entry in your hosts file for each developer and having some infrastructure for provisioning certificates for individual developer machines.
- 43:00So that encryption is just always on.
- 43:02So that encryption is just always on.
- 43:02Nobody ever makes a connection without TLS on it.
- 43:05Even your like local API stubs still have some kind of TLS on them.
- 43:10Because it's actually not all that hard, particularly with Let's Encrypt.
- 43:13You get a couple of DNS plugins and you can easily vend those certificates to your dev team.
- 43:17It takes a couple of days of work at most.
- 43:19And having done that, not only are you more secure because you just don't even have that switch anymore to like accidentally be sending everything in plain text.
- 43:29But also you spot a surprising number of configuration issues.
- 43:32And like you get to see how your like for real certificates work while you're doing development.
- 43:38And that can really help a lot of developers like understand what's going on with the somewhat tricky world of HTTPS.
- 43:45So it's just running a little bit closer to production.
- 43:48Yeah.
- 43:48All right.
- 43:48Let's talk about performance.
- 43:49And I'll just put this up on the screen because I think it's a fun thing.
- 43:52Have you all seen Locus.io?
- 43:54Yeah, we use it regularly for load testing.
- 43:56Do you?
- 43:57Yeah.
- 43:57Maybe tell people about it real quick.
- 43:59I've used it once or twice and it's fantastic.
- 44:01Yeah, definitely.
- 44:01So it's a tool that allows you to essentially write a script that will emulate requests to your server.
- 44:08And then you can give it a variety of, wow, mom brain with no sleep makes me forget words.
- 44:14But basically just like different parameters that you can specify.
- 44:17So it makes it really easy to say like, here is the approximate randomized behavior for a single user.
- 44:24And then scale it up to hundreds or thousands of users and see how your server handles it.
- 44:29Right.
- 44:29You give it a Python script, which is really interesting, right?
- 44:32You create a class and you say, here's a typical user of this type.
- 44:35And it does different things like it'll call the index page.
- 44:39It'll call the about page.
- 44:40It'll go do a search.
- 44:41And you can say things like, there's going to be a certain amount of delay between pages.
- 44:46And then you can, as you said, scale that up.
- 44:49Say like, I want 2,700 regular users and 50 admin users and let them go crawl around on the site and do what they do.
- 44:57Right.
- 44:58Yeah.
- 44:58So it's super cool.
- 44:59And the, like the real, a real time dashboard is neat.
- 45:02So if you want to know about your performance, you could use this, but you know, how do you all think about performance for the apps, either you're running or delivering, you know, what's fast enough?
- 45:12What's just wasting your time, getting that last millisecond of response time?
- 45:16So I'm going to make this the bold statement that for the vast majority of developers, Python is fast enough.
- 45:23Oh yeah, absolutely.
- 45:25It is fast enough to saturate a database.
- 45:27And once your database is saturated, you have different problems.
- 45:30Like there's definitely things for what it is, where it is a problem.
- 45:34Like you cannot saturate an LDAP server, for example.
- 45:37I know that because I tried and it's one of our Go services.
- 45:40It would be nice if Python could be faster.
- 45:43And I'm very excited about Guido's performance task force at Microsoft.
- 45:47It's great.
- 45:48Yeah.
- 45:48I feel like the indifference that the no-jill movement has been shown kind of shows that nobody really thinks that intensively about it anymore.
- 45:58Like for most people, it's fine.
- 46:00It's not good.
- 46:01It's not great.
- 46:02It's fine.
- 46:03And I mean, Instagram is printing money with it.
- 46:05So they absolutely are.
- 46:08Yeah.
- 46:09You know, you can go and put your site into PageSpeed Insights and see what you get.
- 46:14And I think once you get down to several millisecond response time per page, it just, you know, there's not a whole lot you can do to make it faster.
- 46:24There's not a lot of benefit to doing that work, right?
- 46:27It's mostly tuning a database with the right indexes and caching.
- 46:31That's the two things.
- 46:32Yeah.
- 46:32And everything else is like the last 10% or something.
- 46:35Yeah, absolutely.
- 46:36So what I wanted to definitely emphasize here and hear your thoughts.
- 46:39I feel like there's so many times I go to some page and it doesn't necessarily, some site doesn't necessarily have to be Python.
- 46:45It's just some database backed page.
- 46:47And you go there and it's sitting on what seems like one of their primary pages.
- 46:51And it's like five seconds until it responds or several seconds even.
- 46:55It's like, what is this thing doing?
- 46:58And I just, I know they don't have indexes in their database.
- 47:01They just, they can't.
- 47:02So, you know, I just want to put out a plea for please use like some database profiling feature.
- 47:09Please look at your queries and please put an index.
- 47:12It's so incredibly easy.
- 47:14Like any of you all want to rant on that with me?
- 47:16I need to bring up one tool before we talk about this.
- 47:19And it's called PG mustard.
- 47:21Okay.
- 47:21I've never been able to fully understand an explained statement.
- 47:25Like I learned it many times and then I forgot it again.
- 47:28And PG mustard is amazing.
- 47:30You just take an explain.
- 47:32You copy paste it into a web app and it tells you exactly what's going wrong.
- 47:36Oh, nice.
- 47:37And I've shaved, like I had like one query, which is like very big.
- 47:40It's from a financial system.
- 47:41And I've, I think like 66% of the query at runtime, I was able to shave off.
- 47:46Yeah.
- 47:46Just because there was an index, but it was set up wrong.
- 47:49It was amazing.
- 47:50Yeah.
- 47:51So here's a really beautiful visual thing.
- 47:53And it's also a bit of like a profiler.
- 47:55So it says on this part of the query statement, you spent 0.4% of the time.
- 48:00And this part you spent 58% of the time, right?
- 48:03Here's an index scan.
- 48:04That's the best part.
- 48:05It doesn't just tell you what's going wrong, but do this, make this index.
- 48:10Things like that.
- 48:11Okay.
- 48:11I've never seen this before.
- 48:13This is fantastic.
- 48:14Emily, thoughts on indexes?
- 48:15Join my plea.
- 48:16Yeah.
- 48:18So I think that that piece of it's definitely very important.
- 48:21Like making sure that you're doing those sort of basic things to get you to that, you
- 48:25know, 80 to 90% performance potential.
- 48:27But I would also argue that these days in a vast majority of applications, you're going
- 48:33to have a decoupled front end from your back end.
- 48:35And I would argue that making sure that you're implementing best practices for user experience
- 48:41on your front end is going to give you so much more payoff than trying to optimize that
- 48:46API call by, you know, a few milliseconds.
- 48:49So previously I had pulled up the PageSpeed Insights before, right?
- 48:54And at PageSpeed.web.dev from Google, I believe.
- 48:58Yeah.
- 48:59And what's really interesting about that is if you go and put your site into there,
- 49:04it doesn't feel fantastic to do it, by the way.
- 49:06So if you go and you put your site in here, you at some point might get a good number.
- 49:11I'm getting 100 out of 100 on the TalkByThan training site right now.
- 49:14But that's because I spent three days addressing every little thing.
- 49:19Like this image is not sized right.
- 49:21This JavaScript is not bundled with that JavaScript.
- 49:24This element is being resized by the browser.
- 49:26You should make it the same size by default.
- 49:29And just all of these little things.
- 49:31And it wasn't even about the server response time, which was always pretty low.
- 49:36It's about all the other stuff.
- 49:38It's like, how does it feel to the user to get to the page rather than what is the, you
- 49:43know, HTML out of the server response time?
- 49:46And that's what you're talking about, right?
- 49:48That kind of stuff?
- 49:48Yep.
- 49:49Yeah.
- 49:49Yeah, definitely.
- 49:50Awesome.
- 49:50All right.
- 49:51So I have so many feelings about this.
- 49:54This is probably the number two topic for me behind packaging.
- 49:57Okay.
- 49:58Those of you not listening on the live stream, if this next part sounds choppy, it's because
- 50:02I talked for an hour and a half and Michael had to edit it down.
- 50:05We just cut him off.
- 50:07We just had to cut him off when he lost his voice.
- 50:10But seriously, the thing that I think is most important is the, quite often the parts of
- 50:15your application that end up being the performance issues are once you're past this step.
- 50:22Now there are lots of like, you all have been mostly talking about websites, except for Hennek
- 50:26mentioning LDAP, which is an interesting.
- 50:28I've never really thought about scaling that one.
- 50:30No.
- 50:31I have also scaled LDAP.
- 50:33So the two major applications that I've dealt with performance issues on are an internal
- 50:38calendaring service that I maintained at a large company that you can figure out which
- 50:42one it is by reading my Wikipedia page and pilot.com's internal bookkeeping automations.
- 50:48And in both of those, so number one, the calendar service was an API with no front end.
- 50:54The front end was maintained by the client teams that were not even doing web stuff.
- 50:59And the way that we had to performance test that involved standing up our own custom load
- 51:05generation tool and running it as kind of a qualification process for our deployments.
- 51:10And the reason that I bring up that one is it's interesting because we had to figure out
- 51:15what our actual interesting load patterns were.
- 51:17We couldn't use any of these like standard HTTP load generation things because we needed very
- 51:22specific data.
- 51:23And that often ends up being the problem that you're facing.
- 51:27We, on that service in particular, we had performance problems that arose because we
- 51:32added too many indexes.
- 51:34So we were having problems on the right side of the equation.
- 51:37Every time you add an index, you're optimizing read at the expense of write.
- 51:42And usually it's like a lot of read performance for a little write performance, but eventually
- 51:47it does add up.
- 51:48It does.
- 51:49Yeah.
- 51:49Kivo out in the audience says, yeah, you've got to be careful adding too many indexes as
- 51:54well.
- 51:54There's two parts to that, right?
- 51:56One part is when you write something, the indexes have to be computed for that thing that's going
- 52:01in.
- 52:01And the other is more indexes mean more stuff in memory.
- 52:04And so like another really important aspect is do your, does the totality of your indexes
- 52:09reside in memory or does it have to get paged out?
- 52:12Right.
- 52:12And so you would, you would hit that problem.
- 52:14Both of those problems you would run into by having too many indexes.
- 52:17Right.
- 52:17And you really need to, so you need to be ready to measure things because you don't necessarily
- 52:23know.
- 52:24Like, I mean, this is that, you know, chestnut about not really, you know, premature optimization,
- 52:28not knowing what the hotspots are until you run them.
- 52:30But that also means, so there's two things about that.
- 52:32One, the tools for doing this are not great.
- 52:35Like the one that I really wish were good and just isn't is SpeedCenter, which Twisted and
- 52:41PyPy used to monitor their performance over time.
- 52:43Like what the performance of each revision of the code is.
- 52:46And there's nothing like, you know, GitHub Actions or Travis CI, there's no sort of leader
- 52:51in that field that will just tell you like, hey, your performance regressed by 10% on this
- 52:56commit.
- 52:57And that is the tool which I desperately want to exist.
- 53:00And so most of the things that I do are trying to approximate that.
- 53:03Part of that is making sure you have metrics in production that are telling you so that you
- 53:07notice when things are slow.
- 53:09You don't want to be having users telling you, or even really like if you're getting the bad
- 53:14performance metrics out of your load testing tool, and that's a surprise to you, that means
- 53:18you're probably not instrumenting enough in prod to know like, oh, users are seeing some
- 53:23slowness here.
- 53:23Because you're also going to get things where like your database is doing great.
- 53:26Everything seems like it's super fast, but your queries are actually really slow.
- 53:30They're just all running in memory.
- 53:31And then you hit the cliff where suddenly you're hitting the disk.
- 53:34And now everything's much, much slower.
- 53:36And none of your code changed.
- 53:38And your data only grew by like 10%.
- 53:40And being able to spot stuff like that means you have to be looking at perf in prod.
- 53:45You can't do synthetic tests for everything.
- 53:48And particularly if you have a large site with a lot of users, it's very easy to miss if your
- 53:5395th percentile is falling off a cliff, right?
- 53:56Like you have to be looking at your core tiles and like all of these different things, not just
- 54:02like average performance.
- 54:03And the second part of that is the custom data generation for your synthetic tests.
- 54:08So for example, on the calendar service had those issues that I just mentioned.
- 54:12And pilot service had this issue where most of the performance stuff was not the database.
- 54:18It was talking to APIs to pull in financial transactions and analyze them.
- 54:23And it was those APIs being slow, us being silly and not talking to those APIs in parallel,
- 54:29data volumes just being huge, like thousands and thousands and thousands of transactions
- 54:33in a single call.
- 54:35And that you have to know that that's going to happen.
- 54:38And you have to be able to on demand add to your test suite or your performance test suite
- 54:44new types of data.
- 54:46And that performance tool with where you like write Python code looks like a great way to
- 54:51do that.
- 54:51I actually had never used that one.
- 54:52This thing is glorious.
- 54:53Yeah.
- 54:54What was it?
- 54:55Locust.io?
- 54:55Yeah.
- 54:56Yeah.
- 54:56And it has the dynamic sort of graphs and dashboards show you sort of as it ramps up
- 55:01and as you change it.
- 55:01And it's, I think that might give you like the right, because you basically structure with
- 55:06Python how it hammers on the server, which is pretty neat.
- 55:09Yeah.
- 55:09And the one thing I'd say about that was you need to do that.
- 55:12You will need to write custom stuff.
- 55:14Don't just assume you can like add a couple indexes.
- 55:16Like you should just add a couple indexes at first if performance is not your primary concern.
- 55:21But having done that, you have to know you're going to need to think about perf and like
- 55:26write code to monitor it.
- 55:28Absolutely.
- 55:28All right.
- 55:29I think we're just about out of time, although we have barely scratched the surface of all
- 55:33the stuff we could talk about.
- 55:35Let's close out with this question.
- 55:36Do any of you have, sounds like maybe you've thought about this.
- 55:41You have CI performance checks or failures or anything like that, right?
- 55:47Like we have run our tests.
- 55:49The build doesn't pass if the tests don't pass.
- 55:51But do you have something like that for performance?
- 55:53That's the thing I want to exist.
- 55:54And I've never managed.
- 55:56I've done things that approximate it within tests, but never gotten it really.
- 56:00I have nothing like that either.
- 56:02Emily?
- 56:02No, I mean, I think the closest approximation that we get is we focus a lot on like Cypress
- 56:08tests for front end.
- 56:09So actually the user going through and working with the application.
- 56:12And I think the closest thing that we could get at this point is just setting our max time
- 56:17out in our like HTTP service, bumping that down and saying like, if anything's taking over
- 56:2310 seconds to respond when we run the tests, then it should fail.
- 56:26But no, I don't think we don't do any like regular performance testing.
- 56:31Yeah.
- 56:31Hynek?
- 56:32We do not know.
- 56:32Yeah.
- 56:33But we all kind of are like, that was kind of nice to have, I think.
- 56:36But yeah.
- 56:36There's a lot to set it up though, right?
- 56:38You've got to have enough data in the database for it to be meaningful.
- 56:40And that's tricky to do in CI.
- 56:42And it would be cool though.
- 56:43I think Glowth makes a really good point that like the load testing and the manual testing
- 56:48of performance is great, especially when it's a prerequisite to launch.
- 56:51But there's no way that you're going to be able to replicate anything in production.
- 56:55And the best thing that you can do is monitor prod as closely as you can.
- 56:59Yeah, absolutely.
- 57:00Some of that real-time monitoring.
- 57:01Fantastic.
- 57:02All right.
- 57:02Well, thank you all for being here.
- 57:04This has been super interesting to chat about.
- 57:06Before you got out of here, let me, I think I'll just put it down to one of the final
- 57:10two questions so that we don't take too long.
- 57:12But you're going to write some Python code, what editor to use?
- 57:15Let's go.
- 57:15Blockwise, Hynek, how about you?
- 57:17What are you writing code with these days?
- 57:18Well, I have a long story of editors.
- 57:20I've used almost all of them at some point.
- 57:22I usually stopped using because I got crippled, like Emix Pinky.
- 57:26Nowadays, I usually use either Vim in a console or VS Code.
- 57:31Okay.
- 57:31Right on.
- 57:32Cliff?
- 57:32There's an implicit thing in this question where it sounds like you're recommending the
- 57:36thing that you use.
- 57:37So I want to be clear that I'm not doing that.
- 57:39Don't do as I do.
- 57:41Yeah.
- 57:42I use Emix, but with about 10 megabytes of custom Elisp, which I'm never going to share
- 57:48with anyone.
- 57:49Fantastic.
- 57:49Because you shouldn't use it.
- 57:50Just use VS Code.
- 57:51Awesome.
- 57:52Emily?
- 57:52VS Code.
- 57:53All day.
- 57:54Okay.
- 57:54Big thanks to Brett Cannon, who sat me down at a Python and forced me to use it because
- 57:59the first time I used it, I hated it and I went back to Sublime.
- 58:02But yeah, I don't think there's anything that competes these days.
- 58:05Yeah.
- 58:05He's such a good ambassador for that.
- 58:06So it's good to have him working on it.
- 58:08All right.
- 58:09Thank you all for being on the podcast.
- 58:10It's been great to chat about the stuff and really insightful to get your experience.
- 58:15Thanks so much for having us.
- 58:16Awesome.
- 58:16Thanks for having us.
- 58:17Yeah.
- 58:17You bet.
- 58:17Bye.
- 58:17Bye.
- 58:17Bye.
- 58:19This has been another episode of Talk Python To Me.
- 58:22Thank you to our sponsors.
- 58:24Be sure to check out what they're offering.
- 58:25It really helps support the show.
- 58:27Add high-performance, multi-party video calls to any app or website with SignalWire.
- 58:32Visit talkpython.fm/SignalWire and mention that you came from Talk Python To Me to get started
- 58:38and grab those free credits.
- 58:39Tonic.ai creates quality test data that does not contain personally identifiable information.
- 58:47Your generated data sets are safe to share with developers, UA, and data scientists.
- 58:51Most importantly, they behave like production because they're made from production data.
- 58:56Check them out at talkpython.fm/tonic.
- 59:00Want to level up your Python?
- 59:02We have one of the largest catalogs of Python video courses over at Talk Python.
- 59:06Our content ranges from true beginners to deeply advanced topics like memory and async.
- 59:12And best of all, there's not a subscription in sight.
- 59:15Check it out for yourself at training.talkpython.fm.
- 59:17Be sure to subscribe to the show.
- 59:19Open your favorite podcast app and search for Python.
- 59:22We should be right at the top.
- 59:23You can also find the iTunes feed at /itunes, the Google Play feed at /play,
- 59:28and the direct RSS feed at /rss on talkpython.fm.
- 59:32We're live streaming most of our recordings these days.
- 59:36If you want to be part of the show and have your comments featured on the air,
- 59:40be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 59:44This is your host, Michael Kennedy.
- 59:46Thanks so much for listening.
- 59:47I really appreciate it.
- 59:48Now get out there and write some Python code.
- 59:50Bye.
- 59:51Bye.
- 59:51Bye.
- 59:51Bye.
- 59:51Bye.
- 59:52Bye.
- 59:53Bye.
- 59:54Bye.
- 59:55Bye.
- 59:55Bye.
- 59:56Bye.
- 59:57Bye.
- 59:57Bye.
- 59:57Bye.
- 59:57Bye.
- 59:57Bye.
- 59:57Bye.
- 59:58Bye.
- 59:59Bye.
- 59:59Bye.
- 59:59Bye.
- 1:00:00Bye.
- 1:00:01Bye.
- 1:00:01Bye.
- 1:00:01Bye.
- 1:00:01Bye.
- 1:00:02Bye.
- 1:00:02Bye.
- 1:00:03Bye.
- 1:00:03Bye.
- 1:00:04Bye.
- 1:00:05Bye.
- 1:00:05Bye.
- 1:00:05Bye.
- 1:00:06Bye.
- 1:00:07you
- 1:00:07you
- 1:00:08you
- 1:00:08Thank you.
- 1:00:10Thank you.