---
title: "How to build a multi-region Python app with CockroachDB, Django, and K8s"
description: "Data domiciling in a Django app on CockroachDB works by adding a 'cloud' field to a Customers model, deploying the app to Kubernetes clusters in Azure, AWS and GCP, and pinning each row to a region."
url: "https://swe.quest/articles/how-to-build-a-multi-region-python-app-with-cockroachdb-django-and-k8s-004ef71dbf260924"
canonical: "https://www.cockroachlabs.com/blog/django-kubernetes-cockroachdb/"
source: "Cockroach Labs"
published: "2022-06-27"
difficulty: "medium"
kind: "How-to"
reading_minutes: 6
tags: ["distributed-databases","python","kubernetes","replication","privacy"]
---

# How to build a multi-region Python app with CockroachDB, Django, and K8s

A post on [Cockroach Labs](https://swe.quest/sources/cockroachdb.md), published 2022-06-27, 6 min read, How-to. Original: [https://www.cockroachlabs.com/blog/django-kubernetes-cockroachdb/](https://www.cockroachlabs.com/blog/django-kubernetes-cockroachdb/)

## Summary

Data domiciling in a Django app on CockroachDB works by adding a 'cloud' field to a Customers model, deploying the app to Kubernetes clusters in Azure, AWS and GCP, and pinning each row to a region. The setup uses a computed crdb\_internal\_region column with a CASE expression and REGIONAL BY ROW table locality. ALTER DATABASE ... PLACEMENT RESTRICTED then keeps non-voting replicas in the right locality, and replication constraint reports verify that violating ranges have moved. Pinning data cuts consensus round trips for lower write latency and helps meet data sovereignty requirements.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Distributed databases](https://swe.quest/tags/distributed-databases.md) (Data & databases)
- [Python](https://swe.quest/tags/python.md) (Languages)
- [Kubernetes](https://swe.quest/tags/kubernetes.md) (Infrastructure)
- [Replication](https://swe.quest/tags/replication.md) (Distributed systems)
- [Privacy](https://swe.quest/tags/privacy.md) (Security)

## Prerequisites

- Kubernetes basics ([easy posts on Kubernetes](https://swe.quest/tags/kubernetes.md?difficulty=easy))
- Docker ([easy posts on Containers](https://swe.quest/tags/containers.md?difficulty=easy))
- Django models and migrations
- SQL ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))

## Keywords

CockroachDB, Django, Kubernetes, REGIONAL BY ROW, PLACEMENT RESTRICTED, django-cockroachdb

## Related posts

- [Orbital Computing and Distributed Databases | CockroachDB](https://swe.quest/articles/orbital-computing-and-distributed-databases-cockroachdb-c5f1cf8d95fd646c.md): Cockroach Labs · 2026-08-06 · Medium · 18 min read · Distributed databases, Consensus, Replication, Distributed systems, Performance engineering
  Orbital compute creates a harder problem for stateful systems than for GPUs: data must be replicated, coordinated and placed across a moving constellation.
- [How we built multi-region support for Linear](https://swe.quest/articles/how-we-built-multi-region-support-for-linear-acbf98e7bc2a3edb.md): Linear · 2024-05-23 · Medium · 9 min read · System design, Distributed systems, Identity & auth, Infrastructure as code, PostgreSQL
  Linear added an EU region by replicating its entire production deployment per region rather than sharding the database, keeping each region isolated and letting engineers keep writing against a single Postgres instance.
- [The Best Multi-Region Hosting Platforms in 2026](https://swe.quest/articles/the-best-multi-region-hosting-platforms-in-2026-fbed8cd7b315a007.md): Railway · 2026-05-25 · Easy · 13 min read · Cloud platforms, Distributed databases, Replication, System design
  "Multi-region" covers three distinct problems: CDN static asset distribution (level 1), stateless compute in multiple regions with a single-region database (level 2), and multi-region writes for stateful data (level 3).
- [Announcing Deno KV](https://swe.quest/articles/announcing-deno-kv-d97d28c9a7128cf3.md): Deno · 2023-05-01 · Medium · 5 min read · Databases, Consistency models, Replication, JavaScript
  Deno KV is a strongly consistent key-value database built into the Deno runtime.
- [Lessons Learned From Running Apache Airflow at Scale](https://swe.quest/articles/lessons-learned-from-running-apache-airflow-at-scale-465dd0ced6d11da7.md): Shopify Engineering · 2022-05-23 · Medium · 12 min read · Scheduling, Data pipelines, Multi-tenancy, Scaling, Kubernetes
  Shopify runs Airflow 2.2 on Kubernetes with the Celery executor and MySQL 8, and its largest environment handles over 10,000 DAGs and 150,000 runs per day.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
