
To make things even more complex, I use Streaming Replication to replicate every database server's data to multiple slave servers. # - or by querying a "name_to_user" table then querying just the # - either by querying *all* database servers (not good) Searching users by name # fetches all relevant users (kings) from all relevant logical shards User = User(name = "Arthur", title = "King") User = User.create(name = "Arthur", title = "King")
#Postgres 14 sharding code#
Ideally, I would love to be able to write Django code such as:įetching an instance # this gets the user object on the appropriate server, in the appropriate schema:įetching related objects # this gets the user's posted articles, located in the same logical shard:Ĭreating an instance # this selects a random logical shard and creates the user there: How can this be achieved as simply as possible in Django ?


I want users to be sharded across those database servers using the same sharding logic used by Instagram: I have a Django project based on multiple PostgreSQL servers.
