Feature/db replication

This needs some git squashing, but it would be really useful to get it merged in.