Master_ master replication on Mariadb
To avoid the issue with duplicate keys when using auto_increment PKs, you need to configure the system variables auto_increment_increment and auto_increment_offset.

From the MariaDB Knowledgebase: AUTO_INCREMENT:


  To make master-master or Galera safe to use AUTO_INCREMENT one should
  use the system variables auto_increment_increment and
  auto_increment_offset to generate unique values for each server.


So in other words, with two masters: On master1 set auto_increment_increment=2 and auto_increment_offset=1, and on master2 set auto_increment_increment=2 and auto_increment_offset=2.