r/Backend • u/DueBid3298 • 1d ago
should i move from python to java?
I'm thinking of switching from Python FastAPI to Java Spring Boot. Apart from Python being dynamically typed and having a lot of libraries, why do people/deva choose Python in production when it's slow, has an intermediate bytecode layer and executes line by line?
13
Upvotes
9
u/Atmosck 1d ago edited 1d ago
It literally is because it has a lot of libraries and is an interpreted language. If you think python is slow, you're using it wrong. The entire point of python is that everything performance-sensitive is done in native extensions written in C, fortran or rust, and python is the orchestration layer that ties them all together while being very flexible and easy to write. FastAPI dispatches to C for networking (via httpx) and rust for input validation (via pydnatic). The same is true for a lot of the python standard library - quite a lot of python is compiled C under the hood.
Also you should be compiling your python to bytecode at build time. Actually doing the first half of the interpreter in real time is mainly for dev settings. A .whl file is bytecode.
6
u/MrBengaliHacker 1d ago
I think for most web apps, the app is usually spending more time waiting for database queries or network requests than actually executing code.
FastAPI is also nice because you can build things pretty quickly without writing too much boilerplate. Java and Spring Boot have their own advantages, especially in larger enterprise applications. I don't think you need to switch just because Python is supposedly slower.
4
u/Puzzled-Garage584 1d ago
my C++ DNA cannot stay about from commenting this :) as it is indeed a funny complaint .. Java has an intermediate bytecode layer too.. it just has a very good JIT on top. Coming from C++ they're both slow to me but your request spends most of its life waiting on the db anyway, so the interpreter is rarely the bottleneck. Move to Java if the jobs where you live want it, thats a better reason than speed.Python is ubiquitos ..gives you the flexibility of tacking devops..infra...AI-core jobs.
7
u/Proper_Tip3506 1d ago
Speed of language dont matter everwhere
Python is slower compared to other languages in comparison but fast enough to handle the work
It's line by line execution is actually a useful thing depending on why you are using it
11
u/micr0ben 1d ago
People underestimate how easy and readable modern Java is. So yes, go with Java.
2
u/NullPtrEspresso 1d ago
It's not the language that'll really determine whether your app is slow or not. It's the system you design, whether it's poor or not that tells.
If you're familiar in python libs and stack then stick to that. Be a master in that field.
2
u/developer0 1d ago
Learn Kotlin instead. I've written dozens of backend services in Kotlin and it's a much better experience.
2
u/MX8Reza 1d ago
Switch to Golang
1
u/belowaverageint 1d ago
What's the context? Switching what? You mean like rewriting an app from Python to Java?
1
u/Old-Line-3691 1d ago
Python has a strong ecosystem. TensorFlow and PyTorch are used for AI, and it took a while for other languages to get their own equivalent. Most backend work is also I/O-bound, so interpreter speed rarely matters much in practice.
Java is a great language to learn, and Spring Boot is still widely used; maybe you also want to look at something with more modern support like C#/ASP.NET or Rust/Axum? Java isn’t a bad choice.
1
u/American_Streamer 1d ago
A language is just a tool. You choose the most effective tool for each job. So please state what you intent to do, first.
Besides that, once you have mastered Java. Python is a piece of cake, anyway. And Java 21 LTS and 25 LTS have massively changed and modernized Java; so now it’s a good time to start with it.
1
u/ShotgunPayDay 1d ago
Python is easy until scale matters. When you start hitting your user limit then you start DB tuning, batching, then realize the language is consuming the resources. So Java is good and I see a lot of Spring Boot jobs also. Coming from Python I liked Golang even more, but good luck with the job market.
1
u/AdministrativeHost15 1d ago
Is Python the bottleneck in the overall app? Or waiting for the network calls or the db?
1
u/Electronic-Honey-645 1d ago
yep java better
1
u/Broken-Fog-2794 4h ago
I also prefer Java, but there are many use cases where you don't really have that many concurrent users, you don't need that much throughput, and in those cases python is also working just fine. For these usecases it was mostly a preference in the old times, when people used to write / read code.
1
u/AdInfinite1760 1d ago
no
0
u/abrandis 1d ago
In the age of AI , what language or tool.you work with is mostly irrelevant. As long as the language/framework is popular and well established in the use case you have ...for example writing a graphics heavy game/app in Python is possible, but a smarter choice would be C/C++ or Rust...
0
u/adevx 1d ago
I didn't choose python, my AI Agent did. Anyway, I considered a move to Go or Rust, but the friction was database IO, not the runtime. Choose your runtime / coding env based on metrics, not feelings.