Sync messages in dependency order
Messages should be synced in dependency order (i.e. dependencies before their dependents) so they can be delivered to the client as soon as possible.
This can be done by recording the dependency depth of each message in the DB. A message with no dependencies has a depth of 0. A message with dependencies has a depth one greater than the greatest depth of its dependencies.