---
title: "Discussion on \"From O(N³) to O(1): Scaling M2M Validation in Django\" | Hashnode"
description: "Discussion on \"From O(N³) to O(1): Scaling M2M Validation in Django\". Adding a few cities to a delivery zone is instant. Adding 5,000 cities ran over 5,000 database round-trips and regularly timed out the request. The root causes were two common Django patterns that don"
url: "https://hashnode.com/posts/from-o-n-to-o-1-scaling-m2m-validation-in-django/6a6226ccc85cf69361222702"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [From O(N³) to O(1): Scaling M2M Validation in Django](https://blog.acel.dev/from-o-n-to-o-1-scaling-m2m-validation-in-django?utm_source=hashnode&utm_medium=feed)

Adding a few cities to a delivery zone is instant. Adding 5,000 cities ran over 5,000 database round-trips and regularly timed out the request. The root causes were two common Django patterns that don

Jul 23 · 7 min read · blog.acel.dev  
Read the article

-   [#django](https://hashnode.com/tag/django)
-   [#python](https://hashnode.com/tag/python)
-   [#performance](https://hashnode.com/tag/performance)
-   [#postgresql](https://hashnode.com/tag/postgresql)

## Written by

[Chukwuemeka Aladimma](https://hashnode.com/@Acel)

@Acel

  
[View profile](https://hashnode.com/@Acel)

Backend Engineer

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
