Advanced ORM: Filtering, sorting & summing 40M financial transactions
summary
Moves the heavy lifting into Postgres with Django ORM using annotations, F and Q expressions, window functions, JSONB traversal, nested subqueries and outer refs so filtering, grouping, summing and sorting run on the DB instead of iterating Python lists. Handles on‑demand queries over 40 million postings across ~472,000 accounts on ~5,000 properties, and uses materialized views (daily refresh) plus a few raw SQL CTEs/lateral joins when ORM hits limits; overall it works and drastically cuts user wait times.
AI-written summary · about
chapters (11)
- 0:00Introduction and background
- 2:31Problem with financial data queries
- 7:30Improvising with ORM techniques
- 10:47Chain annotations and performance
- 12:56Window functions for sliding calculations
- 14:43Sorting with dynamic JSON data
- 16:50Dynamic subquery generation
- 18:57Nested outer refs in subqueries
- 19:40Materialized views for heavy queries
- 23:30Python vs raw SQL trade-offs
- 25:59Q&A and closing remarks
