Pycon NL: zero-downtime multi-tenancy in Django - Thiago Bellini Ribeiro

Tags: python, pycon, django

(One of my summaries of the 2026 one-day Pycon NL conference in Utrecht, NL).

Full title: zero-downtime multi-tenancy in Django: from user-centric to organizations-based architecture.

He works for Sendcloud. Originally their code was 2010-style Django. Every business object (Parcel, Order, etc) is linked to a django User. But… users can belong to organisations and organisations should be the ones connected to the business objects. Ok, they moved to a “core” user and “sub” users. But still users could only belong to a single organisation, for instance.

What they actually need is many users per organisation. And also many orgs per user. Roles per membership instead of per user. They designed a new system based upon this.

But: they had around 20 Django apps and 40 models with a link to user_id. How to migrate? The solution was to use a “proxy model”. They started an “organisation” model that simply was a differently named Django model, pointing at the same table as the existing user model. This allowed them to keep almost everything the same with only minimal database migrations.

After that, they moved a little bit of functionality over to the new organisation model. Again, a small, minimal database migration.

They did it incrementally. They had all those apps and models to work through. Slowly but surely they got it done. Small steps that are backwards compatible help a lot.

They introduced a mistake-finder: an OrganisationAware mixin that logged direct .user access in production and produced errors in development. This helped turn up usage of the user model that wasn’t findable through basic grepping and searching.

They also used libcst, an abstract syntax tree parser for python to go through the entire code and try and find corner cases where the old way of working was used.

In the end, everything was moved over to the real organisation model and the organisation-proxy wasn’t needed anymore, so they could remove it. They

https://reinout.vanrees.org/images/2026/pyconnl-6.jpeg

Unrelated photo from our Nelen&Schuurmans company trip to Cologne/Köln in Germany. Of course there’s a Hohenzollern-on-a-horse statue near the Hohenzollernbridge! This one is Wilhelm II, the Kaiser during the first world war (who fled to the Netherlands, btw).