Learn Python with Talk Python's 270 hours of courses

Running Python in Production

Episode #352, published Tue, Feb 8, 2022, recorded Wed, Jan 12, 2022

Do we talk about running Python in production enough? I can tell you that the Talk Python infrastructure (courses, podcasts, APIs, etc.) get a fair amount of traffic, but they look nothing like what Google, or Instagram, or insert [BIG TECH NAME] here's deployments do. Yet, mostly, we hear about interesting feats of engineering at massive scale that is impressive but often is also outside of the world most Python devs need for their companies and services.

I have three great guests who do think we should talk more about small to medium-sized Python deployments: Emily Moorehouse, Hynek, and Glyph.

I think you'll enjoy the conversation. They each bring their own interesting perspectives.

Watch this episode on YouTube
Play on YouTube
Watch the live stream version

Episode Deep Dive

Guests introduction and background

Emily Morehouse is Director of Engineering at a digital product development company called Cuddlesocks. She’s also a Python core developer and was PyCon chair for multiple years (including the challenging COVID era). Emily works with diverse web, mobile, and IoT projects, touching everything from the front-end to DevOps.

Glyph is best known for creating and maintaining the Twisted network framework. He has worked on various production-grade Python deployments, most recently at Pilot.com. Glyph emphasizes thoughtful design of systems and is passionate about stability and reliability in Python.

Hynek has 14+ years of experience at a web hosting company based in Germany. He uses Python extensively for automating, securing, and scaling their platform. Hynek is also the maintainer of Argon2 CFFI for password hashing. He highlights topics around security, encryption, and hands-on Python production strategies.

What to Know If You're New to Python

If you’re just getting started, here are a few quick pointers from the discussion to keep you on track:

  • Dependency Pinning: You’ll hear about pinning Python packages and managing them carefully. This ensures consistent, reliable deployments.
  • Docker Basics: Many panelists recommend using Docker containers for portable, repeatable environments.
  • Monolith vs. Microservices: The discussion underscores not overcomplicating your first project; it’s often safer to start with a single codebase.
  • Security and Updates: They emphasized that staying current with Python’s minor versions and patch releases can protect you from known vulnerabilities.

Key points and takeaways

  1. Running Python in Production at Different Scales While huge deployments at Instagram or Google get the most press, most Python teams run apps at small-to-medium scale. The guests highlighted that Python is "fast enough" for a majority of projects, and often performance bottlenecks come from database queries or third-party APIs rather than Python itself. They also emphasized that focusing on real, everyday production setups (rather than hyper-scale) can be more practical for most organizations.
  2. Start with a Monolith, Then Consider Microservices The guests agreed it’s often wise to begin with a single codebase—one “macroservice” or monolith—and split out services only if you have organizational capacity and genuine needs. Microservices introduce higher operational overhead (service discovery, monitoring, handling partial failures) that can be overkill for smaller teams.
  3. Cloud vs. On-Prem vs. Hybrid When deciding between cloud services and traditional hosting, you must weigh cost, operational overhead, and compliance constraints—especially in regions like the EU where data locality is important. Many small teams prefer fully managed platforms (like Heroku’s one-click approach), while larger or privacy-focused organizations might choose their own hardware or a hybrid.
  4. Docker for Portability and Simplified Deployments Packaging Python apps in Docker containers emerged as a major theme. Docker helps standardize local development and production environments. Emily highlighted that whether you’re on Heroku, AWS, or GCP, shipping a Docker image is a portable solution to “it works on my machine” problems.
  5. Security: Defense in Depth and Staying Updated Hynek stressed “defense in depth” – assume your internal network might be compromised and encrypt as much traffic as possible (even internally). Everyone agreed that keeping dependencies updated is crucial, whether through automation like Dependabot or via a pinned-requirements workflow. They highlighted that big vulnerabilities (e.g., log4j) often reinforce how critical it is to keep pace with releases.
  6. Performance and Load Testing Loading up your production-like environment with realistic data and scripts is crucial. The guests recommended using Python-based frameworks, such as Locust, which can mimic different user patterns (like “normal users” plus “admin users”) to see how your site performs under stress. They also noted how database bottlenecks often overshadow raw Python performance.
  7. Database Query Optimization They stressed that many “slow web apps” are really “slow SQL queries.” PG Mustard was praised for simplifying EXPLAIN statements in PostgreSQL. Balancing the right indexes vs. too many indexes is important: you can speed up reads but risk slowing down writes.
  8. Handling Larger Teams As teams grow into the dozens or hundreds, monolithic codebases can become unwieldy with frequent merge conflicts. That is often when splitting into services or multiple repositories can help reduce friction—but only at that scale. The panelists gave real-life examples from large companies where microservices made sense.
  9. Testing and Observability Cypress for front-end acceptance tests, or just limiting your max response time in development, can highlight potential performance or design issues. Pair this with robust real-time metrics and logging in production—so you discover issues before users do.
  10. Editor Choices and Developer Ergonomics A lively side note from each guest covered their editor picks: Emacs (with heavy customization), Vim, or VS Code. Emily credited Brett Cannon with finally convincing her to swap from Sublime to VS Code, praising VS Code’s built-in Python tools. While editors vary, the consensus was to pick something that boosts your efficiency and comfort.

Interesting quotes and stories

  • On microservices vs. monoliths: “More moving parts are always harder to make reliable.” – Hynek, emphasizing that you need strong reasons (and a large enough team) to break your system apart.
  • On security: “We treat our internal network as if it’s compromised … you can’t have enough layers.” – Hynek, describing the value of encryption and zero-trust approaches even inside your private LAN.
  • On scaling: “Python is fast enough. You usually saturate your database before you saturate Python.” – A common refrain from all guests, reminding us where the real bottlenecks often are.
  • On performance: “We had an issue because we added too many indexes. Sometimes you optimize reads at the expense of writes.” – Glyph, sharing real-world complexities of database tuning.

Key definitions and terms

  • Monolith: A single, unified codebase or application that manages all application logic in one deployment.
  • Microservices: A suite of smaller services, each focused on a specific function, communicating over the network.
  • Defense in Depth: A security principle that layers protections (e.g., encryption, segmentation) so that a single failure doesn’t compromise the whole system.
  • Dependency Pinning: Locking packages to a specific version for stability and reproducibility in production.
  • Locust: A Python-based load testing framework that can simulate user scenarios against your web application.

Learning resources

If you’re just starting with Python, or you want a systematic, project-focused approach, check out:

Additional on-topic courses from Talk Python Training that can help you dive deeper into production concepts:

Overall takeaway

Building reliable Python apps in production is more about making wise architectural and operational choices than about picking exotic technologies. Often, you can begin with a monolith, containerize your application, and focus on security fundamentals like dependency updates and defense in depth. As you scale, microservices and deeper cloud integrations might become essential, but keep complexity aligned with team capacity. Above all, monitor your real-world performance, be mindful of database queries, and stay excited about Python’s ever-growing ecosystem for modern production deployments.

Links from the show

Emily on Twitter: @emilyemorehouse
Hynek on Twitter: @hynek
Glyph on Twitter: @glyph

Main article by Hynek
Python in Production Article: hynek.me

Supporting articles
Solid Snakes or: How to Take 5 Weeks of Vacation: hynek.me
How to Write Deployment-friendly Applications: hynek.me
Common Infrastructure Errors I've Made: matduggan.com

Thoughts on Monoliths
Give me back my monolith: craigkerstiens.com
Goodbye Microservices: From 100s of problem children to 1 superstar: segment.com
Configuring uWSGI for Production Deployment: techatbloomberg.com
https://martinfowler.com/bliki/MicroservicePremium.html
https://martinfowler.com/bliki/MonolithFirst.html

More tools
CuttleSoft: cuttlesoft.com
pgMustard: Helps you review Postgres query plans quickly: pgmustard.com
JSON:API: jsonapi.org
Tenacity package: tenacity.readthedocs.io
glom package: glom.readthedocs.io
boltons package: boltons.readthedocs.io

Joke: The Torture Never Stops: devops.com
Watch this episode on YouTube: youtube.com
Episode transcripts: talkpython.fm

--- Stay in touch with us ---
Subscribe to Talk Python on YouTube: youtube.com
Talk Python on Bluesky: @talkpython.fm at bsky.app
Talk Python on Mastodon: talkpython
Michael on Bluesky: @mkennedy.codes at bsky.app
Michael on Mastodon: mkennedy

Talk Python's Mastodon Michael Kennedy's Mastodon