Sometimes LogEntries are written in high succession. In these cases the same local_id is generated several times and the unique db constraint is violated. Making the generate_local_id atomic doesn't help, as the LogEntry isn't saved to the db after generate_local_id yet. Maybe look into sql triggers