SlideShare a Scribd company logo
Why you shouldn’t use
Django for that
Architecture,
the lost years
Robert C. Martin
“Web” is not an
architecture.
Frameworks are
not architecture.
Django is a tool,
not architecture.
WAIT!
What does this even mean?
Ivan Stepaniuk
@istepaniuk
Application metaphor, the three layers
1 32
1.Interact with the user, both ways
1 32
3. Interact with outside world, other systems
1 32
2. The code that justifies the app existence
1 32
Are these layers equally important?
Do we build them the same way?
Do these change at the same pace?
It is all about
CHANGE
OK
How does business logic look like?
Patterns
Enterprise
Application
Architecture
Martin Fowler
Transaction Script
Modeled as procedures
+ Easiest to understand.
+ Obvious transaction boundaries.
- Difficult to de-duplicate.
Table Module
Modeled as objects and Record Sets
+ No DB vs. OO impedance mismatch.
- Model is database-centric.
- Objects, but not really OO.
Domain Model
Modeled after the business you work with.
+ Real OOP, with all the OO advantages.
- Hardest to comprehend and switch to.
- Code overhead for simple logic.
Domain Model
Modeled after the business you work with.
+ Real OOP, with all the OO advantages.
- Hardest to comprehend and switch to.
- Code overhead for simple logic.
Which pattern should I use?
Which one should we use?
Efforttoenhance
Complexity of the business logic
Which one should we use?
Efforttoenhance
Complexity of the business logic
7.42
Which pattern does Django follow?
Domain Model
Architecture
Antipatterns
Anemic Domain Model
- Objects have state, but no behavior
- The Business is somewhere else
Leads to:
- Upside down Transaction Script
- God objects
Anemic Domain Model
- Objects have state, but no behavior
- The Business is somewhere else
Leads to:
- Upside down Transaction Script
- God objects
Mixins!
To inject concerns
Why you shouldnt use django for that
Table Driven Domain Model
- The data model is the domain model
- All objects backed up by a table
Leads to:
- High viscosity
- Complex, slow, fragile tests
- CRUD obsession
Table Driven Domain Model
- The data model is the domain model
- All objects backed up by a table
Leads to:
- High viscosity
- Complex, slow, fragile tests
- CRUD obsession
CREATE
READ
UPDATE
DELETE
DATABASE
DATABASE
DATABASE
DATABASE
Why you shouldnt use django for that
Why you shouldnt use django for that
Connected Domain Model
In a connected system, elements are highly available to each other.
Adding the first feature to a connected system is cheap …
… the cost of all those connections is that subsequent features
are very likely to interact with previous features, driving up the the cost …
In a modular design, connections are deliberately kept to a minimum.
The cost of the first feature is likely to be higher …
Features are less likely to interact in a modular system, though,
leading to a steady stream of features at relatively constant cost.
- Kent Beck
Connected Domain Model
WAIT!
OK, Active Record is bad, but
what about productivity?
Django vs. OOP
Django vs. OOP
Is not the debate here
Questions?
Or come and ask me later!
Thank you!
Oh, and we are hiring!
@istepaniuk

More Related Content

Viewers also liked (14)

PDF
教師須知:如何應用維基百科作為教育工具
Liang-chih Shangkuan
 
DOCX
Pract 9 cons energia
laury kiryu
 
PPT
Todo sobre mi
Gelenpystupystu
 
PPT
Apple Tree
guest1c94e8
 
PPTX
Smart, flipped, moodle and how they interact 2015
russechd
 
PPTX
Referat paris ppt
Edith Degat
 
DOCX
Poliartrita reumatoida
Negotei Elena
 
DOCX
Diagrama de flujo 9
laury kiryu
 
DOCX
Diagrama de flujo pract 3 hidrolisis
laury kiryu
 
PPTX
Softchoice Webinar: Virtual Whiteboard Session on Hybrid Cloud
Softchoice Corporation
 
PDF
Noticia Semana de Orientación hacia la Educación Superior
Colegio Camilo Henríquez
 
DOCX
Ontenció y propiedades del alqueno
Jhonás A. Vega
 
PDF
Étude Softchoice. Favoriser l’innovation : les actes en disent plus long que ...
Softchoice Corporation
 
PDF
How to become a Medical Assistant
Marie Reynolds
 
教師須知:如何應用維基百科作為教育工具
Liang-chih Shangkuan
 
Pract 9 cons energia
laury kiryu
 
Todo sobre mi
Gelenpystupystu
 
Apple Tree
guest1c94e8
 
Smart, flipped, moodle and how they interact 2015
russechd
 
Referat paris ppt
Edith Degat
 
Poliartrita reumatoida
Negotei Elena
 
Diagrama de flujo 9
laury kiryu
 
Diagrama de flujo pract 3 hidrolisis
laury kiryu
 
Softchoice Webinar: Virtual Whiteboard Session on Hybrid Cloud
Softchoice Corporation
 
Noticia Semana de Orientación hacia la Educación Superior
Colegio Camilo Henríquez
 
Ontenció y propiedades del alqueno
Jhonás A. Vega
 
Étude Softchoice. Favoriser l’innovation : les actes en disent plus long que ...
Softchoice Corporation
 
How to become a Medical Assistant
Marie Reynolds
 

Similar to Why you shouldnt use django for that (20)

PDF
The JSON architecture
Constantin Dumitrescu
 
PPTX
Domain oriented development
rajmundr
 
PPTX
Life Beyond Rails: Creating Cross Platform Ruby Apps
Tristan Gomez
 
PPTX
L07 Oranizing Domain Logic
Ólafur Andri Ragnarsson
 
PPTX
L13 Oranizing Domain Logic
Ólafur Andri Ragnarsson
 
ODP
Front Range PHP NoSQL Databases
Jon Meredith
 
PDF
Architecture by Accident
Gleicon Moraes
 
PDF
SQL in the Hybrid World
Tanel Poder
 
PDF
Super Sizing Youtube with Python
didip
 
PDF
Os Solomon
oscon2007
 
PPTX
Let's talk about... Microservices
Alessandro Giorgetti
 
PPTX
Why mongo db was created - Dwight Merriman - MongoSF 2011
MongoDB
 
PDF
Agile data lake? An oxymoron?
samthemonad
 
ODP
Data massage! databases scaled from one to one million nodes (ulf wendel)
Zhang Bo
 
DOC
Ibm redbook
Rahul Verma
 
ODP
Data massage: How databases have been scaled from one to one million nodes
Ulf Wendel
 
PPTX
Rethinking Best Practices
floydophone
 
PPTX
Big iron 2 (published)
Ben Stopford
 
PDF
L15 Organising Domain Layer
Ólafur Andri Ragnarsson
 
PPTX
CQRS recipes or how to cook your architecture
Thomas Jaskula
 
The JSON architecture
Constantin Dumitrescu
 
Domain oriented development
rajmundr
 
Life Beyond Rails: Creating Cross Platform Ruby Apps
Tristan Gomez
 
L07 Oranizing Domain Logic
Ólafur Andri Ragnarsson
 
L13 Oranizing Domain Logic
Ólafur Andri Ragnarsson
 
Front Range PHP NoSQL Databases
Jon Meredith
 
Architecture by Accident
Gleicon Moraes
 
SQL in the Hybrid World
Tanel Poder
 
Super Sizing Youtube with Python
didip
 
Os Solomon
oscon2007
 
Let's talk about... Microservices
Alessandro Giorgetti
 
Why mongo db was created - Dwight Merriman - MongoSF 2011
MongoDB
 
Agile data lake? An oxymoron?
samthemonad
 
Data massage! databases scaled from one to one million nodes (ulf wendel)
Zhang Bo
 
Ibm redbook
Rahul Verma
 
Data massage: How databases have been scaled from one to one million nodes
Ulf Wendel
 
Rethinking Best Practices
floydophone
 
Big iron 2 (published)
Ben Stopford
 
L15 Organising Domain Layer
Ólafur Andri Ragnarsson
 
CQRS recipes or how to cook your architecture
Thomas Jaskula
 
Ad

Recently uploaded (20)

PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Ad

Why you shouldnt use django for that

Editor's Notes

  • #2: Confession: The title is a bit of trick. We are going to speak about application architecture.
  • #3: 2013 Norwegian Developers Conference - (and Javier Acero excellent talk in Madrid) How the web changed the way we write software In the first “WEB” decade, we forgot a lot about architecture. Smart people retire.
  • #4: The web is ONE transmission channel, is how you deliver, it's a detail. That's all. If PostNL changes to UPS - your business keeps running.
  • #5: Frameworks are tools, they can't be in the center of the architecture. Architecture is more about DEFERRING decisions than to decide. Frameworks should too, be a detail.
  • #6: So Django CAN'T be the center of your application. Most importantly, architecture-wise: The way we write applications in Django is -NOT- a generally correct way to write an application
  • #7: WTF does this mean? What do you mean by application architecture then? Let's think through this!
  • #8: I work at the cloakroom as a backend developer, we use python (and even some django)
  • #9: The classic 3 layers. Deliberately, not going to try to name all three now
  • #10: Producing HTML JSON, An HTTP API, REST Command Line Desktop or Mobile UI widgets
  • #11: Databases and Message Queues Sending an email The file system
  • #12: Validation, Calculation Calls to external systems (or preferably to abstractions) IE: Calculate taxes, add invoice lines, etc. This is the Business logic.
  • #13: What is it more important? that a form looks nice, it's usability? that the persistence is really fast? or... that taxes to be calculated correctly?
  • #14: NO WE DON’T! The Busines Logic layer is more difficult to reuse between different problem domains. It is specific. Layer 3, ...we generally do not write DB drivers, or SMTP clients, etc.
  • #15: .
  • #16: Do these layers change at the same pace? 1: Technology changes, a decade ago no JS on the front. 3: We now have NoSQL stores, many of them. 2: BL: Domain rules change slowly, length of a credit-card or the age of a person.
  • #17: What is Business Logic anyway?
  • #18: This influential book from 2003 You wanna read it if you haven’t Mentions the patterns we are going to discuss
  • #19: Modeled as procedures (and of course sub-routines), Easy to understand Obvious transaction boundaries. Even extracting subroutines, is difficult to de-duplicate. (in turn more nasty consequences)
  • #20: Perhaps more exotic now. One instance for each type object, only one, operates over database rows NO oo-db impedance mismatch No polymorphism, no dynamic linking, nada. Modeling around the database structure
  • #21: Specifically based in the domain of the business you are working with (Vaughn Vernon IDDD) Business Logic modeled as object behavior, no DB, no transaction scripts. Business as object graphs and object clusters. The OOP way of modeling. ...
  • #22: Real OOP, with all the bells and whistles. + Heuristics like SOLID Hardest to comprehend. Using a domain model is the essence of the paradigm shift to OOP. Code overhead for simple BL. RELATIONAL Data sources get more complex
  • #23: .
  • #24: this is in PATTERNS - ENTERPRISE - APPLICATION - ARCHITECTURE
  • #25: Complexity bigger than 7.42 Impossible to calculate Difficult to predict
  • #26: So... What is django pattern?? HOW MANY - Tx Script, Table Mod, Domain Model I'd say. Probably a -some sort of- domain model
  • #27: So assuming that, let's take a look at some ANTIPATTERNS
  • #28: This is a CLASSIC in many Django apps I’ve seen. Objects have state but no behavior (and Getters+Setters are not behavior) They are just data structures. This is not OOP. Business Logic and thus behavior is somewhere ELSE (controllers,"service" layer, “managers”, forms) Some say call this the "J2EE smell" - NOT TRUE
  • #29: This is like Transaction Script, old school CGI Solve it by a "Push it down" refactor, not a design pattern (though it's better) Not really a Domain model. just a twisted Transaction Script God objects (User + The most application centric object; Product)
  • #30: God objects can be solved with mixins PYTHON has it.
  • #31: Mixings are inheritance. Inheritance is the strongest form of coupling, you are just spreading the code. You are only making things worse Prefer composition.
  • #32: Viscosity due to tight coupling, persistence and logic coupled together, you can’t change ANY Complex tests need database to run or complex sorcery. Test behavior, not implementation. CRUD obsession >>>>
  • #33: Difficult to avoid in Django: The domain model is basically the data model All objects backed up by a table. Databases are part of the 3rd Layer, DETAILS they do not belong to the DM. They have design requirements Leads to ...
  • #34: You may think that it means… BUT. Actually stands for
  • #35: C, R, U, D are consequences of the use cases, not THE use cases.
  • #36: CRUD APPs are LEGACY We are not modeling the paper-based office in software anymore
  • #37: There is an APP for that!
  • #38: Lastly
  • #39: This antipattern is Unavoidable in Django (and any other ActiveRecord based framework) Global state, models are omnipresent (accessible even from the templates through lazy loading). No real separation, the three layers are connected and tightly coupled. They can't easily change at different pace. Active Record is the culprit. AGAIN
  • #40: The “Django way” is FAST, but consider it is a HUGE trade-off, specially for complex apps. Are you prepared to pay the price? BUT it works for me! - Maybe, but at least keep all these things in mind.
  • #41: So Django vs. OOP is ….
  • #42: NOT THE DEBATE Frameworks are tools, and they have a place. Django is probably good enough if CRUD is good enough for your application - (which rarely is). Where I say Django, you can say Rails, Spring, and other paternalistic, Active Record based frameworks.
  • #43: If we still have time
  • #44: HIRING!