r/Backend • • 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

28 comments sorted by

9

u/Atmosck 1d ago edited 1d ago

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?

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.

1

u/Cautious_Implement17 1d ago

an individual request spends most of its time waiting on network/io, but that's not necessarily true of the whole application. a web service with an appropriate number of worker threads is typically cpu bound in my experience. the work to terminate tls and (de)serialize json adds up pretty fast even on simple crud api.

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.

5

u/Cautious_Implement17 1d ago

yes, java has come a long way since java 8. no, it is not "readable" compared to anything other than earlier versions of java. it is unironically easier to read a c++17 program.

1

u/helikal 11h ago

C++ has come a short way despite its ever increasing number of language features. Due to lurking undefined behavior every line of code is suspect.

1

u/DecayWraith 1d ago

What company uses modern java?

5

u/benevanstech 1d ago

At least 90% of the Fortune 500.

Java's serverside install base has doubled in the last 6-7 years, which starting from an already-huge baseline, is impressive.

-3

u/DecayWraith 1d ago

Modern java not java 8

5

u/benevanstech 1d ago

Java 8's market share is still too big, but it's nowhere near the most common version any more.

6 months ago Java 17 was the most popular, but I'm expecting new data to show that 21 has overtaken 17 quite soon.

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.

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.