Django ORM: a fight between MTI and STI
We use hierarchical data structures in our applications pretty often and the most common question is how to effectively store such data in relation databases.
I'm going to shed some light on this topic and discuss most popular approaches: Multi-Table Inheritance and Single Table Inheritance.
We also will discuss the following points:
- How PostgreSQL support table inheritance out of the box.
- Comparison between MTI and STI: what is better to use. How can Django ORM and Managers help?
- Which Python packages can make MTI/STI approaches easier to implement and maintain.
- How JSONb can improve STI-based approach.
I’ve been developing with Python over 10 years and now I’m engineering manager at well-known Russian Payment System Provider QIWI.
Previously, I’ve worked as technical lead in statusmoney.com fintech project, developer in Yandex, head of Python developers in Ramber&Co and many other well-known Russian IT companies like Kaspersky Lab and Acronis.