Spring Boot or Django?

Mohamed Haseel
6 min readNov 2, 2021

--

Django

Django is an open source web framework that runs in Python. The majority of its use is related to MVC monolithic programming, the ORM, migration capabilities and its support for modules.

If you take a look at the mvc code in Django, there is a folder for views with html, css, templates and js, a folder for controllers with routing and http logic and a folder with the business model and logic. Similar to Rails, Symphony and other MVC frameworks.

In Django, Databases get synchronized with migration technology in an integrated environment supported by the framework.

Templates can be rendered by the framework with python and html helpers of mixed code or a frontend app.

Like many other web frameworks, Django has a strong and proven stable support for scheduling, rest, views, configurations, several database drivers, permissions and roles etc.

The Django community is a big one, there are many examples of patterns and common solutions to existing problems in the web.

Python (and Django as a consequence) implements a subset of the full OOP paradigm. Many design patterns based on OOP when translated to python seem hacky or at least not natural (IMO). Python is easy to learn but really hard to master.

Python has one of the most powerful and simple standard libraries on earth (lists, sets, dicts, numbers, strings, files, lambdas.. ). Python runs in Linux or windows with an interpreter script execution. Pip is the standard dependency manager through a requirements or programmatic specification. Python is an esthetic, practical, expressive scripting dynamical programming language.

Please!!! skip the next two paragraphs if you can’t read opinions. I don’t want to hurt your feelings.

In my personal opinion, dynamic languages tend to rely more on expertise of developers than in enforced structure. The code will sometimes look like you need to know about what it does before you can start maintaining it.

My most opinionated view about python code: It is beautiful code that I can develop really quick, it scales well in expressiveness and freedom, it scales poorly for big teams and inexperienced programmers.

Spring boot

Spring boot is a opinionated starter pack for web development on top of the spring framework. Opinionated because Spring assumes what you need and why you need it before you even click run.

Boot with web runs an embedded tomcat server with spring dependencies and some core software patterns (configuration, stereotypes, application context, IoC, bean management and dependency injection). Boot lets you import the pieces you care from other spring or not spring dependencies. It it’s common to mix spring with Apache commons or the mighty Google guava library.

Spring is a monster. A HUGE monster, with corners of dark past, dungeons of experimental projects and hallways of abandoned ideas. Nevertheless, there’s a lot of prod ready functionality. It covers so many areas that it is really hard to cover them briefly.

Some of the projects I can prove are production ready and stable are, oauth2 and jwt, spring data redis, spring security, spring data JPA, data mongo and AOP.

The awesomeness of spring relies on the separation of concerns with dependencies, the abstraction and integration between abstractions. Moreover, the development speed it provides by providing a set of tools that let you focus on business logic more than in ceremony and boilerplate.

For example: If you need security abstractions there is a whole dependency set and a tree of sub dependencies with much more than you will probably need in your project ready to use (from ldap to social). If you need to connect to databases, you have JPA and many drivers for several databases (Jdbc based) . If you need to develop messaging, caching, scheduling, file management, etc. Spring has many way of providing the functionality or at least an abstraction that works.

There’s even a certification business behind the framework and consulting work profiting from it. The reason behind it’s success for enterprises and big organizations: it provides a lot of software structure control.

Spring normally provides configuration classes that load and provide behavior generic to a purpose. The abstractions provide a way to integrate by dependency injection. Outstanding examples about this are: the storage templates you need to configure for Mongo or Kafka messaging/listening , the different flavors of RestTemplates to call other endpoints, cache abstraction configuration, contract serialization, error management.

Spring has a great documentation, a great community and a plethora of subareas. Spring boot in specific its being widely used for microservices development. Netflix is one of the core influencers of Spring cloud microservices development.

You can build Spring with Maven or Gradle efficiently. Package management is relatively stable although complex to learn. Both maven and gradle provide ways to model dependency sets and namespace them, running tests, pmd checks, linters and code analisys.

Spring has been married to Java for a long time. Java is a statically compiled to byte code programming language that runs in the JVM. Java is OOP complete, verbose and older than python.

Java has a big standard library with many things you don’t need and won’t use (parts of the standard library are really ugly mostly for backwards compatibility reasons) . Java is portable and runs on a lot of devices.

Java has evolved over time, adapting to the new ideas that languages like python brought to the table. Java 8 supports lambdas, ooptionals, streams and reactive support, functional interfaces and very other extensions you would hope would had happened for 1.6 and 1.7. They came late in the game. We all know.

Java has simple yet powerful support for threading and concurrency control. Java tries to support dynamic behavior through generics and oop concepts (polymorphism and default virtual methods) . They don’t work well always specially generics (just casting to object and T casting on runtime).

To develop in Java you generally need to write a lot of code. That’s just how Java is. It is a verbose language.

Spring will supports Kotlin which is an improved JVM language interoperable with Java with much of the perks of python and haskell really soon.

Personal opinion region. Don’t read it if you can’t take it.

My personal opinion about Spring is, it has a lot of abstraction that allows me to develop at a decent velocity with enterprise friendly code. I can enforce almost all the software architecture and behavior. It scales well with big teams and general inexperience. It has a bigger learning curve than most frameworks.

Some downsides about Spring are: version awareness for a lot of features. Several classes for doing the same. Some features require a LOT of configuration that’s really hard to test. Spring also has a black magic approach, sometimes it feels like your driving a car that it is making more choices than it should.

Spring uses a lot of resources. A LOT, some blog posters try to defend it, but they have 0 arguments. Spring generally takes like 400MB of Ram just to have boot running, the JPA classes and a couple of other components like actuator and security. Django does not. That’s jut plain fact.

The use of Ram relates of the fact that beans get registered in the JVM, autoconfiguration classes as well, proxies, singletons and other spring managed beans. All the automatic behavior has a price. The price is memory.

Final thoughts

Analyze your situation carefully. Think about expressiveness vs verbosity. Think about the importance of threading. Think about the esthetic aspect of code. Think about the members of the project, the scope and you will find a choice.

My final argument is: it depends. Choose wisely.

I prefer Spring. If I need to do scripting I can always open an Ipython console and proof my concept, but a small project with python will not become a static enforced project for a big team in one night. I have chosen my trade off. Do more work, write more code, fool-proof everything.

--

--

No responses yet