2đź‘Ť
He’s discussing how Disqus leverages the database routing technique used in Django 1.2 and above, which allows you to have connections to multiple databases alive at the same time.
Unlike earlier versions of Django, Django 1.2 and above use a dictionary of dictionaries, with the key of the initial dictionary being a token to entitle the database, and the keys of the inner dictionary mapping to the familiar Django settings in older versions.
The ForumPartitionRouter is the more obvious: different forums are stored in different databases (this is interesting, because it’s clear that they have some awesome management tools that allow them to define these partitions to their django servers when the servers are started, treating each Django instance as a transient and ephemeral object of their system) and the server uses the forum_id to go and find the right database from which to get the related members of the forum (in this case, the posts). db_for_read() returns the token which points to a database.
Many forums have many posts, but each post has one forum. Since forums don’t have interrelations, you can store each forum and its posts in one database, wholly independent of other forums and their posts.
If you look at the example on page 23, it’s clear from his example:
forum.post_set.all()
… that what’s happening is the forum’s object_id is being used as a lookup in a table somewhere that related forum IDs to databases (not tables, but databases) that may be anywhere else on the network.
It seems to me, therefore, that the ApplicationRouter is doing something similar with relationships. Look at the text: “Vertical Partitioning involves creating tables with fewer columns, and using additional tables to store the remaining columns.” That’s what ApplicationRouter does: when you’re using an application, and you go to access a related object in a diffent table, ApplicationRouter looks at the request and the instance to be filled in, and using a lookup table similar to the one for ForumPartitionRouter returns the key to the database in which that related instance’s details can be found.
You can look up multi-dbs here: