Ban 1+N in Django

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • django-zen-queries

    Explicit control over database query execution in Django applications

  • See also django-zen-queries https://github.com/dabapps/django-zen-queries , which can make it impossible for changes to a template to trigger queries.

  • haxl

    A Haskell library that simplifies access to remote data, such as databases or web-based services.

  • +1. The JS event loop auto-monad-izing Promises into Haxl [1]-esqe trees of implicitly-batched loads has been a big win for us building on JavaScript/TypeScript.

    If I had to move to another language, I'd really want to find a "powered by the event loop / dataloader" framework, i.e. Vert.x for Java.

    Also, per dataloader, a shameless plug for our ORM that has dataloader de-N+1-ing built natively into all object graph traversals:

    https://joist-orm.io/docs/goals/avoiding-n-plus-1s

    [1]: https://github.com/facebook/Haxl

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • funcy

    A fancy and practical functional tools

  • On an unrelated note, Python folks should check out OP's library funcy [1]: "A collection of fancy functional tools focused on practicality. Inspired by clojure, underscore and my own abstractions."

    Thanks for the library Suor!

    [1] https://github.com/Suor/funcy

  • bullet

    help to kill N+1 queries and unused eager loading

  • Rails has Bullet[0] to help identify and warn you against N+1

    Does Django have anything active? Quick search revealed nplusone[1] but its been dead since 2018.

    [0] https://github.com/flyerhzm/bullet

    [1] https://github.com/jmcarp/nplusone

  • nplusone

    Auto-detecting the n+1 queries problem in Python

  • Rails has Bullet[0] to help identify and warn you against N+1

    Does Django have anything active? Quick search revealed nplusone[1] but its been dead since 2018.

    [0] https://github.com/flyerhzm/bullet

    [1] https://github.com/jmcarp/nplusone

  • django-cacheops

    A slick ORM cache with automatic granular event-driven invalidation.

  • django-orm-plus

  • I was working on a library to do this which I never got around to fully finishing but the idea is there: https://github.com/lime-green/django-orm-plus I think all I had left was polishing the auto add logic and testing with a real project

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • pellet

    Pellet helps improve your Django app performance by discovering N+1 queries. (by har777)

  • Self plug: Checkout https://github.com/har777/pellet to easily find and fix django N+1 issues.

    I usually add it to existing integration tests so that they raise exceptions on N+1. If test coverage is low then I would suggest sending the N+1 metrics to something like datadog. That way your users using the product will reveal all the N+1 issues on your monitoring solution.

  • django-auto-prefetching

    Automatic prefetching for Django

  • Shameless plug - I ran into this while developing REST interfaces with Django and built django-auto-prefetching: https://github.com/GeeWee/django-auto-prefetching

    It essentially travels your DRF serializer tree and builds an auto-prefetched query automatically without you needing to do any work.

    Back when I still worked actively on it, I wanted to monkey-patch models to track whether or not n+1 was happening, and if it was, automatically do pre-fetching, so instead of an n+1 problem you'd end up with just a "3-4 queries when it could've been 1" problem - which is much more palatable. Never got around to that part though.

  • django-seal

    Django application providing queryset sealing capability.

  • If I understand it correctly, that's what [django-seal](https://github.com/charettes/django-seal) does.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts