Talk

Zero-Downtime Multi-Tenancy in Django: From User-centric to Organizations-based Architecture

Saturday, May 30

12:25 - 12:55
RoomPassatelli
LanguageEnglish
Audience levelIntermediate
Elevator pitch

Migrating a production Django app to multi-tenancy without downtime or bugs seems impossible

At Sendcloud, we refactored a 600k+ lines Django app using proxy models, dual FKs, and strategic migrations, with zero downtime, and no bugs.

In this talk, I’ll tell you how we did it 💪

Abstract

Multi-tenancy is a common requirement, but retrofitting it into an existing Django application with dozens of models can feel overwhelming.

How do you migrate from a user-centric architecture, where users own resources, to an organization-based one where users belong to multiple organizations? And all without downtime, dangerous migrations, breaking changes, or awful bugs?

At SendCloud, we tackled this exact challenge across our Django monolith: 600k+ lines of Python code with continuous production traffic. This talk shares our battle-tested strategy that allowed continuous deployments throughout the migration, and enabled us to move slowly, one Django app at a time.

The approach: 1) Proxy models as a bridge: Creating an Organization proxy of User, which allowed us to change ForeignKeys in code while maintaining database compatibility 2) Progressive refactoring: Using helpers like a base class with fallback code, and custom codemods to systematically update models, tests, and business logic across all apps 3) Dual foreign keys: Adding new FK constraints pointing to the organization table alongside existing user FKs, using PostgreSQL’s NOT VALID to avoid table locks 4) Seamless cutover: Swapping from proxy to real Organization model without SQL execution, then dropping old constraints

In this talk, I’ll share all the details involved in those steps, with real examples, alongside some pitfalls we discovered, what worked well, and practical tips for anyone attempting a similar large-scale refactoring without taking their Django app offline.

TagsWeb Frameworks, Applications and Libraries
Participant

Thiago Bellini Ribeiro

My name is Thiago Bellini Ribeiro - a 38 year-old Brazilian 🇧🇷 software engineer living and working in the Netherlands 🇳🇱 at Sendcloud, with my wife, two dogs 🐶, and two cats 😸.

I’ve been passionate about Python since 2010, using it both professionally and personally. As an open-source enthusiast, I’m always looking for ways to give back to the community. Since 2022, I’ve been a maintainer of the 🍓 Strawberry GraphQL Python library - a project I continue to support out of passion, even though I no longer use it in my day-to-day work.

Outside of coding, I’m known for my positive outlook and my eagerness to help others in the tech community. I love connecting with people, sharing knowledge, and contributing to a collaborative and forward-thinking industry.