Database replication

Database replication is tricky to set up and maintain. RestAuth provides two Database routers that should help you with the most common replication situations. If you desire more information, please consult the Multiple databases chapter in the Django documentation.


Only use database routers when you actually use multiple databases. Adding a router does introduce a (negligible) performance overhead.

Using database routers

To use a database router (you can either write your own or use an existing one), simply add it to the DATABASE_ROUTERS setting in For example, if you want to use our MasterSlave router, simply add:

DATABASE_ROUTERS = ['common.routers.MasterSlave']


Routers shipping with RestAuth are not intended to be used together with other routers. If you require a more complex database routing schema you can either:

  • File a feature request if you think this is a common scheme that will be used by others, or
  • implement it yourself

Implementing your own routers

You can also implement your own router if you require a more complex configuration. Writing routers is documented in in the Django documentation and requires you to be able to code in Python.

Existing database routers

class common.routers.MasterSlave[source]

This router assumes that you have a single master (that can perform write operations) and multiple slaves that perform read operations.

Read operations will be redirected to a random database (including the master) and write operations will be directed to the “default” database, which should be the master.

class common.routers.MultipleMasterSlave[source]

This router handles multiple (read/write) masters and (read-only) slaves.

Read operations will be redirected to a random database (including any masters). Write-operations will be redirected to a random database with a designation starting with ‘master’.


     'master-a': { ... }, # will get write operations
     'master-b': { ... }, # will get write operations
     'slave': { ... }, # this is a read-only slave

Table Of Contents

Previous topic

Running multiple instances

Next topic

RestAuth import data format

This Page