Logic for persisting an incoming message to a database