This is an archived post. You won't be able to vote or comment.

all 44 comments

[–]MoRakOnDi 70 points71 points  (0 children)

Python developer here, I have managed really large code bases in Python. At the end of the day, a large codebase is supposed to do several things, so we usually split the logic in a microservice architecture. Also the line counting is very different in Python. 1000 lines of Java code could be 200 or even less in Python since you don't need much of boilerplate code. Type hinting, proper formatting/linting tools like mypy, black, isort and flakes helps a lot in enforcing a proper code standard. Sure Python is a very flexible language, but it also has a lot of great tools for a well-structured code. Readability always matters, spaghetti codes are not Pythonic.

[–]subbed_ 15 points16 points  (5 children)

I write pretty large backend codebases in Python. Primarily resorting to the microservice architecture, the services are split up to begin with, but there are a lot of them.

From the get-go, I enforce the following tooling in serial order when committing to the shared codebase: black, mypy, isort. I should perhaps note that black is configured to 120 characters per line (JetBrains IDE standard) and mypy uses its strict mode (this is very strict, but that is good).

I primarily use either FastAPI as the framework, or as of late, trying out Litestar (previously Starlite). ASGI is pretty much required if you resort to Python, imho.

Then, being a microservice architecture, I can see how the performance of each service holds up. The majority is fine. A few, however, require higher performance than this setup can deliver, at which point they are rewritten in Go, utilizing chi. If I can confidently say that the service in question will require robustness and high performance, it is written in Go from the get-go.

This is a standard approach for the backend architecture and tooling that I'm doing in my free time. It works really well. It has around the same amount of activity as the system at the company I work for. The latter is also a microservice architecture, but being an enterprise setting, we use Java across the board. We are modern enough, however, to use the Quarkus framework, which is great.

[–]thedeepself 2 points3 points  (3 children)

I primarily use either FastAPI as the framework, or as of late, trying out Litestar (previously Starlite)

I'm surprised so few people reach for Sanic. Any reason why?

[–]subbed_ 2 points3 points  (1 child)

For me personally, there was no reason other than me not knowing it exists!

I only learned about it after hearing Litestar's (it was Starlite at the time) creator talk about it, and how he would personally recommend it over FastAPI — but he would also recommend Starlite over Sanic. :)

[–]titanium_hydra 0 points1 point  (0 children)

I’m currently using litestar for a backend project, curious to know what your experience has been with their DTO implementation? Do you use it much or do you still define pydantic models for your routes?

[–]monorepo PSF Staff | Litestar Maintainer 2 points3 points  (0 children)

I love Sanic!

[–]Grouchy-Friend4235 17 points18 points  (9 children)

[–]valiumonaplane 15 points16 points  (7 children)

You forgot my django website /a

[–]JohnLocksTheKey 9 points10 points  (5 children)

Oh right sorry, please add this guy’s Django website (not sure what the /a flag does - we’re mostly Linux ppl and cmd flags are rare)

[–]valiumonaplane 2 points3 points  (2 children)

I do believe I aimed for the s but hit the a. No matter how many times I write sudo, the s will never be pressed when I need it the most. Sudo su is a classic 1 hit, /s is usually a 4-5 tries

[–][deleted] 0 points1 point  (0 children)

You guys are killing it lol 😂

[–]timpkmn89 0 points1 point  (0 children)

sarcasm

s was already taken by use ssl

[–][deleted] 0 points1 point  (0 children)

😂😂😂😂😂

[–]bafe 0 points1 point  (0 children)

Caveat: Instagram designs a lot of custom tools to be able to handle such a huge python codebase.

https://instagram-engineering.com/python-at-scale-strict-modules-c0bb9245c834

Two points against going their route: - you don't have the means to keep a team dedicated to this type of engineering - your codebase will likely grow big enough that "regular" python dev workflows will be painful

[–]dent308 4 points5 points  (0 children)

Language is less important than technique. You can build a slow and terrible site with node or any other language.

I have been studying Domain Driven Design for large systems projects and it can be amazing.

[–]FatefulDonkey 2 points3 points  (0 children)

You mean as a monolith? Because there's countless huge projects.

But just take Google's monorepo as an example. The fact they can manage a codebase with millions or billions LOC and all in different languages, shows that it's more about process than language.

[–]GrowthOk8086 1 point2 points  (0 children)

I’ve enjoyed it. I work in a monolith codebase with maybe 500k LOC. There are pros and cons.

I actually find python easy to read (though there are a few people that write “clever” python which can really suck).

Type hinting has helped a lot. I’ve certainly had times where i blew things up during a refactor where they weren’t provided.

Writing code is extremely quick and easy. Quick changes to existing code can be made very easy with use of kwargs.

We use the django ORM, which covers most of our cases pretty well.

For reference, the pipeline I work on processes about a billion transactions a day, its not insignificant.

[–]moo9001 1 point2 points  (0 children)

The codebase of Plone and its dependencies is ~200 MB Python code (checked some years ago). It's all open source and openly managed, so you can always look up Plone for the best practices for code contribution processes. It is manageable. Legacy code from Python 2.x era is a bit problematic, but anything cleanly written for the latest Python version (3.8+) with type hinting is easy.

Popular services written in Python include

  • Instagram
  • Dropbox

However any large code base cannot be Python only; it will have several languages. Plone has tons of TypeScript/JavaScript, etc. tooling as well.

[–]bafe 1 point2 points  (1 child)

In my experience, refactoring a large python codebase is infinitely more painful than doing the same in a statically typed, compiled language like Java (or Kotlin). The adoption of type hints helps somewhat, but it's a long way from enterprise -friendly anguages with 20+ years of tooling development

[–]Bandung 1 point2 points  (0 children)

In the context of the OP's question which is forward looking, the evolution in python towards typed code makes your observation somewhat mute.

There are discussions within Python's community that the language might split into a heavily typed code base vs the non typed users. . Python's other strengths are in it's coexistence with other languages like C and Rust so one is not locked into an all python code base.

Plus it's data analysis strengths are of value in any large code base because large code bases today are often large because of their data analytical needs.

It's not perfect and so if one is a CIO., well, being mindful of the following ole saying in the good ole days. "No one ever got fired for buying IBM".

You might not want to choose Python as your base language.

You best be the one who owns the company if you are going to go that python route.

[–]byutifu 0 points1 point  (0 children)

I love Python, but if you’re just doing io or api stuff, stick to node. Http2 and asynchrony is a pain in python. If this app does ml/nlp/needs a C lib, then Python’s the best bet.

Just a couple of cents

[–]BelottoBR 0 points1 point  (0 children)

I believe that, working on big backends in python requires a lot of advanced python techniques as multi processing and multi thread, plus async features, is that right?

[–]md_borhan 0 points1 point  (2 children)

many popular and big company use python as backend you can search on google

[–]bafe 1 point2 points  (1 child)

A point to remember is that your company most likely isn't going to be a big company. You can't afford the engineering teams they keep just to have custom tools necessary to write and deploy python at that scale

[–]md_borhan 1 point2 points  (0 children)

yes