How do you optimize Django's ORM for read-heavy applications?
Instruction: Describe techniques to improve query performance without sacrificing data integrity or application scalability.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
Identify which reads dominate cost and what freshness each requires. A public catalog page, an account-permission check and a user's just-submitted order have different consistency needs. Measure query plans, scanned/returned rows, repeated queries and end-to-end latency before adding infrastructure.
Reduce unnecessary work first: fetch the required columns, load needed relations deliberately, index demonstrated filter/order patterns and use stable pagination. Deferred fields and unused prefetches can increase cost...